From 4e359060e61985623842cf7f2a21129c506aef87 Mon Sep 17 00:00:00 2001 From: Mrx <18278715334@163.com> Date: Wed, 28 Jan 2026 16:58:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0=E7=BC=9D=E6=9B=BF=E6=8D=A2=E8=A5=BF?= =?UTF-8?q?=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/services/form_config_service.go | 2 +- .../processors/yysy/yysyf7db_processor.go | 106 ++++++++++++++---- 2 files changed, 88 insertions(+), 20 deletions(-) diff --git a/internal/domains/api/services/form_config_service.go b/internal/domains/api/services/form_config_service.go index 4a4beda..fb3f091 100644 --- a/internal/domains/api/services/form_config_service.go +++ b/internal/domains/api/services/form_config_service.go @@ -424,7 +424,7 @@ func (s *FormConfigServiceImpl) generateFieldLabel(jsonTag string) string { "legal_person": "法人姓名", "ent_code": "企业代码", "auth_date": "授权日期", - "date_range": "数据范围", + "date_range": "日期范围", "time_range": "时间范围", "authorized": "是否授权", "authorization_url": "授权链接", diff --git a/internal/domains/api/services/processors/yysy/yysyf7db_processor.go b/internal/domains/api/services/processors/yysy/yysyf7db_processor.go index ae4be9c..d2f3b13 100644 --- a/internal/domains/api/services/processors/yysy/yysyf7db_processor.go +++ b/internal/domains/api/services/processors/yysy/yysyf7db_processor.go @@ -4,13 +4,23 @@ import ( "context" "encoding/json" "errors" + "strings" + "time" "tyapi-server/internal/domains/api/dto" "tyapi-server/internal/domains/api/services/processors" - "tyapi-server/internal/infrastructure/external/westdex" + "tyapi-server/internal/infrastructure/external/shumai" ) -// YYSYF7DBResponse 手机二次卡查询成功响应 +// westdexG19BJ02Resp 上游 G19BJ02 实际返回结构:order_no->guid, result->code, channel->phoneType, desc->msg +type westdexG19BJ02Resp struct { + Result int `json:"result"` // 0-是二次卡 1-不是二次卡 2-数据库中无信息(预留) + OrderNo string `json:"orderNo"` + Channel string `json:"channel"` // cmcc/cucc/ctcc + Desc string `json:"desc"` +} + +// YYSYF7DBResponse 手机二次卡查询成功响应(最终返回结构) type YYSYF7DBResponse struct { Code string `json:"code"` Data YYSYF7DBResponseData `json:"data"` @@ -20,9 +30,9 @@ type YYSYF7DBResponse struct { type YYSYF7DBResponseData struct { Code int `json:"code"` EncryptType string `json:"encryptType"` - Guid string `json:"guid"` - Msg string `json:"msg"` - PhoneType string `json:"phoneType"` + Guid string `json:"guid"` // 来自 order_no + Msg string `json:"msg"` // 来自 desc,按 result:0-是二次卡 1-不是二次卡 + PhoneType string `json:"phoneType"` // 来自 channel:cmcc->CMCC 等 } // ProcessYYSYF7DBRequest YYSYF7DB API处理方法 @@ -36,30 +46,88 @@ func ProcessYYSYF7DBRequest(ctx context.Context, params []byte, deps *processors return nil, errors.Join(processors.ErrInvalidParam, err) } - encryptedMobileNo, err := deps.WestDexService.Encrypt(paramsDto.MobileNo) - if err != nil { - return nil, errors.Join(processors.ErrSystem, err) + // 组装日期:开始日期 + 当前日期(YYYYMMDD-YYYYMMDD) + today := time.Now().Format("20060102") + dateRange := paramsDto.StartDate + "-" + today + + reqFormData := map[string]interface{}{ + "mobile": paramsDto.MobileNo, + "date": dateRange, } - reqData := map[string]interface{}{ - "data": map[string]interface{}{ - "phone": encryptedMobileNo, - "startDate": paramsDto.StartDate, // StartDate 有 encrypt:"false" 标签,不加密 - }, - } - - respBytes, err := deps.WestDexService.CallAPI(ctx, "G19BJ02", reqData) + // 以表单方式调用数脉 API;参数在 CallAPIForm 内转为 application/x-www-form-urlencoded + apiPath := "/v4/mobile_twice/check" // 接口路径,根据数脉文档填写( + respBytes, err := deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData) if err != nil { - if errors.Is(err, westdex.ErrDatasource) { + if errors.Is(err, shumai.ErrDatasource) { + // 数据源错误 return nil, errors.Join(processors.ErrDatasource, err) + } else if errors.Is(err, shumai.ErrSystem) { + // 系统错误 + return nil, errors.Join(processors.ErrSystem, err) } else { + // 其他未知错误 return nil, errors.Join(processors.ErrSystem, err) } } - var mapped YYSYF7DBResponse - if err := json.Unmarshal(respBytes, &mapped); err != nil { + mapped, err := mapWestdexG19BJ02ToYYSYF7DB(respBytes) + if err != nil { return nil, errors.Join(processors.ErrSystem, err) } return json.Marshal(mapped) } + +// mapWestdexG19BJ02ToYYSYF7DB 将上游 result/orderNo/channel/desc 映射为最终 code/data 结构 +// result: 0->1025(是二次卡) 1->1026(不是二次卡) 2->1027(数据库中无信息);channel: cmcc->CMCC cucc->CUCC ctcc->CTCC +func mapWestdexG19BJ02ToYYSYF7DB(dataBytes []byte) (*YYSYF7DBResponse, error) { + var r westdexG19BJ02Resp + if err := json.Unmarshal(dataBytes, &r); err != nil { + return nil, err + } + + var codeStr string + var codeInt int + var msg string + switch r.Result { + case 0: + codeStr = "1025" + codeInt = 1025 + msg = "二次卡" + case 1: + codeStr = "1026" + codeInt = 1026 + msg = "不是二次卡" + default: + codeStr = "1027" + codeInt = 1027 + msg = "不是二次卡" + } + if r.Desc != "" { + msg = strings.TrimSpace(r.Desc) + } + + ch := strings.ToLower(strings.TrimSpace(r.Channel)) + var phoneType string + switch ch { + case "cmcc": + phoneType = "CMCC" + case "cucc": + phoneType = "CUCC" + case "ctcc": + phoneType = "CTCC" + default: + phoneType = "UNKNOWN" + } + + return &YYSYF7DBResponse{ + Code: codeStr, + Data: YYSYF7DBResponseData{ + Code: codeInt, + EncryptType: "MD5", + Guid: r.OrderNo, + Msg: msg, + PhoneType: phoneType, + }, + }, nil +}