diff --git a/internal/domains/api/dto/api_request_dto.go b/internal/domains/api/dto/api_request_dto.go index 2a4a040..041f2f5 100644 --- a/internal/domains/api/dto/api_request_dto.go +++ b/internal/domains/api/dto/api_request_dto.go @@ -249,7 +249,8 @@ type IVYZZQT3Req struct { type IVYZZQ3BReq struct { Name string `json:"name" validate:"required,min=1,validName"` IDCard string `json:"id_card" validate:"required,validIDCard"` - ImageUrl string `json:"image_url" validate:"required,url"` + PhotoData string `json:"photo_data" validate:"omitempty,validBase64Image"` + ImageUrl string `json:"image_url" validate:"omitempty,url"` Authorized string `json:"authorized" validate:"required,oneof=0 1"` } diff --git a/internal/domains/api/services/processors/ivyz/ivyzzq3B_processor.go b/internal/domains/api/services/processors/ivyz/ivyzzq3B_processor.go index bcf90f9..6a63e45 100644 --- a/internal/domains/api/services/processors/ivyz/ivyzzq3B_processor.go +++ b/internal/domains/api/services/processors/ivyz/ivyzzq3B_processor.go @@ -35,10 +35,15 @@ func ProcessIVYZZQ3BRequest(ctx context.Context, params []byte, deps *processors reqData := map[string]interface{}{ "idCard": encryptedIDCard, "name": encryptedName, - "imageId": paramsDto.ImageUrl, "authorized": paramsDto.Authorized, } + if paramsDto.ImageUrl != "" { + reqData["url"] = paramsDto.ImageUrl + } else { + reqData["image"] = paramsDto.PhotoData + } + respData, err := deps.ZhichaService.CallAPI(ctx, "ZCI1001", reqData) if err != nil { if errors.Is(err, zhicha.ErrDatasource) { @@ -53,7 +58,7 @@ func ProcessIVYZZQ3BRequest(ctx context.Context, params []byte, deps *processors return nil, errors.Join(processors.ErrSystem, err) } - outBytes, err := buildToStringmapZCI1001RespToIVYZZQ3B(respBytes) + outBytes, err := mapZCI1001RespToIVYZZQ3B(respBytes) if err != nil { return nil, errors.Join(processors.ErrSystem, err) } @@ -76,28 +81,28 @@ type IVYZZQ3BOutResultData struct { Similarity string `json:"similarity"` } -// zci062UpstreamResp 智查 ZCI062 成功返回体中的字段 -type zci062UpstreamResp struct { +// zci1001UpstreamResp 智查 ZCI1001 成功返回体中的字段 +type zci1001UpstreamResp struct { Score interface{} `json:"score"` Msg string `json:"msg"` Incorrect interface{} `json:"incorrect"` } -func buildToStringmapZCI1001RespToIVYZZQ3B(respBytes []byte) ([]byte, error) { - var r zci062UpstreamResp +func mapZCI1001RespToIVYZZQ3B(respBytes []byte) ([]byte, error) { + var r zci1001UpstreamResp if err := json.Unmarshal(respBytes, &r); err != nil { return nil, err } - score := buildScoreToFloat64(r.Score) - similarityVal := buildlarity(score) + score := parseScoreZCI1001ToFloat64(r.Score) + similarityVal := mapScoreToZCI001Similarity(score) similarity := strconv.FormatFloat(similarityVal, 'f', 2, 64) - verificationResult := buildverifres(score) + verificationResult := buildToStringmapZCI1001RespToIVYZZQ3B(score) out := IVYZZQ3BOut{ HandleTime: time.Now().Format("2006-01-02 15:04:05"), ResultData: IVYZZQ3BOutResultData{ - VerificationCode: buildToString(r.Incorrect), + VerificationCode: valueZCI001ToString(r.Incorrect), VerificationResult: verificationResult, VerificationMessage: r.Msg, Similarity: similarity, @@ -107,17 +112,17 @@ func buildToStringmapZCI1001RespToIVYZZQ3B(respBytes []byte) ([]byte, error) { return json.Marshal(out) } -// buildverifres 审核判定逻辑:score >= 0.45 为 valid,否则为 invalid -func buildverifres(score float64) string { +// buildToStringmapZCI1001RespToIVYZZQ3B 审核判定逻辑:score >= 0.45 为 valid,否则为 invalid +func buildToStringmapZCI1001RespToIVYZZQ3B(score float64) string { if score >= 0.45 { return "valid" } return "invalid" } -// buildlarity 将 score(0~1) 分段映射到 similarity(0~1000): +// mapScoreToZCI001Similarity 将 score(0~1) 分段映射到 similarity(0~1000): // 0.40 -> 600,0.45 -> 700 -func buildlarity(score float64) float64 { +func mapScoreToZCI001Similarity(score float64) float64 { if score <= 0 { return 0 } @@ -136,7 +141,7 @@ func buildlarity(score float64) float64 { return 700 + ((score-0.45)/0.55)*300 } -func buildScoreToFloat64(v interface{}) float64 { +func parseScoreZCI1001ToFloat64(v interface{}) float64 { switch t := v.(type) { case float64: return t @@ -160,7 +165,7 @@ func buildScoreToFloat64(v interface{}) float64 { return 0 } -func buildToString(v interface{}) string { +func valueZCI001ToString(v interface{}) string { if v == nil { return "" }