diff --git a/internal/application/product/product_application_service_impl.go b/internal/application/product/product_application_service_impl.go index 82be60d..d08a9da 100644 --- a/internal/application/product/product_application_service_impl.go +++ b/internal/application/product/product_application_service_impl.go @@ -1032,7 +1032,8 @@ func (s *ProductApplicationServiceImpl) getDTOMap() map[string]interface{} { "YYSY6F2E": &dto.YYSY6F2EReq{}, "YYSY09CD": &dto.YYSY09CDReq{}, "IVYZ0B03": &dto.IVYZ0B03Req{}, - "YYSYBE08": &dto.YYSYBE08Req{}, + "YYSYBE08": &dto.YYSYBE08Req{}, + "YYSYBE08TEST": &dto.YYSYBE08Req{}, "YYSYD50F": &dto.YYSYD50FReq{}, "YYSYF7DB": &dto.YYSYF7DBReq{}, "IVYZ9A2B": &dto.IVYZ9A2BReq{}, diff --git a/internal/domains/api/services/api_request_service.go b/internal/domains/api/services/api_request_service.go index dbe97dc..244cb25 100644 --- a/internal/domains/api/services/api_request_service.go +++ b/internal/domains/api/services/api_request_service.go @@ -241,35 +241,36 @@ func registerAllProcessors(combService *comb.CombService) { "QYGL8848": qygl.ProcessQYGL8848Request, //企业税收违法核查 // YYSY系列处理器 - "YYSY35TA": yysy.ProcessYYSY35TARequest, //运营商归属地数卖 - "YYSYD50F": yysy.ProcessYYSYD50FRequest, - "YYSY09CD": yysy.ProcessYYSY09CDRequest, - "YYSY4B21": yysy.ProcessYYSY4B21Request, - "YYSY4B37": yysy.ProcessYYSY4B37Request, - "YYSY6F2E": yysy.ProcessYYSY6F2ERequest, - "YYSYBE08": yysy.ProcessYYSYBE08Request, - "YYSYF7DB": yysy.ProcessYYSYF7DBRequest, - "YYSY4F2E": yysy.ProcessYYSY4F2ERequest, - "YYSY8B1C": yysy.ProcessYYSY8B1CRequest, - "YYSY6D9A": yysy.ProcessYYSY6D9ARequest, - "YYSY3E7F": yysy.ProcessYYSY3E7FRequest, - "YYSY8F3A": yysy.ProcessYYSY8F3ARequest, - "YYSY9A1B": yysy.ProcessYYSY9A1BRequest, - "YYSY8C2D": yysy.ProcessYYSY8C2DRequest, - "YYSY7D3E": yysy.ProcessYYSY7D3ERequest, - "YYSY9E4A": yysy.ProcessYYSY9E4ARequest, - "YYSY9F1B": yysy.ProcessYYSY9F1BYequest, - "YYSY6F2B": yysy.ProcessYYSY6F2BRequest, - "YYSY3M8S": yysy.ProcessYYSY3M8SRequest, //运营商二要素查询 - "YYSYC4R9": yysy.ProcessYYSYC4R9Request, //运营商三要素详版查询 - "YYSYH6D2": yysy.ProcessYYSYH6D2Request, //运营商三要素简版查询 - "YYSYP0T4": yysy.ProcessYYSYP0T4Request, //在网时长查询 - "YYSYE7V5": yysy.ProcessYYSYE7V5Request, //手机在网状态查询 - "YYSYS9W1": yysy.ProcessYYSYS9W1Request, //手机携号转网查询 - "YYSYK8R3": yysy.ProcessYYSYK8R3Request, //手机空号检测查询 - "YYSYH6F3": yysy.ProcessYYSYH6F3Request, //运营商三要素即时版查询 - "YYSYK9R4": yysy.ProcessYYSYK9R4Request, //全网手机三要素验证1979周更新版 - "YYSYF2T7": yysy.ProcessYYSYF2T7Request, //手机二次放号检测查询 + "YYSY35TA": yysy.ProcessYYSY35TARequest, //运营商归属地数卖 + "YYSYD50F": yysy.ProcessYYSYD50FRequest, + "YYSY09CD": yysy.ProcessYYSY09CDRequest, + "YYSY4B21": yysy.ProcessYYSY4B21Request, + "YYSY4B37": yysy.ProcessYYSY4B37Request, + "YYSY6F2E": yysy.ProcessYYSY6F2ERequest, + "YYSYBE08": yysy.ProcessYYSYBE08Request, + "YYSYBE08TEST": yysy.ProcessYYSYBE08testRequest, // 二要素(阿里云市场),与 YYSYBE08 入参一致 + "YYSYF7DB": yysy.ProcessYYSYF7DBRequest, + "YYSY4F2E": yysy.ProcessYYSY4F2ERequest, + "YYSY8B1C": yysy.ProcessYYSY8B1CRequest, + "YYSY6D9A": yysy.ProcessYYSY6D9ARequest, + "YYSY3E7F": yysy.ProcessYYSY3E7FRequest, + "YYSY8F3A": yysy.ProcessYYSY8F3ARequest, + "YYSY9A1B": yysy.ProcessYYSY9A1BRequest, + "YYSY8C2D": yysy.ProcessYYSY8C2DRequest, + "YYSY7D3E": yysy.ProcessYYSY7D3ERequest, + "YYSY9E4A": yysy.ProcessYYSY9E4ARequest, + "YYSY9F1B": yysy.ProcessYYSY9F1BYequest, + "YYSY6F2B": yysy.ProcessYYSY6F2BRequest, + "YYSY3M8S": yysy.ProcessYYSY3M8SRequest, //运营商二要素查询 + "YYSYC4R9": yysy.ProcessYYSYC4R9Request, //运营商三要素详版查询 + "YYSYH6D2": yysy.ProcessYYSYH6D2Request, //运营商三要素简版查询 + "YYSYP0T4": yysy.ProcessYYSYP0T4Request, //在网时长查询 + "YYSYE7V5": yysy.ProcessYYSYE7V5Request, //手机在网状态查询 + "YYSYS9W1": yysy.ProcessYYSYS9W1Request, //手机携号转网查询 + "YYSYK8R3": yysy.ProcessYYSYK8R3Request, //手机空号检测查询 + "YYSYH6F3": yysy.ProcessYYSYH6F3Request, //运营商三要素即时版查询 + "YYSYK9R4": yysy.ProcessYYSYK9R4Request, //全网手机三要素验证1979周更新版 + "YYSYF2T7": yysy.ProcessYYSYF2T7Request, //手机二次放号检测查询 // IVYZ系列处理器 "IVYZ0B03": ivyz.ProcessIVYZ0B03Request, diff --git a/internal/domains/api/services/form_config_service.go b/internal/domains/api/services/form_config_service.go index 39c9860..a62753c 100644 --- a/internal/domains/api/services/form_config_service.go +++ b/internal/domains/api/services/form_config_service.go @@ -114,7 +114,8 @@ func (s *FormConfigServiceImpl) getDTOStruct(ctx context.Context, apiCode string "YYSY6F2E": &dto.YYSY6F2EReq{}, "YYSY09CD": &dto.YYSY09CDReq{}, "IVYZ0B03": &dto.IVYZ0B03Req{}, - "YYSYBE08": &dto.YYSYBE08Req{}, + "YYSYBE08": &dto.YYSYBE08Req{}, + "YYSYBE08TEST": &dto.YYSYBE08Req{}, "YYSYD50F": &dto.YYSYD50FReq{}, "YYSYF7DB": &dto.YYSYF7DBReq{}, "IVYZ9A2B": &dto.IVYZ9A2BReq{}, diff --git a/internal/domains/api/services/processors/ivyz/ivyz2a8b_processor.go b/internal/domains/api/services/processors/ivyz/ivyz2a8b_processor.go index 57b584e..660a0f4 100644 --- a/internal/domains/api/services/processors/ivyz/ivyz2a8b_processor.go +++ b/internal/domains/api/services/processors/ivyz/ivyz2a8b_processor.go @@ -40,11 +40,11 @@ func ProcessIVYZ2A8BRequest(ctx context.Context, params []byte, deps *processors // 以表单方式调用数脉 API;参数在 CallAPIForm 内转为 application/x-www-form-urlencoded apiPath := "/v4/id_card/check" // 接口路径,根据数脉文档填写(如 v4/xxx) - + // 先尝试使用政务接口(app_id2 和 app_secret2) respBytes, err := deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData, true) if err != nil { - // 使用实时接口(app_id 和 app_secret)重试 + // 使用实时接口(app_id 和 app_secret)重试 respBytes, err = deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData, false) // 如果重试后仍然失败,或者原本就是查无记录错误,返回错误 if err != nil { diff --git a/internal/domains/api/services/processors/yysy/yysybe08_processor.go b/internal/domains/api/services/processors/yysy/yysybe08_processor.go index 74d348f..0652965 100644 --- a/internal/domains/api/services/processors/yysy/yysybe08_processor.go +++ b/internal/domains/api/services/processors/yysy/yysybe08_processor.go @@ -7,6 +7,8 @@ import ( "tyapi-server/internal/domains/api/dto" "tyapi-server/internal/domains/api/services/processors" + "tyapi-server/internal/infrastructure/external/alicloud" + "tyapi-server/internal/infrastructure/external/shumai" ) // ProcessYYSYBE08Request YYSYBE08 API处理方法 - 使用数脉二要素验证 @@ -33,24 +35,19 @@ func ProcessYYSYBE08Request(ctx context.Context, params []byte, deps *processors if err != nil { // 使用实时接口(app_id 和 app_secret)重试 respBytes, err = deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData, false) - // 如果重试后仍然失败,处理错误响应 - 转换为目标格式 + // 重试仍失败:阿里云身份证二要素兜底,返回原始 body;兜底仍失败则按阿里云错误类型返回(与 YYSY3M8S 对数脉的分流一致) if err != nil { - errorMsg := err.Error() - if errorMsg == "" { - errorMsg = "请求失败" + rawBytes, aerr := callAliyunIDCardCheckRaw(ctx, deps, paramsDto.Name, paramsDto.IDCard) + if aerr != nil { + if errors.Is(aerr, alicloud.ErrDatasource) { + return nil, errors.Join(processors.ErrDatasource, aerr) + } + if errors.Is(aerr, alicloud.ErrSystem) { + return nil, errors.Join(processors.ErrSystem, aerr) + } + return nil, errors.Join(processors.ErrSystem, aerr) } - errorResponse := map[string]interface{}{ - "ctidRequest": map[string]interface{}{ - "ctidAuth": map[string]interface{}{ - "idCard": paramsDto.IDCard, - "name": paramsDto.Name, - "resultCode": "5XXX", - "resultMsg": "数据源请求异常无记录", - "verifyResult": "", - }, - }, - } - return json.Marshal(errorResponse) + return rawBytes, nil } } diff --git a/internal/domains/api/services/processors/yysy/yysybe08_processor_test.go b/internal/domains/api/services/processors/yysy/yysybe08_processor_test.go deleted file mode 100644 index eb359b3..0000000 --- a/internal/domains/api/services/processors/yysy/yysybe08_processor_test.go +++ /dev/null @@ -1,158 +0,0 @@ -package yysy - -import ( - "encoding/json" - "testing" -) - -func TestYYSYBE08ResponseStructure(t *testing.T) { - // 测试响应结构构建逻辑 - resultCode := "1001" - resultMsg := "验证通过" - verifyResult := "一致" - - // 模拟阿里云返回result=0(一致)的情况 - alicloudResult := 0 - if alicloudResult == 0 { - // 验证成功 - resultCode = "1001" - resultMsg = "验证通过" - verifyResult = "一致" - } else { - // 验证失败 - resultCode = "1002" - resultMsg = "身份证号不匹配" - verifyResult = "不一致" - } - - // 构建响应结构 - response := map[string]interface{}{ - "ctidRequest": map[string]interface{}{ - "ctidAuth": map[string]interface{}{ - "resultCode": resultCode, - "resultMsg": resultMsg, - "name": "张荣宏", - "idCard": "45212220000827423X", - "verifyResult": verifyResult, - }, - }, - } - - // 序列化为JSON - jsonData, err := json.Marshal(response) - if err != nil { - t.Fatalf("JSON序列化失败: %v", err) - } - - // 验证JSON结构 - var parsedResponse map[string]interface{} - if err := json.Unmarshal(jsonData, &parsedResponse); err != nil { - t.Fatalf("JSON反序列化失败: %v", err) - } - - // 验证字段存在 - ctidRequest, exists := parsedResponse["ctidRequest"] - if !exists { - t.Fatal("响应中缺少ctidRequest字段") - } - - ctidAuth, exists := ctidRequest.(map[string]interface{})["ctidAuth"] - if !exists { - t.Fatal("响应中缺少ctidAuth字段") - } - - authData := ctidAuth.(map[string]interface{}) - - // 验证字段值 - expectedFields := map[string]string{ - "resultCode": "1001", - "resultMsg": "验证通过", - "name": "张荣宏", - "idCard": "45212220000827423X", - "verifyResult": "一致", - } - - for field, expectedValue := range expectedFields { - if authData[field] != expectedValue { - t.Errorf("字段%s期望值为%s,实际为%s", field, expectedValue, authData[field]) - } - } - - t.Logf("测试成功,响应结构: %s", string(jsonData)) -} - -func TestYYSYBE08ResponseStructure_Failure(t *testing.T) { - // 测试验证失败的情况 - resultCode := "1002" - resultMsg := "身份证号不匹配" - verifyResult := "不一致" - - // 模拟阿里云返回result=1(不一致)的情况 - alicloudResult := 1 - if alicloudResult == 0 { - // 验证成功 - resultCode = "1001" - resultMsg = "验证通过" - verifyResult = "一致" - } else { - // 验证失败 - resultCode = "1002" - resultMsg = "身份证号不匹配" - verifyResult = "不一致" - } - - // 构建响应结构 - response := map[string]interface{}{ - "ctidRequest": map[string]interface{}{ - "ctidAuth": map[string]interface{}{ - "resultCode": resultCode, - "resultMsg": resultMsg, - "name": "张三", - "idCard": "110101199001011235", - "verifyResult": verifyResult, - }, - }, - } - - // 序列化为JSON - jsonData, err := json.Marshal(response) - if err != nil { - t.Fatalf("JSON序列化失败: %v", err) - } - - // 验证JSON结构 - var parsedResponse map[string]interface{} - if err := json.Unmarshal(jsonData, &parsedResponse); err != nil { - t.Fatalf("JSON反序列化失败: %v", err) - } - - // 验证字段存在 - ctidRequest, exists := parsedResponse["ctidRequest"] - if !exists { - t.Fatal("响应中缺少ctidRequest字段") - } - - ctidAuth, exists := ctidRequest.(map[string]interface{})["ctidAuth"] - if !exists { - t.Fatal("响应中缺少ctidAuth字段") - } - - authData := ctidAuth.(map[string]interface{}) - - // 验证字段值 - expectedFields := map[string]string{ - "resultCode": "1002", - "resultMsg": "身份证号不匹配", - "name": "张三", - "idCard": "110101199001011235", - "verifyResult": "不一致", - } - - for field, expectedValue := range expectedFields { - if authData[field] != expectedValue { - t.Errorf("字段%s期望值为%s,实际为%s", field, expectedValue, authData[field]) - } - } - - t.Logf("测试成功,失败响应结构: %s", string(jsonData)) -} \ No newline at end of file diff --git a/internal/domains/api/services/processors/yysy/yysybe08test_processor.go b/internal/domains/api/services/processors/yysy/yysybe08test_processor.go new file mode 100644 index 0000000..1c29861 --- /dev/null +++ b/internal/domains/api/services/processors/yysy/yysybe08test_processor.go @@ -0,0 +1,34 @@ +package yysy + +import ( + "context" + "encoding/json" + "errors" + + "tyapi-server/internal/domains/api/dto" + "tyapi-server/internal/domains/api/services/processors" +) + +// ProcessYYSYBE08testRequest 与 YYSYBE08 相同入参,底层使用阿里云市场身份证二要素校验;响应为阿里云接口原始 body(不做字段映射) +func ProcessYYSYBE08testRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) { + var paramsDto dto.YYSYBE08Req + if err := json.Unmarshal(params, ¶msDto); err != nil { + return nil, errors.Join(processors.ErrSystem, err) + } + + if err := deps.Validator.ValidateStruct(paramsDto); err != nil { + return nil, errors.Join(processors.ErrInvalidParam, err) + } + + return callAliyunIDCardCheckRaw(ctx, deps, paramsDto.Name, paramsDto.IDCard) +} + +// callAliyunIDCardCheckRaw POST api-mall/api/id_card/check(form: name、idcard),返回响应体原文,供 YYSYBE08TEST 与 YYSYBE08 数脉失败兜底共用 +func callAliyunIDCardCheckRaw(ctx context.Context, deps *processors.ProcessorDependencies, name, idCard string) ([]byte, error) { + _ = ctx + reqData := map[string]interface{}{ + "name": name, + "idcard": idCard, + } + return deps.AlicloudService.CallAPI("api-mall/api/id_card/check", reqData) +}