fix: 适配 Gateway 响应模型变更,更新轮询处理器和 Mock 服务
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m25s

- polling_handler: Status→RealStatus, UsedFlow→Used, parseRealnameStatus 参数改为 bool
- mock_gateway: 同步接口路径和响应结构与上游文档一致
This commit is contained in:
2026-03-07 11:29:40 +08:00
parent a83dca2eb2
commit 86f8d0b644
2 changed files with 14 additions and 18 deletions

View File

@@ -45,7 +45,7 @@ func main() {
}
// 实名查询接口(匹配 gateway client 的路径)
http.HandleFunc("/flow-card/realname-status", handleRealnameQuery)
http.HandleFunc("/flow-card/realName", handleRealnameQuery)
// 流量查询接口
http.HandleFunc("/flow-card/flow", handleFlowQuery)
@@ -67,7 +67,7 @@ func main() {
fmt.Println("模拟响应时间: 200ms - 4s")
fmt.Println("")
fmt.Println("接口列表:")
fmt.Println(" POST /flow-card/realname-status - 实名查询")
fmt.Println(" POST /flow-card/realName - 实名查询")
fmt.Println(" POST /flow-card/flow - 流量查询")
fmt.Println(" POST /flow-card/status - 卡状态查询")
fmt.Println(" POST /flow-card/cardStop - 停机操作")
@@ -112,14 +112,13 @@ func handleRealnameQuery(w http.ResponseWriter, r *http.Request) {
// 90% 成功10% 失败
if rand.Float64() < 0.90 {
atomic.AddInt64(&successRequests, 1)
// 随机返回实名状态
statuses := []string{"未实名", "实名中", "已实名"}
status := statuses[rand.Intn(3)]
// 随机返回实名状态匹配文档realStatus 为 bool 类型)
realStatus := rand.Float64() < 0.5
resp := GatewayResponse{
Code: 200,
Msg: "success",
TraceID: fmt.Sprintf("trace-%d", time.Now().UnixNano()),
Data: json.RawMessage(fmt.Sprintf(`{"status": "%s"}`, status)),
Data: json.RawMessage(fmt.Sprintf(`{"iccid": "mock-iccid", "realStatus": %t}`, realStatus)),
}
json.NewEncoder(w).Encode(resp)
} else {
@@ -140,13 +139,13 @@ func handleFlowQuery(w http.ResponseWriter, r *http.Request) {
if rand.Float64() < 0.90 {
atomic.AddInt64(&successRequests, 1)
// 随机返回流量数据(匹配 FlowUsageResp 结构
// 随机返回流量数据(匹配文档used 字段
usedFlow := rand.Intn(10000)
resp := GatewayResponse{
Code: 200,
Msg: "success",
TraceID: fmt.Sprintf("trace-%d", time.Now().UnixNano()),
Data: json.RawMessage(fmt.Sprintf(`{"usedFlow": %d, "unit": "MB"}`, usedFlow)),
Data: json.RawMessage(fmt.Sprintf(`{"iccid": "mock-iccid", "used": %d, "unit": "MB"}`, usedFlow)),
}
json.NewEncoder(w).Encode(resp)
} else {