f
This commit is contained in:
@@ -577,8 +577,9 @@ type FLXGHB4FReq struct {
|
||||
}
|
||||
|
||||
type IVYZP2Q6Req struct {
|
||||
Name string `json:"name" validate:"required,min=1,validName"`
|
||||
IDCard string `json:"id_card" validate:"required,validIDCard"`
|
||||
Name string `json:"name" validate:"required,min=1,validName"`
|
||||
IDCard string `json:"id_card" validate:"required,validIDCard"`
|
||||
PdfBase64 string `json:"pdf_base64" validate:"required,validBase64PDF"`
|
||||
}
|
||||
|
||||
type JRZQ1W4XReq struct {
|
||||
@@ -615,7 +616,8 @@ type QYGL5A3CReq struct {
|
||||
}
|
||||
|
||||
type QYGLBH7YReq struct {
|
||||
EntName string `json:"ent_name" validate:"required,min=1,validEnterpriseName"`
|
||||
EntName string `json:"ent_name" validate:"required,min=1,validEnterpriseName"`
|
||||
PdfBase64 string `json:"pdf_base64" validate:"required,validBase64PDF"`
|
||||
}
|
||||
|
||||
type QYGL2naoReq struct {
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
|
||||
"tyapi-server/internal/domains/api/dto"
|
||||
"tyapi-server/internal/domains/api/services/processors"
|
||||
"tyapi-server/internal/infrastructure/external/shumai"
|
||||
"tyapi-server/internal/infrastructure/external/haiyuapi"
|
||||
)
|
||||
|
||||
// ProcessIVYZP2Q6Request IVYZP2Q6 API处理方法 - 身份认证二要素
|
||||
// ProcessIVYZP2Q6Request IVYZP2Q6 API处理方法 - 身份认证二要素(电签版,海宇API)
|
||||
func ProcessIVYZP2Q6Request(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||
var paramsDto dto.IVYZP2Q6Req
|
||||
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
||||
@@ -21,64 +21,27 @@ func ProcessIVYZP2Q6Request(ctx context.Context, params []byte, deps *processors
|
||||
return nil, errors.Join(processors.ErrInvalidParam, err)
|
||||
}
|
||||
|
||||
reqFormData := map[string]interface{}{
|
||||
"idcard": paramsDto.IDCard,
|
||||
"name": paramsDto.Name,
|
||||
if deps.HaiyuapiService == nil {
|
||||
return nil, errors.Join(processors.ErrSystem, errors.New("海宇API服务未初始化"))
|
||||
}
|
||||
|
||||
// 以表单方式调用数脉 API;参数在 CallAPIForm 内转为 application/x-www-form-urlencoded
|
||||
apiPath := "/v4/id_card/check" // 接口路径,根据数脉文档填写(如 v4/xxx)
|
||||
reqParams := map[string]interface{}{
|
||||
"name": paramsDto.Name,
|
||||
"id_card": paramsDto.IDCard,
|
||||
"auth_pdf_base64": paramsDto.PdfBase64,
|
||||
}
|
||||
|
||||
// 先尝试使用政务接口(app_id2 和 app_secret2)
|
||||
respBytes, err := deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData, true)
|
||||
apiPath := "/api/v1/IVYZP2Q6"
|
||||
respBytes, err := deps.HaiyuapiService.CallAPI(ctx, apiPath, reqParams)
|
||||
if err != nil {
|
||||
// 使用实时接口(app_id 和 app_secret)重试
|
||||
respBytes, err = deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData, false)
|
||||
// 如果重试后仍然失败,返回错误
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
if errors.Is(err, haiyuapi.ErrNotFound) {
|
||||
return nil, errors.Join(processors.ErrNotFound, err)
|
||||
}
|
||||
if errors.Is(err, haiyuapi.ErrDatasource) {
|
||||
return nil, errors.Join(processors.ErrDatasource, 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)
|
||||
}
|
||||
|
||||
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 // 未知/异常 → 异常情况
|
||||
}
|
||||
return respBytes, nil
|
||||
}
|
||||
|
||||
@@ -17,12 +17,17 @@ func ProcessQYGLBH7YRequest(ctx context.Context, params []byte, deps *processors
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
|
||||
return nil, errors.Join(processors.ErrInvalidParam, err)
|
||||
}
|
||||
|
||||
if deps.HaiyuapiService == nil {
|
||||
return nil, errors.Join(processors.ErrSystem, errors.New("海宇API服务未初始化"))
|
||||
}
|
||||
|
||||
reqParams := map[string]interface{}{
|
||||
"ent_name": paramsDto.EntName,
|
||||
"ent_name": paramsDto.EntName,
|
||||
"auth_pdf_base64": paramsDto.PdfBase64,
|
||||
}
|
||||
|
||||
apiPath := "/api/v1/QYGLBH7Y"
|
||||
|
||||
Reference in New Issue
Block a user