f
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
"tyapi-server/internal/infrastructure/external/shumai"
|
||||
)
|
||||
|
||||
// ProcessIVYZ9K7FRequest IVYZ9K7F 身份证实名认证 API处理方法
|
||||
// ProcessIVYZ9K7FRequest IVYZ9K7F 身份证实名认证即时版 API处理方法
|
||||
func ProcessIVYZ9K7FRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||
var paramsDto dto.IVYZ9K7FReq
|
||||
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
||||
|
||||
@@ -4,12 +4,39 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"tyapi-server/internal/domains/api/dto"
|
||||
"tyapi-server/internal/domains/api/services/processors"
|
||||
"tyapi-server/internal/infrastructure/external/xingwei"
|
||||
"tyapi-server/internal/infrastructure/external/shumai"
|
||||
)
|
||||
|
||||
// shumaiMobileThreeResp 数脉 /v4/mobile_three/check 返回的 data 结构
|
||||
// result: 0-一致收费 1-不一致收费 2-无记录不收费
|
||||
type shumaiMobileThreeResp struct {
|
||||
OrderNo string `json:"order_no"`
|
||||
Result string `json:"result"`
|
||||
Desc string `json:"desc"`
|
||||
Channel string `json:"channel"`
|
||||
Sex string `json:"sex"`
|
||||
Birthday string `json:"birthday"`
|
||||
Address string `json:"address"`
|
||||
}
|
||||
|
||||
// yysy9a1bOut 最终返回格式
|
||||
// result: 01一致 02不一致 03不确定 04失败/虚拟号;type: 1移动 2联通 3电信 4广电
|
||||
type yysy9a1bOut struct {
|
||||
OrderNo string `json:"orderNo"`
|
||||
HandleTime string `json:"handleTime"`
|
||||
Type string `json:"type"` // 1:移动 2:联通 3:电信 4:广电
|
||||
Result string `json:"result"`
|
||||
Gender string `json:"gender"`
|
||||
Age string `json:"age"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
|
||||
// ProcessYYSY9A1BRequest YYSY9A1B API处理方法 - 运营商三要素查询
|
||||
func ProcessYYSY9A1BRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||
var paramsDto dto.YYSY9A1BReq
|
||||
@@ -20,28 +47,101 @@ func ProcessYYSY9A1BRequest(ctx context.Context, params []byte, deps *processors
|
||||
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
|
||||
return nil, errors.Join(processors.ErrInvalidParam, err)
|
||||
}
|
||||
|
||||
// 构建请求数据,将项目规范的字段名转换为 XingweiService 需要的字段名
|
||||
reqData := map[string]interface{}{
|
||||
"name": paramsDto.Name,
|
||||
"idCardNum": paramsDto.IDCard,
|
||||
"phoneNumber": paramsDto.MobileNo,
|
||||
reqFormData := map[string]interface{}{
|
||||
"idcard": paramsDto.IDCard,
|
||||
"name": paramsDto.Name,
|
||||
"mobile": paramsDto.MobileNo,
|
||||
}
|
||||
|
||||
// 调用行为数据API,使用指定的project_id
|
||||
projectID := "CDJ-1100244697766359040"
|
||||
respBytes, err := deps.XingweiService.CallAPI(ctx, projectID, reqData)
|
||||
// 以表单方式调用数脉 API;参数在 CallAPIForm 内转为 application/x-www-form-urlencoded
|
||||
deps.ShumaiService.UseGovernment()
|
||||
apiPath := "/v4/mobile_three/check"
|
||||
respBytes, err := deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData)
|
||||
if err != nil {
|
||||
if errors.Is(err, xingwei.ErrNotFound) {
|
||||
return nil, errors.Join(processors.ErrNotFound, err)
|
||||
} else if errors.Is(err, xingwei.ErrDatasource) {
|
||||
if errors.Is(err, shumai.ErrDatasource) {
|
||||
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)
|
||||
} else {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
}
|
||||
|
||||
return respBytes, nil
|
||||
// 将数脉 data 映射为最终返回格式
|
||||
out, err := mapShumaiMobileThreeToYYSY9A1B(respBytes)
|
||||
if err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
return json.Marshal(out)
|
||||
}
|
||||
|
||||
// mapShumaiMobileThreeToYYSY9A1B 数脉 mobile_three/check 的 data -> 最终格式
|
||||
// result: 0->01 1->02 2->04 其它->04;gender: 男->1 女->2;type: cmcc->1 cucc->2 ctcc->3 gdcc->4
|
||||
func mapShumaiMobileThreeToYYSY9A1B(dataBytes []byte) (*yysy9a1bOut, error) {
|
||||
var r shumaiMobileThreeResp
|
||||
if err := json.Unmarshal(dataBytes, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// result: 01一致 02不一致 03不确定 04失败/虚拟号;原 2-无记录 及 其它 均映射为 04
|
||||
var res string
|
||||
switch strings.TrimSpace(r.Result) {
|
||||
case "0":
|
||||
res = "01"
|
||||
case "1":
|
||||
res = "02"
|
||||
case "2":
|
||||
res = "04"
|
||||
default:
|
||||
res = "04"
|
||||
}
|
||||
|
||||
// type: 运营商 channel -> 1移动 2联通 3电信 4广电(cmcc/cucc/ctcc/gdcc),未知为空
|
||||
ch := strings.ToLower(strings.TrimSpace(r.Channel))
|
||||
var chType string
|
||||
switch ch {
|
||||
case "cmcc":
|
||||
chType = "1"
|
||||
case "cucc":
|
||||
chType = "2"
|
||||
case "ctcc":
|
||||
chType = "3"
|
||||
case "gdcc":
|
||||
chType = "4"
|
||||
}
|
||||
|
||||
// gender: 男->1 女->2
|
||||
sex := strings.TrimSpace(r.Sex)
|
||||
var gender string
|
||||
if sex == "男" {
|
||||
gender = "1"
|
||||
} else if sex == "女" {
|
||||
gender = "2"
|
||||
}
|
||||
|
||||
return &yysy9a1bOut{
|
||||
OrderNo: r.OrderNo,
|
||||
HandleTime: time.Now().Format("2006-01-02 15:04:05"),
|
||||
Type: chType,
|
||||
Result: res,
|
||||
Gender: gender,
|
||||
Age: ageFromBirthday(r.Birthday),
|
||||
Remark: r.Desc,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ageFromBirthday(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
if len(s) < 4 {
|
||||
return ""
|
||||
}
|
||||
y, err := strconv.Atoi(s[0:4])
|
||||
if err != nil || y <= 0 {
|
||||
return ""
|
||||
}
|
||||
age := time.Now().Year() - y
|
||||
if age < 0 {
|
||||
age = 0
|
||||
}
|
||||
return strconv.Itoa(age)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"tyapi-server/internal/infrastructure/external/shumai"
|
||||
)
|
||||
|
||||
// ProcessYYSYH6F3Request YYSYH6F3 运营商三要素政务版API处理方法
|
||||
// ProcessYYSYH6F3Request YYSYH6F3 运营商三要素即时版API处理方法
|
||||
func ProcessYYSYH6F3Request(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||
var paramsDto dto.YYSYH6F3Req
|
||||
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user