diff --git a/internal/domains/api/services/processors/yysy/yysybe08_processor.go b/internal/domains/api/services/processors/yysy/yysybe08_processor.go index a35981f..8a6d961 100644 --- a/internal/domains/api/services/processors/yysy/yysybe08_processor.go +++ b/internal/domains/api/services/processors/yysy/yysybe08_processor.go @@ -32,53 +32,81 @@ func ProcessYYSYBE08Request(ctx context.Context, params []byte, deps *processors apiPath := "/v4/id_card/check" respBytes, err := deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData) if err != nil { - // 处理错误响应 - var errorCode int - var errorMsg string - // 构建错误响应 - errorResponse := map[string]interface{}{ - "msg": errorMsg, - "success": false, - "code": errorCode, - "data": map[string]interface{}{}, + // 处理错误响应 - 转换为目标格式 + errorMsg := err.Error() + if errorMsg == "" { + errorMsg = "请求失败" } - - return json.Marshal(errorResponse) - } - - // 解析数脉响应数据 - var shumaiData struct { - Result int `json:"result"` - OrderNo string `json:"order_no"` - Desc string `json:"desc"` - Sex string `json:"sex"` - Birthday string `json:"birthday"` - Address string `json:"address"` - } - - if err := json.Unmarshal(respBytes, &shumaiData); err != nil { - // 解析失败,返回系统错误 errorResponse := map[string]interface{}{ - "msg": "响应解析失败", - "success": false, - "code": 500, - "data": map[string]interface{}{}, + "ctidRequest": map[string]interface{}{ + "ctidAuth": map[string]interface{}{ + "idCard": paramsDto.IDCard, + "name": paramsDto.Name, + "resultCode": "5XXX", + "resultMsg": errorMsg, + "verifyResult": "", + }, + }, } return json.Marshal(errorResponse) } - // 构建成功响应 + // 解析数脉响应数据 - 先解析外层结构 + var shumaiResp struct { + Code int `json:"code"` + Msg string `json:"msg"` + Message string `json:"message"` + Data struct { + Result int `json:"result"` + OrderNo string `json:"order_no"` + Desc string `json:"desc"` + Sex string `json:"sex"` + Birthday string `json:"birthday"` + Address string `json:"address"` + } `json:"data"` + } + + if err := json.Unmarshal(respBytes, &shumaiResp); err != nil { + // 解析失败,返回系统错误 - 转换为目标格式 + errorResponse := map[string]interface{}{ + "ctidRequest": map[string]interface{}{ + "ctidAuth": map[string]interface{}{ + "idCard": paramsDto.IDCard, + "name": paramsDto.Name, + "resultCode": "500", + "resultMsg": "响应解析失败", + "verifyResult": "", + }, + }, + } + return json.Marshal(errorResponse) + } + + // 根据 verifyResult (desc) 设置 resultCode + // 0XXX: 一致, 5XXX: 不一致 + resultCode := "5XXX" // 默认为不一致 + if shumaiResp.Data.Desc == "一致" { + resultCode = "0XXX" + } + + resultMsg := shumaiResp.Msg + if resultMsg == "" { + resultMsg = shumaiResp.Message + } + if resultMsg == "" { + resultMsg = "成功" + } + + // 构建目标格式的响应 response := map[string]interface{}{ - "msg": "成功", - "success": true, - "code": 200, - "data": map[string]interface{}{ - "result": shumaiData.Result, - "order_no": shumaiData.OrderNo, - "desc": shumaiData.Desc, - "sex": shumaiData.Sex, - "birthday": shumaiData.Birthday, - "address": shumaiData.Address, + "ctidRequest": map[string]interface{}{ + "ctidAuth": map[string]interface{}{ + "idCard": paramsDto.IDCard, + "name": paramsDto.Name, + "resultCode": resultCode, + "resultMsg": resultMsg, + "verifyResult": shumaiResp.Data.Desc, + }, }, }