f
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -65,15 +66,21 @@ type IVYZZQ3BOut struct {
|
||||
}
|
||||
|
||||
type IVYZZQ3BOutResultData struct {
|
||||
// VerificationResult 审核校验结果:valid 身份审核通过;invalid 身份审核不通过(与 similarity 区间联动,见 mapVerificationResultFromSimilarity)
|
||||
// VerificationCode 审核校验编码,透传上游 incorrect
|
||||
VerificationCode string `json:"verification_code"`
|
||||
// VerificationResult 审核校验结果:valid 身份审核通过;invalid 身份审核不通过(score >= 0.45 为 valid)
|
||||
VerificationResult string `json:"verification_result"`
|
||||
// Similarity 照片相似度分数字符串(0–1000)。区间说明:(0,600)不同人;(600,700)不能确定是否同人;(700,1000)同人。数值为上游 score(0~1)×1000。
|
||||
// VerificationMessage 审核校验信息,透传上游 msg
|
||||
VerificationMessage string `json:"verification_message"`
|
||||
// Similarity 照片相似度分数字符串(0–1000)。区间说明:(0,600)不同人;(600,700)不能确定是否同人;(700,1000)同人。
|
||||
Similarity string `json:"similarity"`
|
||||
}
|
||||
|
||||
// zci062UpstreamResp 智查 ZCI062 成功返回体中的分数字段(分值越大相似度越高)
|
||||
// zci062UpstreamResp 智查 ZCI062 成功返回体中的字段
|
||||
type zci062UpstreamResp struct {
|
||||
Score interface{} `json:"score"`
|
||||
Msg string `json:"msg"`
|
||||
Incorrect interface{} `json:"incorrect"`
|
||||
}
|
||||
|
||||
func mapZCI062RespToIVYZZQ3B(respBytes []byte) ([]byte, error) {
|
||||
@@ -82,15 +89,17 @@ func mapZCI062RespToIVYZZQ3B(respBytes []byte) ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
score := parseScoreToFloat64(r.Score)
|
||||
similarityVal := score * 1000
|
||||
score := buildScoreToFloat64(r.Score)
|
||||
similarityVal := buildlarity(score)
|
||||
similarity := strconv.FormatFloat(similarityVal, 'f', 2, 64)
|
||||
verificationResult := mapVerificationResultFromSimilarity(similarityVal)
|
||||
verificationResult := buildverifres(score)
|
||||
|
||||
out := IVYZZQ3BOut{
|
||||
HandleTime: time.Now().Format("2006-01-02 15:04:05"),
|
||||
ResultData: IVYZZQ3BOutResultData{
|
||||
VerificationCode: buildToString(r.Incorrect),
|
||||
VerificationResult: verificationResult,
|
||||
VerificationMessage: r.Msg,
|
||||
Similarity: similarity,
|
||||
},
|
||||
}
|
||||
@@ -98,11 +107,77 @@ func mapZCI062RespToIVYZZQ3B(respBytes []byte) ([]byte, error) {
|
||||
return json.Marshal(out)
|
||||
}
|
||||
|
||||
// mapVerificationResultFromSimilarity 与 similarity(0–1000)区间说明对齐:
|
||||
// (700,1000】系统判断为同一人 → 身份审核通过 valid;其余 → invalid。
|
||||
func mapVerificationResultFromSimilarity(similarity float64) string {
|
||||
if similarity >= 700 {
|
||||
// buildverifres 审核判定逻辑:score >= 0.45 为 valid,否则为 invalid
|
||||
func buildverifres(score float64) string {
|
||||
if score >= 0.45 {
|
||||
return "valid"
|
||||
}
|
||||
return "invalid"
|
||||
}
|
||||
|
||||
// buildlarity 将 score(0~1) 分段映射到 similarity(0~1000):
|
||||
// 0.40 -> 600,0.45 -> 700
|
||||
func buildlarity(score float64) float64 {
|
||||
if score <= 0 {
|
||||
return 0
|
||||
}
|
||||
if score >= 1 {
|
||||
return 1000
|
||||
}
|
||||
if score < 0.40 {
|
||||
// [0, 0.40) -> [0, 600)
|
||||
return (score / 0.40) * 600
|
||||
}
|
||||
if score < 0.45 {
|
||||
// [0.40, 0.45) -> [600, 700)
|
||||
return 600 + ((score-0.40)/0.05)*100
|
||||
}
|
||||
// [0.45, 1] -> [700, 1000]
|
||||
return 700 + ((score-0.45)/0.55)*300
|
||||
}
|
||||
|
||||
func buildScoreToFloat64(v interface{}) float64 {
|
||||
switch t := v.(type) {
|
||||
case float64:
|
||||
return t
|
||||
case float32:
|
||||
return float64(t)
|
||||
case int:
|
||||
return float64(t)
|
||||
case int32:
|
||||
return float64(t)
|
||||
case int64:
|
||||
return float64(t)
|
||||
case json.Number:
|
||||
if f, err := t.Float64(); err == nil {
|
||||
return f
|
||||
}
|
||||
case string:
|
||||
if f, err := strconv.ParseFloat(t, 64); err == nil {
|
||||
return f
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func buildToString(v interface{}) string {
|
||||
if v == nil {
|
||||
return ""
|
||||
}
|
||||
switch t := v.(type) {
|
||||
case string:
|
||||
return t
|
||||
case int:
|
||||
return strconv.Itoa(t)
|
||||
case int32:
|
||||
return strconv.FormatInt(int64(t), 10)
|
||||
case int64:
|
||||
return strconv.FormatInt(t, 10)
|
||||
case float64:
|
||||
return strconv.FormatFloat(t, 'f', -1, 64)
|
||||
case float32:
|
||||
return strconv.FormatFloat(float64(t), 'f', -1, 64)
|
||||
default:
|
||||
return fmt.Sprintf("%v", v)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user