add ivyz9k2l
This commit is contained in:
@@ -10,6 +10,8 @@ import (
|
||||
"tyapi-server/internal/domains/api/dto"
|
||||
"tyapi-server/internal/domains/api/services/processors"
|
||||
"tyapi-server/internal/infrastructure/external/westdex"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
// ProcessIVYZ9K2LRequest IVYZ9K2L API处理方法 - 身份认证三要素(人脸图像版)
|
||||
@@ -44,15 +46,13 @@ func ProcessIVYZ9K2LRequest(ctx context.Context, params []byte, deps *processors
|
||||
|
||||
// 构建请求数据
|
||||
reqData := map[string]interface{}{
|
||||
"timeStamp": timestamp,
|
||||
"customNumber": customNumber,
|
||||
"xM": encryptedName,
|
||||
"gMSFZHM": encryptedIDCard,
|
||||
}
|
||||
|
||||
// 如果提供了人脸图片,添加到请求数据中
|
||||
if paramsDto.PhotoData != "" {
|
||||
reqData["photoData"] = paramsDto.PhotoData
|
||||
"data": map[string]interface{}{
|
||||
"timeStamp": timestamp,
|
||||
"customNumber": customNumber,
|
||||
"xM": encryptedName,
|
||||
"gMSFZHM": encryptedIDCard,
|
||||
"photoData": paramsDto.PhotoData,
|
||||
},
|
||||
}
|
||||
|
||||
respBytes, err := deps.WestDexService.CallAPI(ctx, "idCardThreeElements", reqData)
|
||||
@@ -67,5 +67,37 @@ func ProcessIVYZ9K2LRequest(ctx context.Context, params []byte, deps *processors
|
||||
}
|
||||
}
|
||||
|
||||
return respBytes, nil
|
||||
// 使用gjson提取authResult字段
|
||||
// 尝试多个可能的路径
|
||||
var authResult string
|
||||
paths := []string{
|
||||
"WEST00037.WEST00038.authResult",
|
||||
"WEST00036.WEST00037.WEST00038.authResult",
|
||||
"authResult",
|
||||
}
|
||||
|
||||
for _, path := range paths {
|
||||
result := gjson.GetBytes(respBytes, path)
|
||||
if result.Exists() {
|
||||
authResult = result.String()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// 如果找不到authResult,返回ErrDatasource
|
||||
if authResult == "" {
|
||||
return nil, errors.Join(processors.ErrDatasource, errors.New("响应中未找到authResult字段"))
|
||||
}
|
||||
|
||||
// 构建返回格式 {result: XXXX}
|
||||
response := map[string]interface{}{
|
||||
"result": authResult,
|
||||
}
|
||||
|
||||
responseBytes, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
return responseBytes, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user