f
This commit is contained in:
@@ -7,10 +7,10 @@ import (
|
|||||||
|
|
||||||
"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/haiyuapi"
|
"tyapi-server/internal/infrastructure/external/shumai"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProcessIVYZP2Q6Request IVYZP2Q6 API处理方法 - 身份认证二要素(电签版,海宇API)
|
// ProcessIVYZP2Q6Request IVYZP2Q6 API处理方法 - 身份认证二要素
|
||||||
func ProcessIVYZP2Q6Request(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
func ProcessIVYZP2Q6Request(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||||
var paramsDto dto.IVYZP2Q6Req
|
var paramsDto dto.IVYZP2Q6Req
|
||||||
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
||||||
@@ -21,26 +21,64 @@ func ProcessIVYZP2Q6Request(ctx context.Context, params []byte, deps *processors
|
|||||||
return nil, errors.Join(processors.ErrInvalidParam, err)
|
return nil, errors.Join(processors.ErrInvalidParam, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if deps.HaiyuapiService == nil {
|
reqFormData := map[string]interface{}{
|
||||||
return nil, errors.Join(processors.ErrSystem, errors.New("海宇API服务未初始化"))
|
"idcard": paramsDto.IDCard,
|
||||||
|
"name": paramsDto.Name,
|
||||||
}
|
}
|
||||||
|
|
||||||
reqParams := map[string]interface{}{
|
// 以表单方式调用数脉 API;参数在 CallAPIForm 内转为 application/x-www-form-urlencoded
|
||||||
"name": paramsDto.Name,
|
apiPath := "/v4/id_card/check" // 接口路径,根据数脉文档填写(如 v4/xxx)
|
||||||
"id_card": paramsDto.IDCard,
|
|
||||||
}
|
|
||||||
|
|
||||||
apiPath := "/api/v1/IVYZP2Q6"
|
// 先尝试使用政务接口(app_id2 和 app_secret2)
|
||||||
respBytes, err := deps.HaiyuapiService.CallAPI(ctx, apiPath, reqParams)
|
respBytes, err := deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, haiyuapi.ErrNotFound) {
|
// 使用实时接口(app_id 和 app_secret)重试
|
||||||
return nil, errors.Join(processors.ErrNotFound, err)
|
respBytes, err = deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData, false)
|
||||||
}
|
// 如果重试后仍然失败,返回错误
|
||||||
if errors.Is(err, haiyuapi.ErrDatasource) {
|
if err != nil {
|
||||||
return nil, errors.Join(processors.ErrDatasource, err)
|
if errors.Is(err, shumai.ErrNotFound) {
|
||||||
|
// 查无记录情况
|
||||||
|
return nil, errors.Join(processors.ErrNotFound, err)
|
||||||
|
} 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)
|
||||||
|
} else {
|
||||||
|
// 其他未知错误
|
||||||
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数据源返回 result(0-一致/1-不一致/2-无记录),映射为 state(1-匹配/2-不匹配/3-异常情况)
|
||||||
|
var dsResp struct {
|
||||||
|
Result int `json:"result"` // 0-一致 1-不一致 2-无记录(预留)
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(respBytes, &dsResp); err != nil {
|
||||||
return nil, errors.Join(processors.ErrSystem, err)
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return respBytes, nil
|
state := resultToState(dsResp.Result)
|
||||||
|
|
||||||
|
out := map[string]interface{}{
|
||||||
|
"errMsg": "",
|
||||||
|
"state": state,
|
||||||
|
}
|
||||||
|
return json.Marshal(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// resultToState 将数据源 result 映射为接口 state:1-匹配 2-不匹配 3-异常情况
|
||||||
|
func resultToState(result int) int {
|
||||||
|
switch result {
|
||||||
|
case 0: // 一致 → 匹配
|
||||||
|
return 1
|
||||||
|
case 1: // 不一致 → 不匹配
|
||||||
|
return 2
|
||||||
|
case 2: // 无记录(预留) → 异常情况
|
||||||
|
return 3
|
||||||
|
default:
|
||||||
|
return 3 // 未知/异常 → 异常情况
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user