fix(issue#3): CMPP ConnectResp 按 2.0 规范 4B Status——修客户连接报 -1;充值字段对齐 amount+错误提示;SrcID 核验口径文案
This commit is contained in:
@@ -2,6 +2,17 @@
|
||||
|
||||
> 本仓 CHANGELOG 自重建起记(POC 明细见归档仓 /data/poc-archive/repos/go-sms.git 的 CHANGELOG.md,已冻结)。
|
||||
|
||||
## 2026-11-16(晚)· Issue#3:CMPP 服务端连接报 -1 + 充值无响应 + SrcID 核验口径
|
||||
|
||||
- **工单**:Gitea Issue#3「Bug:服务端CMPP链接-1」——s2demo 作服务端账号客户连接报 -1;页面充值点击无响应;通道号(接入码)SrcID(≤21位)是否需要核验。
|
||||
- **CMPP -1 根因**:`ConnectResp.Marshal` 把 Status 按 **1 字节**编码(18B 包体)= CMPP **3.0** 布局;而 **CMPP 2.0 规范 CMPP_CONNECT_RESP.Status 为 4 字节整数**(21B 包体;两版本恰与 SUBMIT_RESP.Result 互为镜像——2.0 Result=1B、3.0=4B,本项目 SubmitResp 按 2.0 实现且与真实上游联调通过,唯独 ConnectResp 误用 3.0 布局)。标准 2.0 客户端按 4B 大端解析读到 [status,MD5[0..2]] **恒非 0** → 客户端工具报 -1;自家客户端同按 1B 解析,自测格式对称掩盖缺陷(与 Day39 Submit 布局坑同构:模拟网关与实现同源同错)。
|
||||
- **修复(body.go)**:①`Marshal` Status 4B 大端(21B 包体);②`AuthenticatorISMG` 中 Status 以 4B 参与 MD5(2.0 规范);③`ParseConnectResp` 自适应双布局(≥20B 按 2.0 4B;17~19B 按 3.0 1B 兼容;短包取首字节)——自家客户端连真实上游 2.0 网关不再靠「status=0 时 b[0] 恰为零」侥幸,拒绝码也能正确读出。
|
||||
- **充值无响应根因(双重)**:①前端 `accountApi.recharge` 发 `{count,remark}`,后端 `rechargeReq` 要求 `{amount}`(`binding:"required,gt=0"`)→ 恒 400;②`AccountRecharge.vue` submit 无 catch,BizError 被静默吞掉 → 点击零反馈。修复:API 字段对齐 amount+mock 契约同步(msw handlers)+submit catch 提示(含 acc 未装载 warning 分支)。
|
||||
- **SrcID 核验口径**:CMPP 2.0 协议 Src_ID 定长 21 字节(协议层硬约束,parse 天然截断);平台核验=账号 ext_code 非空时前缀匹配(不匹配回 Result=9,s2demo 未配置故未生效)。AccountDetail 两处文案(接入信息+交付文本)明确「定长 ≤21 位+ext_code 前缀规则」,动态显示账号 ext_code。
|
||||
- **真机实证**:标准 2.0 客户端探针(纯标准库,4B 解析视角)——修复前 18B/Status=3222621(复现 -1);修复后(串行 build→kill→md5 部署)21B/Status=0 连接成功 ✓,错误密码 Status=2(标准语义码);充值 curl:count→ISC:400(复现被吞报错)/amount→ISC:000 余额 0→100 ✓,冒烟数据已还原。
|
||||
- **顺手修**:TestClient_LoginOK 时序竞争(网关 logins.Add 在 WritePacket 后,客户端握手完成与落账存在调度窗口,全量 -race 并行下偶发 0)→ 轮询 1s 吸收;全量复跑 **41 包全绿**。
|
||||
- **门禁**:vet 0/-race 41 包/lint 0;eslint 0/vue-tsc 0/vitest **165**/build 9.88s。
|
||||
|
||||
## 2026-11-16(傍晚)· Issue#2:管理前端多标签导航 + 页签缓存
|
||||
|
||||
- **工单**:Gitea Issue#2「优化:管理前端V1」——增加菜单 Tab 页(可独立关闭/一次全部关闭),切换后页面状态保留。
|
||||
|
||||
@@ -92,7 +92,7 @@ func VerifyAuth(sourceAddr, secret string, ts uint32, authenticator []byte) bool
|
||||
return true
|
||||
}
|
||||
|
||||
// ConnectResp 包体(status 1B + authenticator_ISMG 16B + version 1B)。
|
||||
// ConnectResp 包体(CMPP 2.0 规范:Status 4B 大端 + authenticator_ISMG 16B + version 1B = 21B)。
|
||||
type ConnectResp struct {
|
||||
Status byte
|
||||
Secret string // 计算服务端鉴权串
|
||||
@@ -100,29 +100,50 @@ type ConnectResp struct {
|
||||
}
|
||||
|
||||
// AuthenticatorISMG 计算服务端鉴权串:MD5(status + authenticatorSource + shared)。
|
||||
// Issue#3 修正:CMPP 2.0 规范中 Status 以 4 字节大端参与拼接(此前误用 1 字节)。
|
||||
func (r *ConnectResp) AuthenticatorISMG() []byte {
|
||||
sum := md5.Sum(append(append([]byte{r.Status}, r.AuthenticatorClient...), []byte(r.Secret)...))
|
||||
buf := make([]byte, 0, 4+len(r.AuthenticatorClient)+len(r.Secret))
|
||||
var st [4]byte
|
||||
binary.BigEndian.PutUint32(st[:], uint32(r.Status))
|
||||
buf = append(buf, st[:]...)
|
||||
buf = append(buf, r.AuthenticatorClient...)
|
||||
buf = append(buf, r.Secret...)
|
||||
sum := md5.Sum(buf)
|
||||
return sum[:]
|
||||
}
|
||||
|
||||
// Marshal 编码 ConnectResp 包体。
|
||||
// Issue#3 根因修复:CMPP 2.0 规范 CMPP_CONNECT_RESP 的 Status 为 4 字节整数
|
||||
// (与 3.0 的 1 字节不同——而 2.0 的 SUBMIT_RESP Result 恰为 1 字节,两版本在该
|
||||
// 两字段上互为镜像,极易混淆)。此前按 1B 编码(18B 包体),标准 2.0 客户端按
|
||||
// 4B 大端解析 Status 时读到 [status,MD5[0..2]] 恒非 0,客户连接被误判失败
|
||||
// (客户端工具报 -1);自家客户端同按 1B 解析,自测格式对称掩盖了缺陷。
|
||||
func (r *ConnectResp) Marshal() []byte {
|
||||
b := make([]byte, 1+16+1)
|
||||
b[0] = r.Status
|
||||
copy(b[1:17], r.AuthenticatorISMG())
|
||||
b[17] = 0x20
|
||||
b := make([]byte, 4+16+1)
|
||||
binary.BigEndian.PutUint32(b[0:4], uint32(r.Status))
|
||||
copy(b[4:20], r.AuthenticatorISMG())
|
||||
b[20] = 0x20
|
||||
return b
|
||||
}
|
||||
|
||||
// ParseConnectResp 解析 ConnectResp(客户端校验服务端身份用)。
|
||||
// 自适应两种规范布局(Issue#3):
|
||||
// - CMPP 2.0(≥20B):Status 4B 大端 + AuthenticatorISMG 16B(+Version 1B=21B)
|
||||
// - CMPP 3.0/兼容(17~19B):Status 1B + AuthenticatorISMG 16B(+Version 1B)
|
||||
// - 其余短包:取首字节(历史行为;主流网关均回完整包)。
|
||||
func ParseConnectResp(body []byte) (status byte, authenticatorISMG []byte, err error) {
|
||||
if len(body) < 1 {
|
||||
return 0, nil, errors.New("cmpp: connect_resp 包体为空")
|
||||
}
|
||||
if len(body) >= 17 {
|
||||
authenticatorISMG = body[1:17]
|
||||
if len(body) >= 20 { // CMPP 2.0 布局(4B Status)
|
||||
status = byte(binary.BigEndian.Uint32(body[0:4]))
|
||||
authenticatorISMG = body[4:20]
|
||||
return status, authenticatorISMG, nil
|
||||
}
|
||||
return body[0], authenticatorISMG, nil
|
||||
if len(body) >= 17 { // 3.0/兼容布局(1B Status)
|
||||
return body[0], body[1:17], nil
|
||||
}
|
||||
return body[0], nil, nil
|
||||
}
|
||||
|
||||
// ActiveTest 心跳包体(空)。
|
||||
|
||||
@@ -169,6 +169,12 @@ func TestClient_LoginOK(t *testing.T) {
|
||||
t.Fatalf("握手应成功: %v", err)
|
||||
}
|
||||
defer func() { _ = c.Close() }()
|
||||
// 网关侧 logins.Add 在 WritePacket 之后:客户端握手完成与计数落账存在
|
||||
// 调度窗口,全量 -race 并行下曾偶发 0(轮询吸收,免 flaky 阻塞门禁)。
|
||||
deadline := time.Now().Add(time.Second)
|
||||
for g.logins.Load() != 1 && time.Now().Before(deadline) {
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
if g.logins.Load() != 1 {
|
||||
t.Fatalf("网关成功登录数 = %d", g.logins.Load())
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package cmpp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -66,6 +67,9 @@ func TestConnectRespAuth(t *testing.T) {
|
||||
clientAuth := c.Authenticator(ts)
|
||||
resp := &ConnectResp{Status: 0, Secret: "pw", AuthenticatorClient: clientAuth}
|
||||
body := resp.Marshal()
|
||||
if len(body) != 21 { // Issue#3:CMPP 2.0 布局 4B+16B+1B
|
||||
t.Fatalf("connect_resp 包体应为 21 字节: %d", len(body))
|
||||
}
|
||||
status, ismg, err := ParseConnectResp(body)
|
||||
if err != nil || status != 0 || len(ismg) != 16 {
|
||||
t.Fatalf("解析: status=%d err=%v", status, err)
|
||||
@@ -76,6 +80,52 @@ func TestConnectRespAuth(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestConnectRespCmpp20StatusLayout Issue#3 回归:服务端 Status 必须按 CMPP 2.0
|
||||
// 规范编为 4 字节大端——此前 1B 编码(3.0 布局)致标准 2.0 客户端按 4B 解析读到
|
||||
// [status,MD5[0..2]] 恒非 0,客户连接被误判失败(客户端工具报 -1)。
|
||||
func TestConnectRespCmpp20StatusLayout(t *testing.T) {
|
||||
resp := &ConnectResp{Status: ConnectBadAuth, Secret: "pw",
|
||||
AuthenticatorClient: bytes.Repeat([]byte{0xAB}, 16)}
|
||||
body := resp.Marshal()
|
||||
if len(body) != 21 {
|
||||
t.Fatalf("CMPP 2.0 connect_resp 包体应为 21 字节(4+16+1): %d", len(body))
|
||||
}
|
||||
// 第三方标准 2.0 客户端视角:前 4 字节大端 uint32 即 Status
|
||||
if got := binary.BigEndian.Uint32(body[0:4]); got != uint32(ConnectBadAuth) {
|
||||
t.Fatalf("2.0 客户端按 4B 解析 Status=%d, 期望 %d", got, ConnectBadAuth)
|
||||
}
|
||||
// 成功路径:前 4 字节全零,任何布局客户端均读到 0
|
||||
ok := (&ConnectResp{Status: ConnectOK, Secret: "pw",
|
||||
AuthenticatorClient: bytes.Repeat([]byte{0x01}, 16)}).Marshal()
|
||||
if got := binary.BigEndian.Uint32(ok[0:4]); got != 0 {
|
||||
t.Fatalf("成功状态 4B 解析应全零: %d", got)
|
||||
}
|
||||
// 自家客户端自适应解析(21B → 2.0 布局)拒绝码同样正确
|
||||
status, ismg, err := ParseConnectResp(body)
|
||||
if err != nil || status != ConnectBadAuth || len(ismg) != 16 {
|
||||
t.Fatalf("自适应解析: status=%d ismg=%dB err=%v", status, len(ismg), err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseConnectRespAdaptive Issue#3:客户端自适应两种规范布局。
|
||||
// 2.0(21B/4B Status)与 3.0(18B/1B Status)网关均可正确读出状态码。
|
||||
func TestParseConnectRespAdaptive(t *testing.T) {
|
||||
// 3.0/兼容布局(1B status=3 + 16B auth + 1B ver)
|
||||
b18 := append([]byte{3}, bytes.Repeat([]byte{0x11}, 17)...)
|
||||
if st, ismg, err := ParseConnectResp(b18); err != nil || st != 3 || len(ismg) != 16 {
|
||||
t.Fatalf("18B 布局解析: st=%d ismg=%dB err=%v", st, len(ismg), err)
|
||||
}
|
||||
// 2.0 无 Version 变体(4B status + 16B = 20B)
|
||||
b20 := append([]byte{0, 0, 0, 4}, bytes.Repeat([]byte{0x22}, 16)...)
|
||||
if st, ismg, err := ParseConnectResp(b20); err != nil || st != 4 || len(ismg) != 16 {
|
||||
t.Fatalf("20B 布局解析: st=%d ismg=%dB err=%v", st, len(ismg), err)
|
||||
}
|
||||
// 空包拒绝
|
||||
if _, _, err := ParseConnectResp(nil); err == nil {
|
||||
t.Fatal("空包应拒绝")
|
||||
}
|
||||
}
|
||||
|
||||
// TestPacketReadWrite 包读写往返(WritePacket 自动补 TotalLength)。
|
||||
func TestPacketReadWrite(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# 当前工作上下文(最近更新:2026-11-16 下午)
|
||||
# 当前工作上下文(最近更新:2026-11-16 晚)
|
||||
|
||||
## 当前状态快照(2026-11-16,**S4 泳道收官,一期 18/27 计划日**)
|
||||
## 当前状态快照(2026-11-16,**Issue#3 已修复入库,S4 泳道收官,一期 18/27 计划日**)
|
||||
|
||||
- **Issue#3 三连修复(2026-11-16 晚)**:①CMPP 连接报 -1 根因=`ConnectResp` 误按 **3.0 的 1B Status** 编码(标准 2.0 客户端按 4B 大端解析恒非 0)→ 修复=Marshal 4B(21B 包体)+AuthenticatorISMG 4B 参与 MD5+`ParseConnectResp` 自适应双布局(≥20B/2.0,17~19B/3.0);标准 2.0 探针真机实证 18B/垃圾值→21B/Status=0,**教训:2.0 与 3.0 在 CONNECT_RESP.Status/SUBMIT_RESP.Result 上互为镜像(2.0=4B/1B),自家 client+server 同源对称自测掩盖协议错位——同 Day39 坑**;②充值无响应=前端发 `{count}` 后端要 `{amount}`+submit 无 catch 静默吞错 → API/mock/组件三处修复;③SrcID 核验口径=协议定长 21B+ext_code 前缀校验,AccountDetail 文案明确。顺手修 TestClient_LoginOK 时序竞争(轮询吸收);门禁 -race 41 包/vitest 165/build 全绿;gateway 已串行部署(md5 比对 ✓)。
|
||||
- **仓库**:main 已推 Gitea;每日 bundle+push 双轨。
|
||||
- **一期进度**:S0✅ S1✅ S2✅ / S3 ✅(11-15 凌晨)/ **S4 ✅ 收官(11-16,三项验收全过:死信可查/拒收即拉黑/冷查 16ms<1s)**——D1/D2=C1 回调推送引擎+ C2 上行自动拉黑(真机六步实证,验收单 s4-d1d2-callback.md);D3=明细按天 RANGE(id) 分区热 5 天(迁移 v22,9 分区)+CH 冷热归档 job(count 校验零丢失方向)+/record/history 冷查(settle-check 热窗感知 DetailPartial 两方基线;真机 5 连坑全修存档,验收单 s4-d3-partition-archive.md)。
|
||||
- **下一步=S5 基线与灰度(8 日,一期最后泳道)**:kind 安装+deploy/k8s manifests apply(NodePort 30081)→ 24h 稳定性复核(S4 动了大表结构,S5 压测前重跑一轮而非沿用 11-14 旧判)→ 压测基线 200QPS×30min(SSD 下重标 workers:4/55/s 等 HDD 数字)→ 消费参数重标定 → 灰度接管现网流量。**出口四项**:七件套全绿/P0+P1+结算覆盖矩阵全勾/SSD 基线报告入档/v2 承载 ≥1 周零 P0 事故+POC 转冷备。
|
||||
|
||||
@@ -438,11 +438,12 @@ export const handlers = [
|
||||
const id = Number(params.id)
|
||||
const acc = accountDB.find((a) => a.id === id)
|
||||
if (!acc) return fail('ISC:404', '资源不存在', 404)
|
||||
const body = (await request.json()) as { count: number; remark: string }
|
||||
if (!body.count || body.count <= 0) return fail('ISC:400', '充值条数必须大于 0')
|
||||
acc.balance += body.count
|
||||
// Issue#3:契约对齐真实后端 rechargeReq{amount, remark}(amount>0 必填)
|
||||
const body = (await request.json()) as { amount: number; remark: string }
|
||||
if (!body.amount || body.amount <= 0) return fail('ISC:400', '充值条数必须大于 0')
|
||||
acc.balance += body.amount
|
||||
balanceLogs.push({
|
||||
id: balanceLogs.length + 1, account_id: id, biz_type: 'recharge', amount: body.count,
|
||||
id: balanceLogs.length + 1, account_id: id, biz_type: 'recharge', amount: body.amount,
|
||||
balance_after: acc.balance, operator: 'admin', remark: body.remark || '后台充值',
|
||||
created_at: new Date().toISOString().slice(0, 19).replace('T', ' '),
|
||||
})
|
||||
|
||||
@@ -109,8 +109,9 @@ export const accountApi = {
|
||||
update: (id: number, body: Partial<Account>) => put<Account>(`/accounts/${id}`, body),
|
||||
setStatus: (id: number, status: number) => put<Account>(`/accounts/${id}/status`, { status }),
|
||||
remove: (id: number) => del<{ id: number }>(`/accounts/${id}`),
|
||||
recharge: (id: number, count: number, remark: string) =>
|
||||
post<{ balance: number }>(`/accounts/${id}/recharge`, { count, remark }),
|
||||
// Issue#3 修复:后端 rechargeReq 为 {amount, remark}(此前误发 count 致 400 被吞)。
|
||||
recharge: (id: number, amount: number, remark: string) =>
|
||||
post<{ balance: number }>(`/accounts/${id}/recharge`, { amount, remark }),
|
||||
balanceLogs: (id: number) => get<Paged<BalanceLog>>(`/accounts/${id}/balance_logs`),
|
||||
// Day 62:外部 API 配置(CMPP 密码/接入配额/交付块)
|
||||
getApiConfig: (id: number) => get<ApiConfig>(`/accounts/${id}/api-config`),
|
||||
|
||||
@@ -46,7 +46,9 @@
|
||||
<el-button link type="primary" style="margin-left: 8px" @click="showPwd = !showPwd">{{ showPwd ? '隐藏' : '显示' }}</el-button>
|
||||
<el-button link type="primary" :disabled="!apiCfg.cmpp_password" @click="copyText(apiCfg.cmpp_password, 'CMPP密码')">复制</el-button>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="通道号(接入码)">提交时 SrcID 自带(≤21位)</el-descriptions-item>
|
||||
<el-descriptions-item label="通道号(接入码)">
|
||||
提交时 SrcID 自带(CMPP 2.0 协议定长 ≤21 位){{ apiCfg.ext_code ? `;须以 ${apiCfg.ext_code} 为前缀,不匹配拒收(Result=9)` : ';未配置扩展码,暂不校验前缀' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="最大连接数">
|
||||
{{ apiCfg.cmpp_max_conns_effective }}{{ apiCfg.cmpp_max_conns ? '' : '(系统默认)' }}
|
||||
</el-descriptions-item>
|
||||
@@ -267,7 +269,7 @@ function deliveryText(): string {
|
||||
`连接端口:${c.cmpp_access?.port ?? '-'}`,
|
||||
`企业ID:${acc.value?.username ?? '-'}`,
|
||||
`CMPP密码:${c.cmpp_password}`,
|
||||
'通道号(接入码):提交时 SrcID 自带(≤21位)',
|
||||
`通道号(接入码):提交时 SrcID 自带(CMPP 2.0 定长 ≤21 位${c.ext_code ? `;须以 ${c.ext_code} 为前缀` : ''})`,
|
||||
`单链接速度:${c.cmpp_speed_effective} 条/秒`,
|
||||
`最大连接数:${c.cmpp_max_conns_effective}`,
|
||||
`协议版本:${c.cmpp_access?.version ?? 'CMPP 2.0'}`,
|
||||
|
||||
@@ -36,12 +36,18 @@ onMounted(async () => {
|
||||
})
|
||||
|
||||
async function submit() {
|
||||
if (!acc.value) return
|
||||
// Issue#3 修复:账号未装载/接口报错此前静默吞掉,页面表现为「点击无响应」。
|
||||
if (!acc.value) {
|
||||
ElMessage.warning('账号信息未加载,请刷新后重试')
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await accountApi.recharge(acc.value.id, count.value, remark.value)
|
||||
acc.value.balance = r.balance
|
||||
ElMessage.success(`充值成功,当前余额 ${r.balance}`)
|
||||
} catch (e) {
|
||||
ElMessage.error(e instanceof Error ? `充值失败:${e.message}` : '充值失败,请稍后重试')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user