This commit is contained in:
Mrx
2026-05-11 13:36:49 +08:00
parent 38410a7378
commit 8c301de7d2
2 changed files with 23 additions and 17 deletions

View File

@@ -249,7 +249,8 @@ type IVYZZQT3Req struct {
type IVYZZQ3BReq struct { type IVYZZQ3BReq struct {
Name string `json:"name" validate:"required,min=1,validName"` Name string `json:"name" validate:"required,min=1,validName"`
IDCard string `json:"id_card" validate:"required,validIDCard"` 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"` Authorized string `json:"authorized" validate:"required,oneof=0 1"`
} }

View File

@@ -35,10 +35,15 @@ func ProcessIVYZZQ3BRequest(ctx context.Context, params []byte, deps *processors
reqData := map[string]interface{}{ reqData := map[string]interface{}{
"idCard": encryptedIDCard, "idCard": encryptedIDCard,
"name": encryptedName, "name": encryptedName,
"imageId": paramsDto.ImageUrl,
"authorized": paramsDto.Authorized, "authorized": paramsDto.Authorized,
} }
if paramsDto.ImageUrl != "" {
reqData["url"] = paramsDto.ImageUrl
} else {
reqData["image"] = paramsDto.PhotoData
}
respData, err := deps.ZhichaService.CallAPI(ctx, "ZCI1001", reqData) respData, err := deps.ZhichaService.CallAPI(ctx, "ZCI1001", reqData)
if err != nil { if err != nil {
if errors.Is(err, zhicha.ErrDatasource) { 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) return nil, errors.Join(processors.ErrSystem, err)
} }
outBytes, err := buildToStringmapZCI1001RespToIVYZZQ3B(respBytes) outBytes, err := mapZCI1001RespToIVYZZQ3B(respBytes)
if err != nil { if err != nil {
return nil, errors.Join(processors.ErrSystem, err) return nil, errors.Join(processors.ErrSystem, err)
} }
@@ -76,28 +81,28 @@ type IVYZZQ3BOutResultData struct {
Similarity string `json:"similarity"` Similarity string `json:"similarity"`
} }
// zci062UpstreamResp 智查 ZCI062 成功返回体中的字段 // zci1001UpstreamResp 智查 ZCI1001 成功返回体中的字段
type zci062UpstreamResp struct { type zci1001UpstreamResp struct {
Score interface{} `json:"score"` Score interface{} `json:"score"`
Msg string `json:"msg"` Msg string `json:"msg"`
Incorrect interface{} `json:"incorrect"` Incorrect interface{} `json:"incorrect"`
} }
func buildToStringmapZCI1001RespToIVYZZQ3B(respBytes []byte) ([]byte, error) { func mapZCI1001RespToIVYZZQ3B(respBytes []byte) ([]byte, error) {
var r zci062UpstreamResp var r zci1001UpstreamResp
if err := json.Unmarshal(respBytes, &r); err != nil { if err := json.Unmarshal(respBytes, &r); err != nil {
return nil, err return nil, err
} }
score := buildScoreToFloat64(r.Score) score := parseScoreZCI1001ToFloat64(r.Score)
similarityVal := buildlarity(score) similarityVal := mapScoreToZCI001Similarity(score)
similarity := strconv.FormatFloat(similarityVal, 'f', 2, 64) similarity := strconv.FormatFloat(similarityVal, 'f', 2, 64)
verificationResult := buildverifres(score) verificationResult := buildToStringmapZCI1001RespToIVYZZQ3B(score)
out := IVYZZQ3BOut{ out := IVYZZQ3BOut{
HandleTime: time.Now().Format("2006-01-02 15:04:05"), HandleTime: time.Now().Format("2006-01-02 15:04:05"),
ResultData: IVYZZQ3BOutResultData{ ResultData: IVYZZQ3BOutResultData{
VerificationCode: buildToString(r.Incorrect), VerificationCode: valueZCI001ToString(r.Incorrect),
VerificationResult: verificationResult, VerificationResult: verificationResult,
VerificationMessage: r.Msg, VerificationMessage: r.Msg,
Similarity: similarity, Similarity: similarity,
@@ -107,17 +112,17 @@ func buildToStringmapZCI1001RespToIVYZZQ3B(respBytes []byte) ([]byte, error) {
return json.Marshal(out) return json.Marshal(out)
} }
// buildverifres 审核判定逻辑score >= 0.45 为 valid否则为 invalid // buildToStringmapZCI1001RespToIVYZZQ3B 审核判定逻辑score >= 0.45 为 valid否则为 invalid
func buildverifres(score float64) string { func buildToStringmapZCI1001RespToIVYZZQ3B(score float64) string {
if score >= 0.45 { if score >= 0.45 {
return "valid" return "valid"
} }
return "invalid" return "invalid"
} }
// buildlarity 将 score(0~1) 分段映射到 similarity(0~1000) // mapScoreToZCI001Similarity 将 score(0~1) 分段映射到 similarity(0~1000)
// 0.40 -> 6000.45 -> 700 // 0.40 -> 6000.45 -> 700
func buildlarity(score float64) float64 { func mapScoreToZCI001Similarity(score float64) float64 {
if score <= 0 { if score <= 0 {
return 0 return 0
} }
@@ -136,7 +141,7 @@ func buildlarity(score float64) float64 {
return 700 + ((score-0.45)/0.55)*300 return 700 + ((score-0.45)/0.55)*300
} }
func buildScoreToFloat64(v interface{}) float64 { func parseScoreZCI1001ToFloat64(v interface{}) float64 {
switch t := v.(type) { switch t := v.(type) {
case float64: case float64:
return t return t
@@ -160,7 +165,7 @@ func buildScoreToFloat64(v interface{}) float64 {
return 0 return 0
} }
func buildToString(v interface{}) string { func valueZCI001ToString(v interface{}) string {
if v == nil { if v == nil {
return "" return ""
} }