f
This commit is contained in:
@@ -4,12 +4,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
|
||||||
"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/alicloud"
|
"tyapi-server/internal/infrastructure/external/shumai"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProcessIVYZN2P8Request IVYZN2P8 身份证实名认证政务版 API处理方法
|
// ProcessIVYZN2P8Request IVYZN2P8 身份证实名认证政务版 API处理方法
|
||||||
@@ -27,75 +25,97 @@ func ProcessIVYZN2P8Request(ctx context.Context, params []byte, deps *processors
|
|||||||
"name": paramsDto.Name,
|
"name": paramsDto.Name,
|
||||||
"idcard": paramsDto.IDCard,
|
"idcard": paramsDto.IDCard,
|
||||||
}
|
}
|
||||||
respBytes, err := deps.AlicloudService.CallAPI("api-mall/api/id_card/check", reqData)
|
|
||||||
|
// 以表单方式调用数脉 API;参数在 CallAPIForm 内转为 application/x-www-form-urlencoded
|
||||||
|
apiPath := "/v4/id_card/check"
|
||||||
|
|
||||||
|
// 先尝试使用政务接口(app_id2 和 app_secret2)
|
||||||
|
respBytes, err := deps.ShumaiService.CallAPIForm(ctx, apiPath, reqData, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, alicloud.ErrDatasource) {
|
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)
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 对齐 yysybe08test 的原始响应结构,取 data 字段映射为 ivyzn2p8 返回
|
|
||||||
var aliyunData struct {
|
|
||||||
Code int `json:"code"`
|
|
||||||
Data struct {
|
|
||||||
Birthday string `json:"birthday"`
|
|
||||||
Result interface{} `json:"result"`
|
|
||||||
Address string `json:"address"`
|
|
||||||
OrderNo string `json:"orderNo"`
|
|
||||||
Sex string `json:"sex"`
|
|
||||||
Desc string `json:"desc"`
|
|
||||||
} `json:"data"`
|
|
||||||
Result interface{} `json:"result"`
|
|
||||||
Desc string `json:"desc"`
|
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(respBytes, &aliyunData); err != nil {
|
return respBytes, nil
|
||||||
return nil, errors.Join(processors.ErrSystem, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
rawResult := aliyunData.Result
|
|
||||||
rawDesc := aliyunData.Desc
|
|
||||||
if aliyunData.Code == 200 {
|
|
||||||
rawResult = aliyunData.Data.Result
|
|
||||||
rawDesc = aliyunData.Data.Desc
|
|
||||||
}
|
|
||||||
|
|
||||||
response := map[string]interface{}{
|
|
||||||
"result": normalizeResult(rawResult),
|
|
||||||
"order_no": aliyunData.Data.OrderNo,
|
|
||||||
"desc": rawDesc,
|
|
||||||
"sex": aliyunData.Data.Sex,
|
|
||||||
"birthday": aliyunData.Data.Birthday,
|
|
||||||
"address": aliyunData.Data.Address,
|
|
||||||
}
|
|
||||||
return json.Marshal(response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func normalizeResult(v interface{}) int {
|
// respBytes, err := deps.AlicloudService.CallAPI("api-mall/api/id_card/check", reqData)
|
||||||
switch r := v.(type) {
|
// if err != nil {
|
||||||
case float64:
|
// if errors.Is(err, alicloud.ErrDatasource) {
|
||||||
return int(r)
|
// return nil, errors.Join(processors.ErrDatasource, err)
|
||||||
case int:
|
// }
|
||||||
return r
|
// return nil, errors.Join(processors.ErrSystem, err)
|
||||||
case int32:
|
// }
|
||||||
return int(r)
|
|
||||||
case int64:
|
// return respBytes, nil
|
||||||
return int(r)
|
// // 对齐 yysybe08test 的原始响应结构,取 data 字段映射为 ivyzn2p8 返回
|
||||||
case json.Number:
|
// var aliyunData struct {
|
||||||
n, err := r.Int64()
|
// Code int `json:"code"`
|
||||||
if err == nil {
|
// Data struct {
|
||||||
return int(n)
|
// Birthday string `json:"birthday"`
|
||||||
}
|
// Result interface{} `json:"result"`
|
||||||
case string:
|
// Address string `json:"address"`
|
||||||
s := strings.TrimSpace(r)
|
// OrderNo string `json:"orderNo"`
|
||||||
if s == "" {
|
// Sex string `json:"sex"`
|
||||||
return 1
|
// Desc string `json:"desc"`
|
||||||
}
|
// } `json:"data"`
|
||||||
n, err := strconv.Atoi(s)
|
// Result interface{} `json:"result"`
|
||||||
if err == nil {
|
// Desc string `json:"desc"`
|
||||||
return n
|
// }
|
||||||
}
|
// if err := json.Unmarshal(respBytes, &aliyunData); err != nil {
|
||||||
}
|
// return nil, errors.Join(processors.ErrSystem, err)
|
||||||
// 默认按不一致处理
|
// }
|
||||||
return 1
|
|
||||||
}
|
// rawResult := aliyunData.Result
|
||||||
|
// rawDesc := aliyunData.Desc
|
||||||
|
// if aliyunData.Code == 200 {
|
||||||
|
// rawResult = aliyunData.Data.Result
|
||||||
|
// rawDesc = aliyunData.Data.Desc
|
||||||
|
// }
|
||||||
|
|
||||||
|
// response := map[string]interface{}{
|
||||||
|
// "result": normalizeResult(rawResult),
|
||||||
|
// "order_no": aliyunData.Data.OrderNo,
|
||||||
|
// "desc": rawDesc,
|
||||||
|
// "sex": aliyunData.Data.Sex,
|
||||||
|
// "birthday": aliyunData.Data.Birthday,
|
||||||
|
// "address": aliyunData.Data.Address,
|
||||||
|
// }
|
||||||
|
// return json.Marshal(response)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func normalizeResult(v interface{}) int {
|
||||||
|
// switch r := v.(type) {
|
||||||
|
// case float64:
|
||||||
|
// return int(r)
|
||||||
|
// case int:
|
||||||
|
// return r
|
||||||
|
// case int32:
|
||||||
|
// return int(r)
|
||||||
|
// case int64:
|
||||||
|
// return int(r)
|
||||||
|
// case json.Number:
|
||||||
|
// n, err := r.Int64()
|
||||||
|
// if err == nil {
|
||||||
|
// return int(n)
|
||||||
|
// }
|
||||||
|
// case string:
|
||||||
|
// s := strings.TrimSpace(r)
|
||||||
|
// if s == "" {
|
||||||
|
// return 1
|
||||||
|
// }
|
||||||
|
// n, err := strconv.Atoi(s)
|
||||||
|
// if err == nil {
|
||||||
|
// return n
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// // 默认按不一致处理
|
||||||
|
// return 1
|
||||||
|
// }
|
||||||
|
|||||||
Reference in New Issue
Block a user