feat: 卡实名时间以上游 archiveTime 为准并记录实名时间历史,新增二次实名批次
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled

This commit is contained in:
邹进
2026-11-08 19:12:46 +09:00
parent 94f86ab217
commit 4967f4df43
32 changed files with 1885 additions and 47 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"strconv"
"strings"
"time"
)
// FlexBool 灵活布尔类型
@@ -206,8 +207,17 @@ type CardOperationReq struct {
// RealnameStatusResp 是实名认证状态的响应
type RealnameStatusResp struct {
ICCID string `json:"iccid" description:"ICCID"`
RealStatus bool `json:"realStatus" description:"实名状态(true=已实名, false=未实名)"`
ICCID string `json:"iccid" description:"ICCID"`
RealStatus bool `json:"realStatus" description:"实名状态(true=已实名, false=未实名)"`
ArchiveTime *string `json:"archiveTime,omitempty" description:"上游实名时间(YYYY-MM-DD HH:mm:ss,北京时间;部分运营商不返回)"`
}
// UpstreamRealnameAt 返回上游实名时间:仅已实名且 archiveTime 可解析时有值;缺失、空、格式错误或未实名时返回 nil。
func (r *RealnameStatusResp) UpstreamRealnameAt() *time.Time {
if r == nil || !r.RealStatus || r.ArchiveTime == nil {
return nil
}
return parseUpstreamTime(*r.ArchiveTime)
}
// RealnameLinkResp 是实名认证链接的响应

View File

@@ -0,0 +1,25 @@
package gateway
import (
"strings"
"time"
)
// upstreamLocation 是上游时间字段的时区(北京时间,固定 +08:00,不依赖系统时区数据库)。
var upstreamLocation = time.FixedZone("CST", 8*3600)
var upstreamTimeLayouts = []string{"2006-01-02 15:04:05", "2006-01-02T15:04:05", "2006/01/02 15:04:05"}
// parseUpstreamTime 按北京时间解析上游时间字符串,空或无法解析返回 nil。
func parseUpstreamTime(raw string) *time.Time {
value := strings.TrimSpace(raw)
if value == "" || strings.EqualFold(value, "null") {
return nil
}
for _, layout := range upstreamTimeLayouts {
if parsed, err := time.ParseInLocation(layout, value, upstreamLocation); err == nil {
return &parsed
}
}
return nil
}

View File

@@ -0,0 +1,42 @@
package gateway
import (
"encoding/json"
"testing"
"time"
)
func TestRealnameStatusRespUpstreamRealnameAt(t *testing.T) {
cases := []struct {
name string
body string
want string
}{
{"移动返回实名时间", `{"archiveTime":"2026-07-16 19:43:39","iccid":"89860885192590574640","realStatus":true}`, "2026-07-16T19:43:39+08:00"},
{"电信不返回", `{"iccid":"8986112520903884400","realStatus":true}`, ""},
{"联通 extend 无时间", `{"extend":"已实名","iccid":"89860625750010460562","realStatus":true}`, ""},
{"未实名 null", `{"archiveTime":null,"iccid":"898608851925D1284902","realStatus":false}`, ""},
{"未实名但带时间忽略", `{"archiveTime":"2026-07-16 19:43:39","realStatus":false}`, ""},
{"空串", `{"archiveTime":"","realStatus":true}`, ""},
{"格式错误", `{"archiveTime":"07/16/2026","realStatus":true}`, ""},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
var resp RealnameStatusResp
if err := json.Unmarshal([]byte(tc.body), &resp); err != nil {
t.Fatalf("unmarshal: %v", err)
}
got := resp.UpstreamRealnameAt()
if tc.want == "" {
if got != nil {
t.Fatalf("want nil, got %v", got)
}
return
}
want, _ := time.Parse(time.RFC3339, tc.want)
if got == nil || !got.Equal(want) {
t.Fatalf("want %v, got %v", want, got)
}
})
}
}