add ivyz9k2l

This commit is contained in:
2025-11-20 20:16:18 +08:00
parent a53727757c
commit 7fc072e608
4 changed files with 309 additions and 12 deletions

View File

@@ -302,7 +302,7 @@ type IVYZ3A7FReq struct {
type IVYZ9K2LReq struct {
Name string `json:"name" validate:"required,min=1,validName"`
IDCard string `json:"id_card" validate:"required,validIDCard"`
PhotoData string `json:"photo_data" validate:"omitempty,validBase64Image"`
PhotoData string `json:"photo_data" validate:"required,validBase64Image"`
}
type IVYZ9D2EReq struct {

View File

@@ -295,6 +295,8 @@ func (s *FormConfigServiceImpl) parseValidationRules(validateTag string) string
frontendRules = append(frontendRules, "返回链接格式")
case rule == "validAuthorizationURL":
frontendRules = append(frontendRules, "授权链接格式")
case rule == "validBase64Image":
frontendRules = append(frontendRules, "Base64图片格式JPG、BMP、PNG")
case strings.HasPrefix(rule, "oneof="):
values := strings.TrimPrefix(rule, "oneof=")
frontendRules = append(frontendRules, "可选值: "+values)
@@ -324,6 +326,8 @@ func (s *FormConfigServiceImpl) getFieldType(fieldType reflect.Type, validation
return "url"
} else if strings.Contains(validation, "可选值") {
return "select"
} else if strings.Contains(validation, "Base64图片") || strings.Contains(validation, "base64") {
return "textarea"
}
return "text"
case reflect.Int64:
@@ -515,7 +519,7 @@ func (s *FormConfigServiceImpl) generateDescription(jsonTag string, validation s
"plate_type": "号牌类型01-小型汽车02-大型汽车(可选)",
"vin_code": "请输入17位车辆识别代号VIN码Vehicle Identification Number",
"return_type": "返回类型1-专业和学校名称数据返回编码形式默认2-专业和学校名称数据返回中文名称",
"photo_data": "人脸图片(base64编码的图片数据仅支持JPG、BMP、PNG三种格式",
"photo_data": "人脸图片(base64编码的图片数据仅支持JPG、BMP、PNG三种格式",
}
if desc, exists := descMap[jsonTag]; exists {

View File

@@ -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
}