This commit is contained in:
Mrx
2026-05-29 12:28:09 +08:00

View File

@@ -5,10 +5,11 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"
"tyapi-server/internal/domains/api/dto"
"tyapi-server/internal/domains/api/services/processors"
"tyapi-server/internal/infrastructure/external/xingwei"
"tyapi-server/internal/infrastructure/external/shumai"
"github.com/tidwall/gjson"
)
@@ -92,37 +93,42 @@ func verifyEnterpriseInfo(ctx context.Context, paramsDto dto.QYGL5CMPReq, deps *
}, nil
}
// verifyPersonalInfo 验证个人信息并返回API数据
// verifyPersonalInfo 验证个人信息(姓名+身份证+手机号三要素)
func verifyPersonalInfo(ctx context.Context, paramsDto dto.QYGL5CMPReq, deps *processors.ProcessorDependencies) (map[string]interface{}, error) {
// 构建请求数据,将项目规范的字段名转换为 XingweiService 需要的字段名
reqData := map[string]interface{}{
"name": paramsDto.LegalPerson,
"idCardNum": paramsDto.IDCard,
"phoneNumber": paramsDto.MobileNo,
reqFormData := map[string]interface{}{
"idcard": paramsDto.IDCard,
"name": paramsDto.LegalPerson,
"mobile": paramsDto.MobileNo,
}
// 调用行为数据API使用指定的project_id
projectID := "CDJ-1100244702166183936"
respBytes, err := deps.XingweiService.CallAPI(ctx, projectID, reqData)
apiPath := "/v4/mobile_three/check"
// 先尝试政务接口,失败再切换实时接口
respBytes, err := deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData, true)
if err != nil {
// 个人信息验证失败,返回错误状态
if errors.Is(err, xingwei.ErrNotFound) {
return nil, errors.Join(processors.ErrNotFound, err)
} else if errors.Is(err, xingwei.ErrDatasource) {
return nil, errors.Join(processors.ErrDatasource, err)
} else if errors.Is(err, xingwei.ErrSystem) {
return nil, errors.Join(processors.ErrSystem, err)
} else {
respBytes, err = deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData, false)
if err != nil {
if errors.Is(err, shumai.ErrNotFound) {
return nil, fmt.Errorf("个人信息验证不通过")
} else if errors.Is(err, shumai.ErrDatasource) {
return nil, errors.Join(processors.ErrDatasource, err)
} else if errors.Is(err, shumai.ErrSystem) {
return nil, errors.Join(processors.ErrSystem, err)
}
return nil, errors.Join(processors.ErrSystem, err)
}
}
// 解析星维API返回的数据
var xingweiData map[string]interface{}
if err := json.Unmarshal(respBytes, &xingweiData); err != nil {
return nil, errors.Join(processors.ErrSystem, fmt.Errorf("解析星维API响应失败: %w", err))
// result: 0-一致 1-不一致 2-无记录
var resp struct {
Result string `json:"result"`
}
if err := json.Unmarshal(respBytes, &resp); err != nil {
return nil, errors.Join(processors.ErrSystem, fmt.Errorf("解析数脉API响应失败: %w", err))
}
if strings.TrimSpace(resp.Result) != "0" {
return nil, fmt.Errorf("个人信息验证不通过")
}
// 返回星维API的全部数据
return xingweiData, nil
return nil, nil
}