企业五要素
This commit is contained in:
@@ -133,6 +133,13 @@ type QYGL23T7Req struct {
|
|||||||
IDCard string `json:"id_card" validate:"required,validIDCard"`
|
IDCard string `json:"id_card" validate:"required,validIDCard"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type QYGL5CMPReq struct {
|
||||||
|
EntName string `json:"ent_name" validate:"required,min=1,validEnterpriseName"`
|
||||||
|
EntCode string `json:"ent_code" validate:"required,validUSCI"`
|
||||||
|
LegalPerson string `json:"legal_person" validate:"required,min=1,validName"`
|
||||||
|
IDCard string `json:"id_card" validate:"required,validIDCard"`
|
||||||
|
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
||||||
|
}
|
||||||
type YYSY4B37Req struct {
|
type YYSY4B37Req struct {
|
||||||
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ func registerAllProcessors(combService *comb.CombService) {
|
|||||||
"QYGL9T1Q": qygl.ProcessQYGL9T1QRequest, //全国企业借贷意向验证查询_V1
|
"QYGL9T1Q": qygl.ProcessQYGL9T1QRequest, //全国企业借贷意向验证查询_V1
|
||||||
"QYGL5A9T": qygl.ProcessQYGL5A9TRequest, //全国企业各类工商风险统计数量查询
|
"QYGL5A9T": qygl.ProcessQYGL5A9TRequest, //全国企业各类工商风险统计数量查询
|
||||||
"QYGL2S0W": qygl.ProcessQYGL2S0WRequest, //失信被执行企业个人查询
|
"QYGL2S0W": qygl.ProcessQYGL2S0WRequest, //失信被执行企业个人查询
|
||||||
|
"QYGL5CMP": qygl.ProcessQYGL5CMPRequest, //企业五要素验证
|
||||||
|
|
||||||
// YYSY系列处理器
|
// YYSY系列处理器
|
||||||
"YYSYD50F": yysy.ProcessYYSYD50FRequest,
|
"YYSYD50F": yysy.ProcessYYSYD50FRequest,
|
||||||
|
|||||||
@@ -198,6 +198,7 @@ func (s *FormConfigServiceImpl) getDTOStruct(ctx context.Context, apiCode string
|
|||||||
"IVYZ2B2T": &dto.IVYZ2B2TReq{}, //能力资质核验(学历)
|
"IVYZ2B2T": &dto.IVYZ2B2TReq{}, //能力资质核验(学历)
|
||||||
"IVYZ5A9O": &dto.IVYZ5A9tReq{}, //全国⾃然⼈⻛险评估评分模型
|
"IVYZ5A9O": &dto.IVYZ5A9tReq{}, //全国⾃然⼈⻛险评估评分模型
|
||||||
"IVYZ6M8P": &dto.IVYZ6M8PReq{}, //职业资格证书
|
"IVYZ6M8P": &dto.IVYZ6M8PReq{}, //职业资格证书
|
||||||
|
"QYGL5CMP": &dto.QYGL5CMPReq{}, //企业五要素验证
|
||||||
}
|
}
|
||||||
|
|
||||||
// 优先返回已配置的DTO
|
// 优先返回已配置的DTO
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
package qygl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"tyapi-server/internal/domains/api/dto"
|
||||||
|
"tyapi-server/internal/domains/api/services/processors"
|
||||||
|
"tyapi-server/internal/infrastructure/external/xingwei"
|
||||||
|
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProcessQYGL5CMPRequest QYGL5CMP API处理方法 - 企业五要素验证
|
||||||
|
func ProcessQYGL5CMPRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||||
|
var paramsDto dto.QYGL5CMPReq
|
||||||
|
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
||||||
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
|
||||||
|
return nil, errors.Join(processors.ErrInvalidParam, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建API调用参数
|
||||||
|
apiParams := map[string]string{
|
||||||
|
"code": paramsDto.EntCode,
|
||||||
|
"name": paramsDto.EntName,
|
||||||
|
"legalPersonName": paramsDto.LegalPerson,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用天眼查API - 使用通用的CallAPI方法
|
||||||
|
response, err := deps.TianYanChaService.CallAPI(ctx, "VerifyThreeElements", apiParams)
|
||||||
|
if err != nil {
|
||||||
|
return nil, convertTianYanChaError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查天眼查API调用是否成功
|
||||||
|
if !response.Success {
|
||||||
|
// 天眼查API调用失败,返回企业信息校验不通过
|
||||||
|
return createStatusResponsess(1), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析天眼查响应数据
|
||||||
|
if response.Data == nil {
|
||||||
|
// 天眼查响应数据为空,返回企业信息校验不通过
|
||||||
|
return createStatusResponsess(1), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将response.Data转换为JSON字符串,然后使用gjson解析
|
||||||
|
dataBytes, err := json.Marshal(response.Data)
|
||||||
|
if err != nil {
|
||||||
|
// 数据序列化失败,返回企业信息校验不通过
|
||||||
|
return createStatusResponsess(1), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用gjson解析嵌套的data.result.data字段
|
||||||
|
result := gjson.GetBytes(dataBytes, "result")
|
||||||
|
if !result.Exists() {
|
||||||
|
// 字段不存在,返回企业信息校验不通过
|
||||||
|
return createStatusResponsess(1), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查data.result.data是否等于1
|
||||||
|
if result.Int() != 1 {
|
||||||
|
// 不等于1,返回企业信息校验不通过
|
||||||
|
return createStatusResponsess(1), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 天眼查三要素验证通过,继续调用星维身份证三要素验证
|
||||||
|
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
||||||
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
|
||||||
|
return nil, errors.Join(processors.ErrInvalidParam, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建请求数据,将项目规范的字段名转换为 XingweiService 需要的字段名
|
||||||
|
reqData := map[string]interface{}{
|
||||||
|
"name": paramsDto.LegalPerson,
|
||||||
|
"idCardNum": paramsDto.IDCard,
|
||||||
|
"phoneNumber": paramsDto.MobileNo,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用行为数据API,使用指定的project_id
|
||||||
|
projectID := "CDJ-1100244702166183936"
|
||||||
|
respBytes, err := deps.XingweiService.CallAPI(ctx, projectID, reqData)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, xingwei.ErrNotFound) {
|
||||||
|
return nil, errors.Join(processors.ErrNotFound, err)
|
||||||
|
} else if errors.Is(err, xingwei.ErrDatasource) {
|
||||||
|
return nil, errors.Join(processors.ErrDatasource, err)
|
||||||
|
} else if errors.Is(err, xingwei.ErrSystem) {
|
||||||
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
|
} else {
|
||||||
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析星维API返回的数据
|
||||||
|
var xingweiData map[string]interface{}
|
||||||
|
if err := json.Unmarshal(respBytes, &xingweiData); err != nil {
|
||||||
|
return nil, errors.Join(processors.ErrSystem, fmt.Errorf("解析星维API响应失败: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建天眼查API返回的数据结构
|
||||||
|
tianYanChaData := map[string]interface{}{
|
||||||
|
"success": response.Success,
|
||||||
|
"message": response.Message,
|
||||||
|
"data": response.Data,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 合并两个API的返回数据
|
||||||
|
mergedData := map[string]interface{}{
|
||||||
|
"Personal Information": xingweiData, // 星维API返回的数据
|
||||||
|
"Enterprise Information": tianYanChaData, // 天眼查API返回的数据
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将合并后的数据序列化为JSON
|
||||||
|
mergedBytes, err := json.Marshal(mergedData)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Join(processors.ErrSystem, fmt.Errorf("合并数据序列化失败: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return mergedBytes, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// createStatusResponsess 创建状态响应
|
||||||
|
func createStatusResponsess(status int) []byte {
|
||||||
|
response := map[string]interface{}{
|
||||||
|
"status": status,
|
||||||
|
"message": "企业信息不通过",
|
||||||
|
}
|
||||||
|
respBytes, _ := json.Marshal(response)
|
||||||
|
return respBytes
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user