开放接口,修复上游同步不对的问题
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m55s

This commit is contained in:
2026-05-11 11:20:48 +08:00
parent a9eaf1d697
commit 98ff88d5c3
25 changed files with 1432 additions and 39 deletions

View File

@@ -0,0 +1,73 @@
package constants
import "time"
// 代理开放接口请求头名称
const (
AgentOpenAPIHeaderAccount = "X-Agent-Account" // 开放接口账号请求头
AgentOpenAPIHeaderPassword = "X-Agent-Password" // 开放接口密码请求头
AgentOpenAPIHeaderTimestamp = "X-Agent-Timestamp" // 开放接口时间戳请求头
AgentOpenAPIHeaderNonce = "X-Agent-Nonce" // 开放接口随机串请求头
AgentOpenAPIHeaderSign = "X-Agent-Sign" // 开放接口签名请求头
)
// 代理开放接口签名配置
const (
AgentOpenAPISignatureWindow = 5 * time.Minute // 签名允许时间窗
AgentOpenAPIBatchNoPrefix = "AOP" // 开放接口批次号前缀
)
// 代理开放接口卡状态
const (
AgentOpenAPICardStatusNormal = "normal" // 正常
AgentOpenAPICardStatusStopped = "stopped" // 停机
AgentOpenAPIWalletCurrencyCNY = "CNY" // 人民币币种
)
// AgentOpenAPICardStatusName 返回开放接口卡状态名称
func AgentOpenAPICardStatusName(status string) string {
switch status {
case AgentOpenAPICardStatusNormal:
return "正常"
case AgentOpenAPICardStatusStopped:
return "停机"
default:
return "未知"
}
}
// AgentOpenAPIPackageTypeName 返回开放接口套餐类型名称
func AgentOpenAPIPackageTypeName(packageType string) string {
switch packageType {
case PackageTypeFormal:
return "正式套餐"
case PackageTypeAddon:
return "附加套餐"
default:
return "未知"
}
}
// AgentOpenAPIStopReasonName 返回开放接口停机原因名称
func AgentOpenAPIStopReasonName(reason string) string {
switch reason {
case StopReasonTrafficExhausted:
return "流量耗尽"
case StopReasonManual:
return "手动停机"
case StopReasonArrears:
return "欠费"
case StopReasonProtectPeriod:
return "保护期自动停机"
case StopReasonNoPackage:
return "无有效套餐"
case StopReasonNotRealname:
return "未完成实名认证"
case StopReasonCarrierStopped:
return "运营商侧停机"
case "":
return ""
default:
return "未知"
}
}

View File

@@ -57,6 +57,14 @@ const (
NetworkStatusOnline = 1 // 开机
)
// Gateway 卡状态
const (
GatewayCardStatusReady = "准备" // 网关卡状态:准备
GatewayCardStatusNormal = "正常" // 网关卡状态:正常
GatewayCardStatusStopped = "停机" // 网关卡状态:停机
GatewayCardExtendPendingActivation = "待激活" // 网关扩展状态:待激活
)
// IoT 卡停机原因
const (
StopReasonTrafficExhausted = "traffic_exhausted" // 流量耗尽

View File

@@ -13,6 +13,13 @@ func RedisAuthTokenKey(token string) string {
return fmt.Sprintf("auth:token:%s", token)
}
// RedisAgentOpenAPINonceKey 生成代理开放接口 nonce 防重放 Redis 键
// 用途:记录账号在签名时间窗内已使用的随机串,防止重复请求
// 过期时间:与开放接口签名时间窗一致
func RedisAgentOpenAPINonceKey(account, nonce string) string {
return fmt.Sprintf("agent_open_api:nonce:%s:%s", account, nonce)
}
// RedisRefreshTokenKey 生成刷新令牌的 Redis 键
// 用途:存储用户 refresh token 信息
// 过期时间7 天(可配置)