替换shumai
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/zhicha"
|
"tyapi-server/internal/infrastructure/external/shumai"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProcessIVYZ2A8BRequest IVYZ2A8B API处理方法 - 身份二要素认证
|
// ProcessIVYZ2A8BRequest IVYZ2A8B API处理方法 - 身份二要素认证政务版 数脉内部替换
|
||||||
func ProcessIVYZ2A8BRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
func ProcessIVYZ2A8BRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||||
var paramsDto dto.IVYZ2A8BReq
|
var paramsDto dto.IVYZ2A8BReq
|
||||||
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
||||||
@@ -20,37 +20,31 @@ func ProcessIVYZ2A8BRequest(ctx context.Context, params []byte, deps *processors
|
|||||||
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
|
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
|
||||||
return nil, errors.Join(processors.ErrInvalidParam, err)
|
return nil, errors.Join(processors.ErrInvalidParam, err)
|
||||||
}
|
}
|
||||||
|
reqFormData := map[string]interface{}{
|
||||||
encryptedName, err := deps.ZhichaService.Encrypt(paramsDto.Name)
|
"idcard": paramsDto.IDCard,
|
||||||
if err != nil {
|
"name": paramsDto.Name,
|
||||||
return nil, errors.Join(processors.ErrSystem, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
encryptedIDCard, err := deps.ZhichaService.Encrypt(paramsDto.IDCard)
|
//走政务接口 - 使用 app_id2 和 app_secret2
|
||||||
|
deps.ShumaiService.UseGovernment()
|
||||||
|
// 以表单方式调用数脉 API;参数在 CallAPIForm 内转为 application/x-www-form-urlencoded
|
||||||
|
apiPath := "/v4/id_card/check" // 接口路径,根据数脉文档填写(如 v4/xxx)
|
||||||
|
respBytes, err := deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Join(processors.ErrSystem, err)
|
if errors.Is(err, shumai.ErrNotFound) {
|
||||||
}
|
// 查无记录情况
|
||||||
|
return nil, errors.Join(processors.ErrNotFound, err)
|
||||||
reqData := map[string]interface{}{
|
} else if errors.Is(err, shumai.ErrDatasource) {
|
||||||
"name": encryptedName,
|
// 数据源错误
|
||||||
"idCard": encryptedIDCard,
|
|
||||||
"authorized": paramsDto.Authorized,
|
|
||||||
}
|
|
||||||
|
|
||||||
respData, err := deps.ZhichaService.CallAPI(ctx, "ZCI001", reqData)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, zhicha.ErrDatasource) {
|
|
||||||
return nil, errors.Join(processors.ErrDatasource, err)
|
return nil, errors.Join(processors.ErrDatasource, err)
|
||||||
|
} else if errors.Is(err, shumai.ErrSystem) {
|
||||||
|
// 系统错误
|
||||||
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
} else {
|
} else {
|
||||||
|
// 其他未知错误
|
||||||
return nil, errors.Join(processors.ErrSystem, err)
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将响应数据转换为JSON字节
|
|
||||||
respBytes, err := json.Marshal(respData)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Join(processors.ErrSystem, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return respBytes, nil
|
return respBytes, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user