This commit is contained in:
Mrx
2026-01-24 11:36:41 +08:00
parent 4664c06c03
commit 37ce65d6f7
5 changed files with 124 additions and 23 deletions

View File

@@ -195,7 +195,7 @@ func registerAllProcessors(combService *comb.CombService) {
"YYSYE7V5": yysy.ProcessYYSYE7V5Request, //手机在网状态查询 "YYSYE7V5": yysy.ProcessYYSYE7V5Request, //手机在网状态查询
"YYSYS9W1": yysy.ProcessYYSYS9W1Request, //手机携号转网查询 "YYSYS9W1": yysy.ProcessYYSYS9W1Request, //手机携号转网查询
"YYSYK8R3": yysy.ProcessYYSYK8R3Request, //手机空号检测查询 "YYSYK8R3": yysy.ProcessYYSYK8R3Request, //手机空号检测查询
"YYSYF2T7": yysy.ProcessYYSYF2T7Request, //手机二次放号检测查询 "YYSYH6F3": yysy.ProcessYYSYH6F3Request, //运营商三要素即时版查询
// IVYZ系列处理器 // IVYZ系列处理器
"IVYZ0B03": ivyz.ProcessIVYZ0B03Request, "IVYZ0B03": ivyz.ProcessIVYZ0B03Request,
@@ -231,9 +231,9 @@ func registerAllProcessors(combService *comb.CombService) {
"IVYZSFEL": ivyz.ProcessIVYZSFELRequest, //全国自然人人像三要素核验_V1 "IVYZSFEL": ivyz.ProcessIVYZSFELRequest, //全国自然人人像三要素核验_V1
"IVYZ0S0D": ivyz.ProcessIVYZ0S0DRequest, //劳动仲裁信息查询(个人版) "IVYZ0S0D": ivyz.ProcessIVYZ0S0DRequest, //劳动仲裁信息查询(个人版)
"IVYZ1J7H": ivyz.ProcessIVYZ1J7HRequest, //行驶证核查v2 "IVYZ1J7H": ivyz.ProcessIVYZ1J7HRequest, //行驶证核查v2
"IVYZ9K7F": ivyz.ProcessIVYZ9K7FRequest, //身份证实名认证 "IVYZ9K7F": ivyz.ProcessIVYZ9K7FRequest, //身份证实名认证即时版
"IVYZA1B3": ivyz.ProcessIVYZA1B3Request, //公安三要素人脸识别 "IVYZA1B3": ivyz.ProcessIVYZA1B3Request, //公安三要素人脸识别
"IVYZN2P8": ivyz.ProcessIVYZN2P8Request, //身份证实名认证即时版本 "IVYZN2P8": ivyz.ProcessIVYZN2P8Request, //身份证实名认证政务版
// COMB系列处理器 - 只注册有自定义逻辑的组合包 // COMB系列处理器 - 只注册有自定义逻辑的组合包
"COMB86PM": comb.ProcessCOMB86PMRequest, // 有自定义逻辑重命名ApiCode "COMB86PM": comb.ProcessCOMB86PMRequest, // 有自定义逻辑重命名ApiCode

View File

@@ -228,10 +228,10 @@ func (s *FormConfigServiceImpl) getDTOStruct(ctx context.Context, apiCode string
"JRZQO6L7": &dto.JRZQO6L7Req{}, //全国自然人经济特征评分模型v3 简版 "JRZQO6L7": &dto.JRZQO6L7Req{}, //全国自然人经济特征评分模型v3 简版
"JRZQO7L1": &dto.JRZQO7L1Req{}, //全国自然人经济特征评分模型v4 详版 "JRZQO7L1": &dto.JRZQO7L1Req{}, //全国自然人经济特征评分模型v4 详版
"JRZQS7G0": &dto.JRZQS7G0Req{}, //社保综合评分V1 "JRZQS7G0": &dto.JRZQS7G0Req{}, //社保综合评分V1
"IVYZ9K7F": &dto.IVYZ9K7FReq{}, //身份证实名认证 "IVYZ9K7F": &dto.IVYZ9K7FReq{}, //身份证实名认证即时版
"YYSY3M8S": &dto.YYSY3M8SReq{}, //运营商二要素查询 "YYSY3M8S": &dto.YYSY3M8SReq{}, //运营商二要素查询
"YYSYC4R9": &dto.YYSYC4R9Req{}, //运营商三要素详版查询 "YYSYC4R9": &dto.YYSYC4R9Req{}, //运营商三要素详版查询
"YYSYH6D2": &dto.YYSYH6D2Req{}, //运营商三要素简版查询 "YYSYH6D2": &dto.YYSYH6D2Req{}, //运营商三要素简版政务版查询
"YYSYP0T4": &dto.YYSYP0T4Req{}, //在网时长查询 "YYSYP0T4": &dto.YYSYP0T4Req{}, //在网时长查询
"YYSYE7V5": &dto.YYSYE7V5Req{}, //手机在网状态查询 "YYSYE7V5": &dto.YYSYE7V5Req{}, //手机在网状态查询
"YYSYS9W1": &dto.YYSYS9W1Req{}, //手机携号转网查询 "YYSYS9W1": &dto.YYSYS9W1Req{}, //手机携号转网查询
@@ -239,7 +239,8 @@ func (s *FormConfigServiceImpl) getDTOStruct(ctx context.Context, apiCode string
"YYSYF2T7": &dto.YYSYF2T7Req{}, //手机二次放号检测查询 "YYSYF2T7": &dto.YYSYF2T7Req{}, //手机二次放号检测查询
"IVYZA1B3": &dto.IVYZA1B3Req{}, //公安三要素人脸识别 "IVYZA1B3": &dto.IVYZA1B3Req{}, //公安三要素人脸识别
"IVYZX5QZ": &dto.IVYZX5QZReq{}, //活体识别 "IVYZX5QZ": &dto.IVYZX5QZReq{}, //活体识别
"IVYZN2P8": &dto.IVYZ9K7FReq{}, //身份证实名认证即时版本 "IVYZN2P8": &dto.IVYZ9K7FReq{}, //身份证实名认证政务版
"YYSYH6F3": &dto.YYSYH6F3Req{}, //运营商三要素简版即时版查询
} }

View File

@@ -10,7 +10,7 @@ import (
"tyapi-server/internal/infrastructure/external/shumai" "tyapi-server/internal/infrastructure/external/shumai"
) )
// ProcessIVYZ9K7FRequest IVYZ9K7F 身份证实名认证 API处理方法 // ProcessIVYZ9K7FRequest IVYZ9K7F 身份证实名认证即时版 API处理方法
func ProcessIVYZ9K7FRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) { func ProcessIVYZ9K7FRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
var paramsDto dto.IVYZ9K7FReq var paramsDto dto.IVYZ9K7FReq
if err := json.Unmarshal(params, &paramsDto); err != nil { if err := json.Unmarshal(params, &paramsDto); err != nil {

View File

@@ -4,12 +4,39 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"strconv"
"strings"
"time"
"tyapi-server/internal/domains/api/dto" "tyapi-server/internal/domains/api/dto"
"tyapi-server/internal/domains/api/services/processors" "tyapi-server/internal/domains/api/services/processors"
"tyapi-server/internal/infrastructure/external/xingwei" "tyapi-server/internal/infrastructure/external/shumai"
) )
// shumaiMobileThreeResp 数脉 /v4/mobile_three/check 返回的 data 结构
// result: 0-一致收费 1-不一致收费 2-无记录不收费
type shumaiMobileThreeResp struct {
OrderNo string `json:"order_no"`
Result string `json:"result"`
Desc string `json:"desc"`
Channel string `json:"channel"`
Sex string `json:"sex"`
Birthday string `json:"birthday"`
Address string `json:"address"`
}
// yysy9a1bOut 最终返回格式
// result: 01一致 02不一致 03不确定 04失败/虚拟号type: 1移动 2联通 3电信 4广电
type yysy9a1bOut struct {
OrderNo string `json:"orderNo"`
HandleTime string `json:"handleTime"`
Type string `json:"type"` // 1:移动 2:联通 3:电信 4:广电
Result string `json:"result"`
Gender string `json:"gender"`
Age string `json:"age"`
Remark string `json:"remark"`
}
// ProcessYYSY9A1BRequest YYSY9A1B API处理方法 - 运营商三要素查询 // ProcessYYSY9A1BRequest YYSY9A1B API处理方法 - 运营商三要素查询
func ProcessYYSY9A1BRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) { func ProcessYYSY9A1BRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
var paramsDto dto.YYSY9A1BReq var paramsDto dto.YYSY9A1BReq
@@ -20,28 +47,101 @@ func ProcessYYSY9A1BRequest(ctx context.Context, params []byte, deps *processors
if err := deps.Validator.ValidateStruct(paramsDto); err != nil { if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
return nil, errors.Join(processors.ErrInvalidParam, err) return nil, errors.Join(processors.ErrInvalidParam, err)
} }
reqFormData := map[string]interface{}{
// 构建请求数据,将项目规范的字段名转换为 XingweiService 需要的字段名 "idcard": paramsDto.IDCard,
reqData := map[string]interface{}{ "name": paramsDto.Name,
"name": paramsDto.Name, "mobile": paramsDto.MobileNo,
"idCardNum": paramsDto.IDCard,
"phoneNumber": paramsDto.MobileNo,
} }
// 调用行为数据API使用指定的project_id // 以表单方式调用数脉 API参数在 CallAPIForm 内转为 application/x-www-form-urlencoded
projectID := "CDJ-1100244697766359040" deps.ShumaiService.UseGovernment()
respBytes, err := deps.XingweiService.CallAPI(ctx, projectID, reqData) apiPath := "/v4/mobile_three/check"
respBytes, err := deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData)
if err != nil { if err != nil {
if errors.Is(err, xingwei.ErrNotFound) { if errors.Is(err, shumai.ErrDatasource) {
return nil, errors.Join(processors.ErrNotFound, err)
} else if errors.Is(err, xingwei.ErrDatasource) {
return nil, errors.Join(processors.ErrDatasource, err) return nil, errors.Join(processors.ErrDatasource, err)
} else if errors.Is(err, xingwei.ErrSystem) { } else if errors.Is(err, shumai.ErrSystem) {
return nil, errors.Join(processors.ErrSystem, err) return nil, errors.Join(processors.ErrSystem, err)
} else { } else {
return nil, errors.Join(processors.ErrSystem, err) return nil, errors.Join(processors.ErrSystem, err)
} }
} }
return respBytes, nil // 将数脉 data 映射为最终返回格式
out, err := mapShumaiMobileThreeToYYSY9A1B(respBytes)
if err != nil {
return nil, errors.Join(processors.ErrSystem, err)
}
return json.Marshal(out)
}
// mapShumaiMobileThreeToYYSY9A1B 数脉 mobile_three/check 的 data -> 最终格式
// result: 0->01 1->02 2->04 其它->04gender: 男->1 女->2type: cmcc->1 cucc->2 ctcc->3 gdcc->4
func mapShumaiMobileThreeToYYSY9A1B(dataBytes []byte) (*yysy9a1bOut, error) {
var r shumaiMobileThreeResp
if err := json.Unmarshal(dataBytes, &r); err != nil {
return nil, err
}
// result: 01一致 02不一致 03不确定 04失败/虚拟号;原 2-无记录 及 其它 均映射为 04
var res string
switch strings.TrimSpace(r.Result) {
case "0":
res = "01"
case "1":
res = "02"
case "2":
res = "04"
default:
res = "04"
}
// type: 运营商 channel -> 1移动 2联通 3电信 4广电cmcc/cucc/ctcc/gdcc未知为空
ch := strings.ToLower(strings.TrimSpace(r.Channel))
var chType string
switch ch {
case "cmcc":
chType = "1"
case "cucc":
chType = "2"
case "ctcc":
chType = "3"
case "gdcc":
chType = "4"
}
// gender: 男->1 女->2
sex := strings.TrimSpace(r.Sex)
var gender string
if sex == "男" {
gender = "1"
} else if sex == "女" {
gender = "2"
}
return &yysy9a1bOut{
OrderNo: r.OrderNo,
HandleTime: time.Now().Format("2006-01-02 15:04:05"),
Type: chType,
Result: res,
Gender: gender,
Age: ageFromBirthday(r.Birthday),
Remark: r.Desc,
}, nil
}
func ageFromBirthday(s string) string {
s = strings.TrimSpace(s)
if len(s) < 4 {
return ""
}
y, err := strconv.Atoi(s[0:4])
if err != nil || y <= 0 {
return ""
}
age := time.Now().Year() - y
if age < 0 {
age = 0
}
return strconv.Itoa(age)
} }

View File

@@ -10,7 +10,7 @@ import (
"tyapi-server/internal/infrastructure/external/shumai" "tyapi-server/internal/infrastructure/external/shumai"
) )
// ProcessYYSYH6F3Request YYSYH6F3 运营商三要素政务版API处理方法 // ProcessYYSYH6F3Request YYSYH6F3 运营商三要素即时版API处理方法
func ProcessYYSYH6F3Request(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) { func ProcessYYSYH6F3Request(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
var paramsDto dto.YYSYH6F3Req var paramsDto dto.YYSYH6F3Req
if err := json.Unmarshal(params, &paramsDto); err != nil { if err := json.Unmarshal(params, &paramsDto); err != nil {