This commit is contained in:
2026-05-28 12:23:04 +08:00
parent ff66c341f5
commit 8a9b87be0e

View File

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