2024-12-24 11:37:25 +08:00
|
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
2024-12-28 02:21:47 +08:00
|
|
|
|
"io"
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
2025-04-23 17:48:38 +08:00
|
|
|
|
"sort"
|
2024-12-28 02:21:47 +08:00
|
|
|
|
"strings"
|
2024-12-24 11:37:25 +08:00
|
|
|
|
"sync"
|
|
|
|
|
"sync/atomic"
|
|
|
|
|
"time"
|
2025-04-09 15:58:06 +08:00
|
|
|
|
"tyc-server/app/user/cmd/api/internal/config"
|
|
|
|
|
"tyc-server/app/user/model"
|
|
|
|
|
"tyc-server/pkg/lzkit/crypto"
|
|
|
|
|
"tyc-server/pkg/lzkit/lzUtils"
|
2025-03-20 02:03:28 +08:00
|
|
|
|
|
|
|
|
|
"github.com/Masterminds/squirrel"
|
|
|
|
|
"github.com/bytedance/sonic"
|
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
2024-12-24 11:37:25 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ApiRequestService struct {
|
|
|
|
|
config config.Config
|
|
|
|
|
westDexService *WestDexService
|
2024-12-28 02:21:47 +08:00
|
|
|
|
yushanService *YushanService
|
2025-03-20 20:32:57 +08:00
|
|
|
|
tianjuService *TianjuService
|
2024-12-24 11:37:25 +08:00
|
|
|
|
featureModel model.FeatureModel
|
|
|
|
|
productFeatureModel model.ProductFeatureModel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewApiRequestService 是一个构造函数,用于初始化 ApiRequestService
|
2025-03-20 20:32:57 +08:00
|
|
|
|
func NewApiRequestService(c config.Config, westDexService *WestDexService, yushanService *YushanService, tianjuService *TianjuService, featureModel model.FeatureModel, productFeatureModel model.ProductFeatureModel) *ApiRequestService {
|
2024-12-24 11:37:25 +08:00
|
|
|
|
return &ApiRequestService{
|
|
|
|
|
config: c,
|
|
|
|
|
featureModel: featureModel,
|
|
|
|
|
productFeatureModel: productFeatureModel,
|
|
|
|
|
westDexService: westDexService,
|
2024-12-28 02:21:47 +08:00
|
|
|
|
yushanService: yushanService,
|
2025-03-20 20:32:57 +08:00
|
|
|
|
tianjuService: tianjuService,
|
2024-12-24 11:37:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type APIResponseData struct {
|
|
|
|
|
ApiID string `json:"apiID"`
|
|
|
|
|
Data json.RawMessage `json:"data"` // 这里用 RawMessage 来存储原始的 data
|
2025-03-21 15:47:11 +08:00
|
|
|
|
TaskID string `json:"task_id,omitempty"`
|
|
|
|
|
IsAsync bool `json:"is_async,omitempty"`
|
2024-12-24 11:37:25 +08:00
|
|
|
|
Success bool `json:"success"`
|
|
|
|
|
Timestamp string `json:"timestamp"`
|
|
|
|
|
Error string `json:"error,omitempty"`
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
type APIInternalResult struct {
|
|
|
|
|
IsAsync bool `json:"is_async,omitempty"`
|
|
|
|
|
TaskID string `json:"task_id,omitempty"`
|
|
|
|
|
Data json.RawMessage `json:"data"`
|
|
|
|
|
}
|
2024-12-24 11:37:25 +08:00
|
|
|
|
|
|
|
|
|
// ProcessRequests 处理请求
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessRequests(ctx context.Context, params []byte, productID int64) ([]byte, error) {
|
2024-12-24 11:37:25 +08:00
|
|
|
|
build := a.productFeatureModel.SelectBuilder().Where(squirrel.Eq{
|
|
|
|
|
"product_id": productID,
|
|
|
|
|
})
|
|
|
|
|
productFeatureList, findProductFeatureErr := a.productFeatureModel.FindAll(ctx, build, "")
|
|
|
|
|
if findProductFeatureErr != nil {
|
|
|
|
|
return nil, findProductFeatureErr
|
|
|
|
|
}
|
|
|
|
|
var featureIDs []int64
|
2025-01-18 22:34:27 +08:00
|
|
|
|
isImportantMap := make(map[int64]int64, len(productFeatureList))
|
2024-12-24 11:37:25 +08:00
|
|
|
|
for _, pf := range productFeatureList {
|
|
|
|
|
featureIDs = append(featureIDs, pf.FeatureId)
|
2025-01-18 22:34:27 +08:00
|
|
|
|
isImportantMap[pf.FeatureId] = pf.IsImportant
|
2024-12-24 11:37:25 +08:00
|
|
|
|
}
|
|
|
|
|
if len(featureIDs) == 0 {
|
|
|
|
|
return nil, errors.New("featureIDs 是空的")
|
|
|
|
|
}
|
|
|
|
|
builder := a.featureModel.SelectBuilder().Where(squirrel.Eq{"id": featureIDs})
|
|
|
|
|
featureList, findFeatureErr := a.featureModel.FindAll(ctx, builder, "")
|
|
|
|
|
if findFeatureErr != nil {
|
|
|
|
|
return nil, findFeatureErr
|
|
|
|
|
}
|
|
|
|
|
if len(featureList) == 0 {
|
|
|
|
|
return nil, errors.New("处理请求错误,产品无对应接口功能")
|
|
|
|
|
}
|
|
|
|
|
var (
|
|
|
|
|
wg sync.WaitGroup
|
|
|
|
|
resultsCh = make(chan APIResponseData, len(featureList))
|
|
|
|
|
errorsCh = make(chan error, len(featureList))
|
|
|
|
|
errorCount int32
|
2025-01-18 22:34:27 +08:00
|
|
|
|
errorLimit = len(featureList)
|
|
|
|
|
retryNum = 5
|
2024-12-24 11:37:25 +08:00
|
|
|
|
)
|
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
childCtx, cancel := context.WithCancel(ctx)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
2024-12-24 11:37:25 +08:00
|
|
|
|
for i, feature := range featureList {
|
|
|
|
|
wg.Add(1)
|
|
|
|
|
go func(i int, feature *model.Feature) {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
|
|
|
|
|
select {
|
2025-03-21 15:47:11 +08:00
|
|
|
|
case <-childCtx.Done():
|
2024-12-24 11:37:25 +08:00
|
|
|
|
return
|
|
|
|
|
default:
|
|
|
|
|
}
|
|
|
|
|
result := APIResponseData{
|
|
|
|
|
ApiID: feature.ApiId,
|
|
|
|
|
Success: false,
|
|
|
|
|
}
|
|
|
|
|
timestamp := time.Now().Format("2006-01-02 15:04:05")
|
2025-01-18 22:34:27 +08:00
|
|
|
|
var (
|
2025-03-21 15:47:11 +08:00
|
|
|
|
resp *APIInternalResult
|
2025-01-18 22:34:27 +08:00
|
|
|
|
preprocessErr error
|
|
|
|
|
)
|
|
|
|
|
isImportant := isImportantMap[feature.Id] == 1
|
|
|
|
|
tryCount := 0
|
|
|
|
|
for {
|
|
|
|
|
tryCount++
|
2025-03-21 15:47:11 +08:00
|
|
|
|
resp, preprocessErr = a.PreprocessRequestApi(childCtx, params, feature.ApiId)
|
2025-01-18 22:34:27 +08:00
|
|
|
|
if preprocessErr == nil {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
if isImportant && tryCount < retryNum {
|
|
|
|
|
continue
|
|
|
|
|
} else {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-24 11:37:25 +08:00
|
|
|
|
if preprocessErr != nil {
|
|
|
|
|
result.Timestamp = timestamp
|
|
|
|
|
result.Error = preprocessErr.Error()
|
2025-03-21 15:47:11 +08:00
|
|
|
|
if resp != nil {
|
|
|
|
|
result.Data = resp.Data
|
|
|
|
|
if resp.IsAsync {
|
|
|
|
|
result.IsAsync = true
|
|
|
|
|
result.TaskID = resp.TaskID
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-24 11:37:25 +08:00
|
|
|
|
resultsCh <- result
|
2024-12-28 02:21:47 +08:00
|
|
|
|
errorsCh <- fmt.Errorf("请求失败: %v", preprocessErr)
|
2024-12-24 11:37:25 +08:00
|
|
|
|
atomic.AddInt32(&errorCount, 1)
|
|
|
|
|
if atomic.LoadInt32(&errorCount) >= int32(errorLimit) {
|
|
|
|
|
cancel()
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
result.Data = resp.Data
|
2024-12-24 11:37:25 +08:00
|
|
|
|
result.Success = true
|
|
|
|
|
result.Timestamp = timestamp
|
2025-03-21 15:47:11 +08:00
|
|
|
|
if resp.IsAsync {
|
|
|
|
|
result.IsAsync = true
|
|
|
|
|
result.TaskID = resp.TaskID
|
|
|
|
|
}
|
2024-12-24 11:37:25 +08:00
|
|
|
|
resultsCh <- result
|
|
|
|
|
}(i, feature)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
wg.Wait()
|
|
|
|
|
close(resultsCh)
|
|
|
|
|
close(errorsCh)
|
|
|
|
|
}()
|
|
|
|
|
var responseData []APIResponseData
|
|
|
|
|
for result := range resultsCh {
|
|
|
|
|
responseData = append(responseData, result)
|
|
|
|
|
}
|
|
|
|
|
if atomic.LoadInt32(&errorCount) >= int32(errorLimit) {
|
|
|
|
|
var allErrors []error
|
|
|
|
|
for err := range errorsCh {
|
|
|
|
|
allErrors = append(allErrors, err)
|
|
|
|
|
}
|
|
|
|
|
return nil, fmt.Errorf("请求失败次数超过 %d 次: %v", errorLimit, allErrors)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
combinedResponse, err := json.Marshal(responseData)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("响应数据转 JSON 失败: %+v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return combinedResponse, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------------------------------------请求处理器--------------------------
|
2025-03-21 15:47:11 +08:00
|
|
|
|
var requestProcessors = map[string]func(*ApiRequestService, context.Context, []byte) (*APIInternalResult, error){
|
2025-03-20 20:32:57 +08:00
|
|
|
|
"G09SC02": (*ApiRequestService).ProcessG09SC02Request,
|
|
|
|
|
"G27BJ05": (*ApiRequestService).ProcessG27BJ05Request,
|
|
|
|
|
"G26BJ05": (*ApiRequestService).ProcessG26BJ05Request,
|
|
|
|
|
"G34BJ03": (*ApiRequestService).ProcessG34BJ03Request,
|
|
|
|
|
"G35SC01": (*ApiRequestService).ProcessG35SC01Request,
|
|
|
|
|
"G28BJ05": (*ApiRequestService).ProcessG28BJ05Request,
|
|
|
|
|
"G05HZ01": (*ApiRequestService).ProcessG05HZ01Request,
|
|
|
|
|
"Q23SC01": (*ApiRequestService).ProcessQ23SC01Request,
|
|
|
|
|
"G15BJ02": (*ApiRequestService).ProcessG15BJ02Request,
|
|
|
|
|
"G17BJ02": (*ApiRequestService).ProcessG17BJ02Request,
|
|
|
|
|
"G08SC02": (*ApiRequestService).ProcessG08SC02Request,
|
|
|
|
|
"KZEYS": (*ApiRequestService).ProcessKZEYSRequest,
|
|
|
|
|
"P_C_B332": (*ApiRequestService).ProcessP_C_B332Request,
|
|
|
|
|
"FIN019": (*ApiRequestService).ProcessFIN019Request,
|
|
|
|
|
"G10SC02": (*ApiRequestService).ProcessG10SC02Request,
|
|
|
|
|
"G03HZ01": (*ApiRequestService).ProcessG03HZ01Request,
|
|
|
|
|
"G02BJ02": (*ApiRequestService).ProcessG02BJ02Request,
|
|
|
|
|
"G19BJ02": (*ApiRequestService).ProcessG19BJ02Request,
|
|
|
|
|
"G20GZ01": (*ApiRequestService).ProcessG20GZ01Request,
|
|
|
|
|
"CAR061": (*ApiRequestService).ProcessCAR061Request, // 名下车辆
|
|
|
|
|
"CAR074": (*ApiRequestService).ProcessCAR074Request, // 车辆出险信息
|
|
|
|
|
"CAR058": (*ApiRequestService).ProcessCAR058Request, // 车辆维保记录
|
2025-03-21 15:47:11 +08:00
|
|
|
|
"CAR059": (*ApiRequestService).ProcessCAR059Request, // 车辆维保记录结果查询
|
2025-03-20 20:32:57 +08:00
|
|
|
|
"CAR079": (*ApiRequestService).ProcessCAR079Request, // 车架号查车
|
|
|
|
|
"CAR066": (*ApiRequestService).ProcessCAR066Request, // 车辆过户次数
|
|
|
|
|
"CAR100": (*ApiRequestService).ProcessCAR100Request, // 车辆估值
|
|
|
|
|
"G37SC01": (*ApiRequestService).ProcessG37SC01Request,
|
|
|
|
|
"G36SC01": (*ApiRequestService).ProcessG36SC01Request,
|
|
|
|
|
"G22SC01": (*ApiRequestService).ProcessG22SC01Request,
|
|
|
|
|
"Q03SC01": (*ApiRequestService).ProcessQ03SC01Request,
|
|
|
|
|
"COM187": (*ApiRequestService).ProcessCOM187Request,
|
|
|
|
|
"MOB035": (*ApiRequestService).ProcessMOB035Request,
|
|
|
|
|
"PCB915": (*ApiRequestService).ProcessPCB915Request,
|
|
|
|
|
"RIS031": (*ApiRequestService).ProcessRIS031Request,
|
|
|
|
|
"PCB601": (*ApiRequestService).ProcessPCB601Request,
|
|
|
|
|
"PCB148": (*ApiRequestService).ProcessPCB148Request,
|
|
|
|
|
"FIN011": (*ApiRequestService).ProcessFIN011Request,
|
|
|
|
|
"FIN020": (*ApiRequestService).ProcessFIN020Request,
|
|
|
|
|
"FIN018": (*ApiRequestService).ProcessFIN018Request,
|
|
|
|
|
"MOB032": (*ApiRequestService).ProcessMOB032Request,
|
|
|
|
|
"FIN032": (*ApiRequestService).ProcessFIN032Request,
|
|
|
|
|
"HRD004": (*ApiRequestService).ProcessHRD004Request,
|
|
|
|
|
"mobilelocal": (*ApiRequestService).ProcessMobilelocalRequest, // 手机归属地
|
|
|
|
|
"sfz": (*ApiRequestService).ProcessSfzRequest, // 身份证归属地
|
2025-04-02 19:06:13 +08:00
|
|
|
|
"IDV044": (*ApiRequestService).ProcessIDV044Request,
|
2025-04-23 17:48:38 +08:00
|
|
|
|
|
|
|
|
|
// New Feature
|
|
|
|
|
"PersonEnterprisePro": (*ApiRequestService).ProcessPersonEnterpriseProRequest,
|
|
|
|
|
"BehaviorRiskScan": (*ApiRequestService).ProcessBehaviorRiskScanRequest,
|
|
|
|
|
"G30BJ05": (*ApiRequestService).ProcessG30BJ05Request,
|
|
|
|
|
"G31BJ05": (*ApiRequestService).ProcessG31BJ05Request,
|
|
|
|
|
"G32BJ05": (*ApiRequestService).ProcessG32BJ05Request,
|
|
|
|
|
"G09XM02": (*ApiRequestService).ProcessG09XM02Request,
|
|
|
|
|
"G10XM02": (*ApiRequestService).ProcessG10XM02Request,
|
|
|
|
|
"G11BJ06": (*ApiRequestService).ProcessG11BJ06Request,
|
2024-12-24 11:37:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PreprocessRequestApi 调用指定的请求处理函数
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) PreprocessRequestApi(ctx context.Context, params []byte, apiID string) (*APIInternalResult, error) {
|
2024-12-24 11:37:25 +08:00
|
|
|
|
if processor, exists := requestProcessors[apiID]; exists {
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return processor(a, ctx, params) // 调用 ApiRequestService 方法
|
2024-12-24 11:37:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil, errors.New("api请求, 未找到相应的处理程序")
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG09SC02Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-24 11:37:25 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G09SC02, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"certNumMan": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
"nameMan": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G09SC02", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
result := gjson.GetBytes(resp, "data.0.maritalStatus")
|
|
|
|
|
|
|
|
|
|
if result.Exists() {
|
|
|
|
|
responseMap := map[string]string{"status": result.String()}
|
|
|
|
|
jsonResponse, err := json.Marshal(responseMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: jsonResponse,
|
|
|
|
|
}, nil
|
2024-12-24 11:37:25 +08:00
|
|
|
|
} else {
|
|
|
|
|
return nil, errors.New("查询为空")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG27BJ05Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-24 11:37:25 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() || !mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G27BJ05, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"id": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
"name": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
"cell": a.westDexService.Encrypt(mobile.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G27BJ05", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
// 获取 code 字段
|
|
|
|
|
codeResult := gjson.GetBytes(resp, "code")
|
|
|
|
|
if !codeResult.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("code 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
if codeResult.String() != "00" {
|
|
|
|
|
return nil, fmt.Errorf("未匹配到相关结果")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取 data 字段
|
|
|
|
|
dataResult := gjson.GetBytes(resp, "data")
|
|
|
|
|
if !dataResult.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("data 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将 data 字段解析为 map
|
|
|
|
|
var dataMap map[string]interface{}
|
|
|
|
|
if err := json.Unmarshal([]byte(dataResult.Raw), &dataMap); err != nil {
|
|
|
|
|
return nil, fmt.Errorf("解析 data 字段失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除指定字段
|
|
|
|
|
delete(dataMap, "swift_number")
|
|
|
|
|
delete(dataMap, "DataStrategy")
|
|
|
|
|
|
|
|
|
|
// 重新编码为 JSON
|
|
|
|
|
modifiedData, err := json.Marshal(dataMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("编码修改后的 data 失败: %v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: modifiedData,
|
|
|
|
|
}, nil
|
2024-12-24 11:37:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG26BJ05Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-24 11:37:25 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() || !mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G26BJ05, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"id": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
"name": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
"cell": a.westDexService.Encrypt(mobile.String()),
|
|
|
|
|
"time_range": 5,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G26BJ05", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
codeResult := gjson.GetBytes(resp, "code")
|
|
|
|
|
if !codeResult.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("code 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
if codeResult.String() != "00" {
|
|
|
|
|
return nil, fmt.Errorf("未匹配到相关结果")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取 data 字段
|
|
|
|
|
dataResult := gjson.GetBytes(resp, "data")
|
|
|
|
|
if !dataResult.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("data 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将 data 字段解析为 map
|
|
|
|
|
var dataMap map[string]interface{}
|
|
|
|
|
if err := json.Unmarshal([]byte(dataResult.Raw), &dataMap); err != nil {
|
|
|
|
|
return nil, fmt.Errorf("解析 data 字段失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除指定字段
|
|
|
|
|
delete(dataMap, "swift_number")
|
|
|
|
|
delete(dataMap, "DataStrategy")
|
|
|
|
|
|
|
|
|
|
// 重新编码为 JSON
|
|
|
|
|
modifiedData, err := json.Marshal(dataMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("编码修改后的 data 失败: %v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: modifiedData,
|
|
|
|
|
}, nil
|
2024-12-24 11:37:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG34BJ03Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-24 11:37:25 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G34BJ03, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"id_card": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
"name": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G34BJ03", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
dataResult := gjson.GetBytes(resp, "negative_info.data.risk_level")
|
|
|
|
|
if dataResult.Exists() {
|
|
|
|
|
// 如果字段存在,构造包含 "status" 的 JSON 响应
|
|
|
|
|
responseMap := map[string]string{"risk_level": dataResult.String()}
|
|
|
|
|
jsonResponse, err := json.Marshal(responseMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: jsonResponse,
|
|
|
|
|
}, nil
|
2024-12-24 11:37:25 +08:00
|
|
|
|
} else {
|
|
|
|
|
return nil, errors.New("查询为空")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG35SC01Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-24 11:37:25 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G35SC01, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"idcard": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
"name": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
"inquired_auth": a.westDexService.GetDateRange(),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G35SC01", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
// 第一步:提取外层的 data 字段
|
|
|
|
|
dataResult := gjson.GetBytes(resp, "data")
|
|
|
|
|
if !dataResult.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("外层 data 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 第二步:解析外层 data 的 JSON 字符串
|
|
|
|
|
var outerDataMap map[string]interface{}
|
|
|
|
|
if err := json.Unmarshal([]byte(dataResult.String()), &outerDataMap); err != nil {
|
|
|
|
|
return nil, fmt.Errorf("解析外层 data 字段失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 第三步:提取内层的 data 字段
|
|
|
|
|
innerData, ok := outerDataMap["data"].(string)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, fmt.Errorf("内层 data 字段不存在或类型错误")
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-30 19:09:10 +08:00
|
|
|
|
if innerData == "" || innerData == "{}" || innerData == "[]" {
|
|
|
|
|
innerData = "{}"
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-24 11:37:25 +08:00
|
|
|
|
// 第四步:解析内层 data 的 JSON 字符串
|
|
|
|
|
var finalDataMap map[string]interface{}
|
|
|
|
|
if err := json.Unmarshal([]byte(innerData), &finalDataMap); err != nil {
|
|
|
|
|
return nil, fmt.Errorf("解析内层 data 字段失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
finalDataBytes, err := json.Marshal(finalDataMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("编码最终的 JSON 对象失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: finalDataBytes,
|
|
|
|
|
}, nil
|
2024-12-24 11:37:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG28BJ05Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-24 11:37:25 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() || !mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G28BJ05, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"id": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
"name": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
"cell": a.westDexService.Encrypt(mobile.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G28BJ05", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
// 获取 code 字段
|
|
|
|
|
codeResult := gjson.GetBytes(resp, "code")
|
|
|
|
|
if !codeResult.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("code 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
if codeResult.String() != "00" {
|
|
|
|
|
return nil, fmt.Errorf("未匹配到相关结果")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取 data 字段
|
|
|
|
|
dataResult := gjson.GetBytes(resp, "data")
|
|
|
|
|
if !dataResult.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("data 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将 data 字段解析为 map
|
|
|
|
|
var dataMap map[string]interface{}
|
|
|
|
|
if err := json.Unmarshal([]byte(dataResult.Raw), &dataMap); err != nil {
|
|
|
|
|
return nil, fmt.Errorf("解析 data 字段失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除指定字段
|
|
|
|
|
delete(dataMap, "swift_number")
|
|
|
|
|
delete(dataMap, "DataStrategy")
|
|
|
|
|
|
|
|
|
|
// 重新编码为 JSON
|
|
|
|
|
modifiedData, err := json.Marshal(dataMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("编码修改后的 data 失败: %v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: modifiedData,
|
|
|
|
|
}, nil
|
2024-12-24 11:37:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG05HZ01Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-24 11:37:25 +08:00
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
|
|
|
|
|
if !idCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G05HZ01, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"pid": crypto.Md5Encrypt(idCard.String()),
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.G05HZ01CallAPI("G05HZ01", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
// 处理股东人企关系的响应数据
|
|
|
|
|
code := gjson.GetBytes(resp, "code")
|
|
|
|
|
if !code.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("响应中缺少 code 字段")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 判断 code 是否等于 "0000"
|
|
|
|
|
if code.String() == "0000" {
|
|
|
|
|
// 获取 data 字段的值
|
|
|
|
|
data := gjson.GetBytes(resp, "data")
|
|
|
|
|
if !data.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("响应中缺少 data 字段")
|
|
|
|
|
}
|
|
|
|
|
// 返回 data 字段的内容
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: []byte(data.Raw),
|
|
|
|
|
}, nil
|
2024-12-24 11:37:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// code 不等于 "0000",返回错误
|
|
|
|
|
return nil, fmt.Errorf("响应code错误%s", code.String())
|
|
|
|
|
}
|
2024-12-31 19:00:43 +08:00
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessQ23SC01Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-24 11:37:25 +08:00
|
|
|
|
entName := gjson.GetBytes(params, "ent_name")
|
|
|
|
|
entCode := gjson.GetBytes(params, "ent_code")
|
|
|
|
|
|
|
|
|
|
if !entName.Exists() || !entCode.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, Q23SC01, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"uscc": a.westDexService.Encrypt(entCode.String()),
|
|
|
|
|
"org_name": a.westDexService.Encrypt(entName.String()),
|
|
|
|
|
"inquired_auth": a.westDexService.GetDateRange(),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("Q23SC01", request)
|
|
|
|
|
logx.Infof("企业涉诉返回%+v", string(resp))
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
// 第一步:提取外层的 data 字段
|
|
|
|
|
dataResult := gjson.GetBytes(resp, "data")
|
|
|
|
|
if !dataResult.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("外层 data 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 第二步:解析外层 data 的 JSON 字符串
|
|
|
|
|
var outerDataMap map[string]interface{}
|
|
|
|
|
if err := json.Unmarshal([]byte(dataResult.String()), &outerDataMap); err != nil {
|
|
|
|
|
return nil, fmt.Errorf("解析外层 data 字段失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 第三步:提取内层的 data 字段
|
|
|
|
|
innerData, ok := outerDataMap["data"].(string)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, fmt.Errorf("内层 data 字段不存在或类型错误")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 第四步:解析内层 data 的 JSON 字符串
|
|
|
|
|
var finalDataMap map[string]interface{}
|
|
|
|
|
if err := json.Unmarshal([]byte(innerData), &finalDataMap); err != nil {
|
|
|
|
|
return nil, fmt.Errorf("解析内层 data 字段失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将最终的 JSON 对象编码为字节数组返回
|
|
|
|
|
finalDataBytes, err := json.Marshal(finalDataMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("编码最终的 JSON 对象失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
statusResult := gjson.GetBytes(finalDataBytes, "status.status")
|
|
|
|
|
if statusResult.Exists() || statusResult.Int() == -1 {
|
|
|
|
|
return nil, fmt.Errorf("企业涉诉为空: %+v", finalDataBytes)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: finalDataBytes,
|
|
|
|
|
}, nil
|
2024-12-24 11:37:25 +08:00
|
|
|
|
}
|
2024-12-31 19:00:43 +08:00
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG15BJ02Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-28 02:21:47 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() || !mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G15BJ02, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"name": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
"idNo": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
"phone": a.westDexService.Encrypt(mobile.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G15BJ02", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
dataResult := gjson.GetBytes(resp, "data.code")
|
|
|
|
|
if !dataResult.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("code 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
code := dataResult.Int()
|
|
|
|
|
// 处理允许的 code 值
|
|
|
|
|
if code == 1000 || code == 1003 || code == 1004 || code == 1005 {
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2024-12-28 02:21:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("三要素核验失败: %+v", resp)
|
|
|
|
|
}
|
2024-12-31 19:00:43 +08:00
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG17BJ02Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-28 02:21:47 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G17BJ02, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"name": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
"phone": a.westDexService.Encrypt(mobile.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G17BJ02", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
dataResult := gjson.GetBytes(resp, "data.code")
|
|
|
|
|
if !dataResult.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("code 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
code := dataResult.Int()
|
|
|
|
|
// 处理允许的 code 值
|
|
|
|
|
if code == 1000 || code == 1001 {
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2024-12-28 02:21:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("手机二要素核验失败: %+v", resp)
|
|
|
|
|
}
|
2024-12-31 19:00:43 +08:00
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG08SC02Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-28 02:21:47 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G08SC02, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"xm": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
"gmsfzhm": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G08SC02", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2024-12-28 02:21:47 +08:00
|
|
|
|
}
|
2024-12-31 19:00:43 +08:00
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessKZEYSRequest(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-28 02:21:47 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, KZEYS, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
appCode := a.config.Ali.Code
|
|
|
|
|
requestUrl := "https://kzidcardv1.market.alicloudapi.com/api-mall/api/id_card/check"
|
|
|
|
|
|
|
|
|
|
// 构造查询参数
|
|
|
|
|
data := url.Values{}
|
|
|
|
|
data.Add("name", name.String())
|
|
|
|
|
data.Add("idcard", idCard.String())
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequest(http.MethodPost, requestUrl, strings.NewReader(data.Encode()))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("KZEYS 创建请求失败: %+v", err)
|
|
|
|
|
}
|
|
|
|
|
req.Header.Set("Authorization", "APPCODE "+appCode)
|
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
|
|
|
|
|
client := &http.Client{}
|
|
|
|
|
resp, err := client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("KZEYS 请求失败: %+v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
|
return nil, fmt.Errorf("KZEYS 请求失败, 状态码: %d", resp.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
respBody, err := io.ReadAll(resp.Body)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("KZEYS 响应体读取失败:%v", err)
|
|
|
|
|
}
|
|
|
|
|
// 使用 gjson 解析 JSON 数据
|
|
|
|
|
code := gjson.GetBytes(respBody, "code").Int()
|
|
|
|
|
if code != 200 {
|
|
|
|
|
msg := gjson.GetBytes(respBody, "msg").String()
|
|
|
|
|
if msg == "" {
|
|
|
|
|
msg = "未知错误"
|
|
|
|
|
}
|
|
|
|
|
return nil, fmt.Errorf("KZEYS 响应失败: %s", msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
respData := gjson.GetBytes(respBody, "data")
|
|
|
|
|
if !respData.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("KZEYS 响应, data 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
dataRaw := respData.Raw
|
|
|
|
|
// 成功返回
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: []byte(dataRaw),
|
|
|
|
|
}, nil
|
2024-12-28 02:21:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 人车核验
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessP_C_B332Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-28 02:21:47 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
carType := gjson.GetBytes(params, "car_type")
|
|
|
|
|
carLicense := gjson.GetBytes(params, "car_license")
|
|
|
|
|
if !name.Exists() || !carType.Exists() || !carLicense.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, P_C_B332, 获取相关参数失败: car_number")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"name": name.String(),
|
|
|
|
|
"carType": carType.String(),
|
|
|
|
|
"carNumber": carLicense.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("P_C_B332", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("人车核验查询失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2024-12-28 02:21:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-18 22:34:27 +08:00
|
|
|
|
// 车辆出险信息
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessCAR074Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-01-18 22:34:27 +08:00
|
|
|
|
vinCode := gjson.GetBytes(params, "vin_code")
|
|
|
|
|
if !vinCode.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, CAR074, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"vin": vinCode.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("CAR074", request)
|
|
|
|
|
if err != nil {
|
2025-02-13 19:39:16 +08:00
|
|
|
|
return nil, fmt.Errorf("车辆出险信息查询失败: %+v", err)
|
2025-01-18 22:34:27 +08:00
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-01-18 22:34:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 车辆维保记录
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessCAR058Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-01-18 22:34:27 +08:00
|
|
|
|
vinCode := gjson.GetBytes(params, "vin_code")
|
|
|
|
|
carType := gjson.GetBytes(params, "car_driving_permit")
|
|
|
|
|
if !vinCode.Exists() || !carType.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, CAR058, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"vin": vinCode,
|
|
|
|
|
"image": carType,
|
|
|
|
|
"notifyUrl": "",
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("CAR058", request)
|
|
|
|
|
if err != nil {
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return nil, fmt.Errorf("车辆维保记录查询失败: %+v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
orderID := gjson.GetBytes(resp, "orderId").String()
|
|
|
|
|
if orderID == "" {
|
|
|
|
|
return nil, fmt.Errorf("获取订单ID失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果需要查询结果(queryID > 0),直接调用ProcessCAR059Request
|
|
|
|
|
// 构建查询参数
|
|
|
|
|
queryParams := map[string]interface{}{
|
|
|
|
|
"order_id": orderID,
|
|
|
|
|
}
|
|
|
|
|
queryBytes, _ := json.Marshal(queryParams)
|
|
|
|
|
|
|
|
|
|
// 直接调用ProcessCAR059Request进行查询,传递上级context
|
|
|
|
|
result, err := a.ProcessCAR059Request(ctx, queryBytes)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 返回CAR058响应与CAR059结果的组合
|
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: result.Data, // 原始CAR058响应
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 车辆维保记录结果查询
|
|
|
|
|
func (a *ApiRequestService) ProcessCAR059Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
|
|
|
|
orderID := gjson.GetBytes(params, "order_id")
|
|
|
|
|
if !orderID.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, CAR059, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
retryCount := 0
|
|
|
|
|
if gjson.GetBytes(params, "retry_count").Exists() {
|
|
|
|
|
retryCount = int(gjson.GetBytes(params, "retry_count").Int())
|
|
|
|
|
}
|
|
|
|
|
// 构建请求参数
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"orderId": orderID.String(),
|
|
|
|
|
}
|
|
|
|
|
// 调用API
|
|
|
|
|
resp, err := a.yushanService.request("CAR059", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if resp != nil {
|
|
|
|
|
// 使用gjson解析返回结果中的状态码
|
|
|
|
|
retcode := gjson.GetBytes(resp, "retcode").String()
|
|
|
|
|
logx.Infof("车辆维保记录查询任务,订单号: %s, 状态码: %s, 重试次数: %d",
|
|
|
|
|
orderID.String(), retcode, retryCount)
|
|
|
|
|
// 根据不同状态码进行不同处理
|
|
|
|
|
switch retcode {
|
|
|
|
|
case "warn_029": // 未查询到结果,请稍后重试
|
|
|
|
|
logx.Infof("车辆维保记录查询任务,订单号: %s, 未查询到结果,需要重试", orderID.String())
|
|
|
|
|
|
|
|
|
|
// 检查重试次数
|
2025-03-21 20:39:02 +08:00
|
|
|
|
maxRetries := 56
|
2025-03-21 15:47:11 +08:00
|
|
|
|
if retryCount >= maxRetries {
|
2025-03-21 16:12:47 +08:00
|
|
|
|
return nil, fmt.Errorf("车辆维保记录查询任务已达最大重试次数 %d,停止重试,订单号: %s",
|
2025-03-21 15:47:11 +08:00
|
|
|
|
maxRetries, orderID.String())
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-02 19:06:13 +08:00
|
|
|
|
// 固定延迟时间为30秒
|
2025-03-21 20:39:02 +08:00
|
|
|
|
fixedDelay := 30 * time.Second
|
2025-03-21 15:47:11 +08:00
|
|
|
|
|
|
|
|
|
// 检查ctx是否已经有超时
|
|
|
|
|
deadline, hasDeadline := ctx.Deadline()
|
|
|
|
|
if hasDeadline {
|
|
|
|
|
timeRemaining := time.Until(deadline)
|
2025-03-21 16:12:47 +08:00
|
|
|
|
|
|
|
|
|
// 检查上下文是否已经超时或即将超时
|
|
|
|
|
if timeRemaining <= 0 {
|
|
|
|
|
return nil, fmt.Errorf("上下文已超时,停止重试,订单号: %s", orderID.String())
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 16:18:58 +08:00
|
|
|
|
// 如果剩余时间不足以等待完整的15秒
|
|
|
|
|
if timeRemaining < fixedDelay+500*time.Millisecond {
|
|
|
|
|
logx.Infof("上下文剩余时间不足,提前返回,订单号: %s, 剩余时间: %v",
|
|
|
|
|
orderID.String(), timeRemaining)
|
|
|
|
|
return nil, fmt.Errorf("上下文剩余时间不足,无法完成下一次重试")
|
2025-03-21 15:47:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 16:18:58 +08:00
|
|
|
|
// 等待固定的延迟时间
|
2025-04-02 19:06:13 +08:00
|
|
|
|
logx.Infof("安排固定延迟重试,订单号: %s, 延迟: 30秒, 重试次数: %d",
|
2025-03-21 16:18:58 +08:00
|
|
|
|
orderID.String(), retryCount+1)
|
2025-03-21 15:47:11 +08:00
|
|
|
|
|
|
|
|
|
select {
|
2025-03-21 16:18:58 +08:00
|
|
|
|
case <-time.After(fixedDelay):
|
2025-03-21 15:47:11 +08:00
|
|
|
|
// 延迟时间到,继续处理
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
|
// 上下文被取消,返回错误
|
|
|
|
|
return nil, ctx.Err()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构建新的重试参数
|
|
|
|
|
retryParams := map[string]interface{}{
|
|
|
|
|
"order_id": orderID.String(),
|
|
|
|
|
"retry_count": retryCount + 1,
|
|
|
|
|
}
|
|
|
|
|
retryBytes, _ := json.Marshal(retryParams)
|
|
|
|
|
|
|
|
|
|
// 递归调用自身进行重试
|
|
|
|
|
return a.ProcessCAR059Request(ctx, retryBytes)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil, fmt.Errorf("车辆维保记录结果查询失败: %+v", err)
|
2025-01-18 22:34:27 +08:00
|
|
|
|
}
|
2025-03-21 20:39:02 +08:00
|
|
|
|
logx.Infof("车辆维保记录查询任务完成,订单号: %s",
|
|
|
|
|
orderID.String())
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-01-18 22:34:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 车架号查车
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessCAR079Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-01-18 22:34:27 +08:00
|
|
|
|
vinCode := gjson.GetBytes(params, "vin_code")
|
|
|
|
|
if !vinCode.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, CAR079, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"vin": vinCode.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("CAR079", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("车架号查车查询失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-01-18 22:34:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 车辆过户次数
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessCAR066Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-01-18 22:34:27 +08:00
|
|
|
|
vinCode := gjson.GetBytes(params, "vin_code")
|
|
|
|
|
if !vinCode.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, CAR066, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"vin": vinCode.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("CAR066", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("车辆过户次数查询失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-01-18 22:34:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 车辆估值
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessCAR100Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-01-18 22:34:27 +08:00
|
|
|
|
vinCode := gjson.GetBytes(params, "vin_code")
|
|
|
|
|
carLicense := gjson.GetBytes(params, "car_license")
|
|
|
|
|
if !vinCode.Exists() || !carLicense.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, CAR100, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"vin": vinCode.String(),
|
|
|
|
|
"carNumber": carLicense.String(),
|
|
|
|
|
"cardNo": "",
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("CAR100", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("车辆估值查询失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-01-18 22:34:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-28 02:21:47 +08:00
|
|
|
|
// 银行卡黑名单
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessFIN019Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-28 02:21:47 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
bankCard := gjson.GetBytes(params, "bank_card")
|
|
|
|
|
if !name.Exists() || !idCard.Exists() || !mobile.Exists() || !bankCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, FIN019, 获取相关参数失败: car_number")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"name": name.String(),
|
|
|
|
|
"cardNo": idCard.String(),
|
|
|
|
|
"mobile": mobile.String(),
|
|
|
|
|
"cardld": bankCard.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("FIN019", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("银行卡黑名单查询失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2024-12-28 02:21:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 名下车辆
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessCAR061Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-28 02:21:47 +08:00
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
|
|
|
|
|
if !idCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, CAR061, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"cardNo": idCard.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("CAR061", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("名下车辆查询失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2024-12-28 02:21:47 +08:00
|
|
|
|
}
|
2024-12-31 19:00:43 +08:00
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG10SC02Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-28 02:21:47 +08:00
|
|
|
|
// 提取男方和女方信息
|
|
|
|
|
nameMan := gjson.GetBytes(params, "nameMan")
|
|
|
|
|
idCardMan := gjson.GetBytes(params, "idCardMan")
|
|
|
|
|
nameWoman := gjson.GetBytes(params, "nameWoman")
|
|
|
|
|
idCardWoman := gjson.GetBytes(params, "idCardWoman")
|
|
|
|
|
|
|
|
|
|
// 校验是否存在必要参数
|
|
|
|
|
if !nameMan.Exists() || !idCardMan.Exists() || !nameWoman.Exists() || !idCardWoman.Exists() {
|
|
|
|
|
return nil, errors.New("请求参数缺失:需要提供男方和女方的姓名及身份证号")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构造请求数据
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"certNumMan": a.westDexService.Encrypt(idCardMan.String()),
|
|
|
|
|
"nameMan": a.westDexService.Encrypt(nameMan.String()),
|
|
|
|
|
"certNumWoman": a.westDexService.Encrypt(idCardWoman.String()),
|
|
|
|
|
"nameWoman": a.westDexService.Encrypt(nameWoman.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 调用 API
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G10SC02", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解析响应数据
|
|
|
|
|
code := gjson.GetBytes(resp, "code").String()
|
|
|
|
|
|
|
|
|
|
// 状态码校验
|
|
|
|
|
if code != "200" {
|
|
|
|
|
return nil, fmt.Errorf("婚姻查询失败:%s", string(resp))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result := gjson.GetBytes(resp, "data.0.maritalStatus")
|
|
|
|
|
|
|
|
|
|
if result.Exists() {
|
|
|
|
|
responseMap := map[string]string{"status": result.String()}
|
|
|
|
|
jsonResponse, err := json.Marshal(responseMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: jsonResponse,
|
|
|
|
|
}, nil
|
2024-12-28 02:21:47 +08:00
|
|
|
|
} else {
|
|
|
|
|
return nil, errors.New("查询为空")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 手机号码风险
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG03HZ01Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-28 02:21:47 +08:00
|
|
|
|
mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
|
|
|
|
|
if !mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G03HZ01, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"mobile": a.westDexService.Encrypt(mobile.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G03HZ01", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
// 获取 code 字段
|
|
|
|
|
codeResult := gjson.GetBytes(resp, "code")
|
|
|
|
|
if !codeResult.Exists() || codeResult.String() != "0000" {
|
|
|
|
|
return nil, fmt.Errorf("查询手机号码风险失败, %s", string(resp))
|
|
|
|
|
}
|
|
|
|
|
data := gjson.GetBytes(resp, "data.data")
|
|
|
|
|
if !data.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("查询手机号码风险失败, %s", string(resp))
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: []byte(data.Raw),
|
|
|
|
|
}, nil
|
2024-12-28 02:21:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 手机在网时长
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG02BJ02Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-28 02:21:47 +08:00
|
|
|
|
mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
|
|
|
|
|
if !mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G02BJ02, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"phone": a.westDexService.Encrypt(mobile.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G02BJ02", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
// 获取 code 字段
|
|
|
|
|
codeResult := gjson.GetBytes(resp, "code")
|
|
|
|
|
validCodes := map[string]bool{"1006": true, "1007": true, "1008": true, "1009": true, "1010": true}
|
|
|
|
|
if !validCodes[codeResult.String()] {
|
|
|
|
|
return nil, fmt.Errorf("查询手机在网时长失败, %s", string(resp))
|
|
|
|
|
}
|
|
|
|
|
data := gjson.GetBytes(resp, "data")
|
|
|
|
|
if !data.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("查询手机在网时长失败, %s", string(resp))
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: []byte(data.Raw),
|
|
|
|
|
}, nil
|
2024-12-28 02:21:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 手机二次卡
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG19BJ02Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-28 02:21:47 +08:00
|
|
|
|
mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
startDate := gjson.GetBytes(params, "startDate")
|
|
|
|
|
if !mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G19BJ02, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"phone": a.westDexService.Encrypt(mobile.String()),
|
|
|
|
|
"startDate": startDate.String(),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G19BJ02", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
// 获取 code 字段
|
|
|
|
|
codeResult := gjson.GetBytes(resp, "code")
|
|
|
|
|
if !codeResult.Exists() || (codeResult.String() != "1025" && codeResult.String() != "1026") {
|
|
|
|
|
return nil, fmt.Errorf("手机二次卡失败, %s", string(resp))
|
|
|
|
|
}
|
|
|
|
|
data := gjson.GetBytes(resp, "data")
|
|
|
|
|
if !data.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("手机二次卡失败, %s", string(resp))
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: []byte(data.Raw),
|
|
|
|
|
}, nil
|
2024-12-28 02:21:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 银行卡四要素
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG20GZ01Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2024-12-28 02:21:47 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
bankCard := gjson.GetBytes(params, "bank_card")
|
|
|
|
|
|
|
|
|
|
if !mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G20GZ01, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"name": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
"idcard": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
"acc_no": a.westDexService.Encrypt(bankCard.String()),
|
|
|
|
|
"mobile": a.westDexService.Encrypt(mobile.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G20GZ01", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
// 获取 code 字段
|
|
|
|
|
codeResult := gjson.GetBytes(resp, "code")
|
|
|
|
|
if !codeResult.Exists() || codeResult.String() != "10000" {
|
|
|
|
|
return nil, fmt.Errorf("银行卡四要素失败, %s", string(resp))
|
|
|
|
|
}
|
|
|
|
|
data := gjson.GetBytes(resp, "data")
|
|
|
|
|
if !data.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("银行卡四要素失败, %s", string(resp))
|
|
|
|
|
}
|
|
|
|
|
// 解析 data.Raw 字符串为接口类型
|
|
|
|
|
var parsedData interface{}
|
|
|
|
|
err := json.Unmarshal([]byte(data.String()), &parsedData)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("解析 data 失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将解析后的数据重新编码为 []byte
|
|
|
|
|
resultBytes, err := json.Marshal(parsedData)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("重新编码 data 失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resultBytes,
|
|
|
|
|
}, nil
|
2024-12-28 02:21:47 +08:00
|
|
|
|
}
|
2025-03-16 00:36:13 +08:00
|
|
|
|
|
|
|
|
|
// G37SC01 自然人失信信息
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG37SC01Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-16 00:36:13 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G37SC01, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"name": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
"idcard": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G37SC01", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
// 第一步:提取外层的 data 字段
|
|
|
|
|
dataResult := gjson.GetBytes(resp, "data")
|
|
|
|
|
if !dataResult.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("外层 data 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解析 data 字符串为 JSON 对象
|
|
|
|
|
parsedData := gjson.Parse(dataResult.String())
|
|
|
|
|
sxbzxr := parsedData.Get("sxbzxr")
|
|
|
|
|
if !sxbzxr.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("内层 sxbzxr 字段不存在")
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: []byte(sxbzxr.Raw),
|
|
|
|
|
}, nil
|
2025-03-16 00:36:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// G36SC01 自然人限高信息
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG36SC01Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-16 00:36:13 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G36SC01, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"name": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
"idcard": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G36SC01", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
// 第一步:提取外层的 data 字段
|
|
|
|
|
dataResult := gjson.GetBytes(resp, "data")
|
|
|
|
|
if !dataResult.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("外层 data 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解析 data 字符串为 JSON 对象
|
|
|
|
|
parsedData := gjson.Parse(dataResult.String())
|
|
|
|
|
xgbzxr := parsedData.Get("xgbzxr")
|
|
|
|
|
if !xgbzxr.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("内层 xgbzxr 字段不存在")
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: []byte(xgbzxr.Raw),
|
|
|
|
|
}, nil
|
2025-03-16 00:36:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// G22SC01 自然人司法模型
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessG22SC01Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-16 00:36:13 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G22SC01, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"name": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
"idcard": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
"inquired_auth": a.westDexService.GetDateRange(),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G22SC01", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
// 第一步:提取外层的 data 字段
|
|
|
|
|
dataResult := gjson.GetBytes(resp, "data")
|
|
|
|
|
if !dataResult.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("外层 data 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parseResult, err := lzUtils.RecursiveParse(dataResult.Raw)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("递归反序列化")
|
|
|
|
|
}
|
|
|
|
|
marshal, err := sonic.Marshal(parseResult)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("序列化失败: %v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: marshal,
|
|
|
|
|
}, nil
|
2025-03-16 00:36:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Q03SC01 企业涉诉信息
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessQ03SC01Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-16 00:36:13 +08:00
|
|
|
|
entName := gjson.GetBytes(params, "ent_name")
|
|
|
|
|
entCode := gjson.GetBytes(params, "ent_code")
|
|
|
|
|
|
|
|
|
|
if !entName.Exists() || !entCode.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, Q03SC01, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"uscc": a.westDexService.Encrypt(entCode.String()),
|
|
|
|
|
"org_name": a.westDexService.Encrypt(entName.String()),
|
|
|
|
|
"inquired_auth": a.westDexService.GetDateRange(),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("Q03SC01", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
// 第一步:提取外层的 data 字段
|
|
|
|
|
dataResult := gjson.GetBytes(resp, "data")
|
|
|
|
|
if !dataResult.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("外层 data 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-23 17:48:38 +08:00
|
|
|
|
// 保留原有的递归解析和序列化逻辑
|
2025-03-16 00:36:13 +08:00
|
|
|
|
parseResult, err := lzUtils.RecursiveParse(dataResult.Raw)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("递归反序列化")
|
|
|
|
|
}
|
2025-04-23 17:48:38 +08:00
|
|
|
|
logx.Infof("parseResult: %v", parseResult)
|
2025-03-16 00:36:13 +08:00
|
|
|
|
marshal, err := sonic.Marshal(parseResult)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("序列化失败: %v", err)
|
|
|
|
|
}
|
2025-04-23 17:48:38 +08:00
|
|
|
|
// 第二步:使用gjson预处理数据
|
|
|
|
|
dataMap := make(map[string]interface{})
|
|
|
|
|
|
|
|
|
|
// 处理entout数据
|
|
|
|
|
entoutArray := gjson.GetBytes(marshal, "entout").Array()
|
|
|
|
|
if len(entoutArray) > 0 {
|
|
|
|
|
// 检查是否存在count字段来判断是否有数据
|
|
|
|
|
countField := entoutArray[0].Get("data.count")
|
|
|
|
|
if countField.Exists() {
|
|
|
|
|
// 有count字段,表示有数据
|
|
|
|
|
entoutData := entoutArray[0].Get("data")
|
|
|
|
|
if entoutData.Exists() {
|
|
|
|
|
dataMap["data"] = json.RawMessage(entoutData.Raw)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 没有count字段,使用空对象
|
|
|
|
|
dataMap["data"] = json.RawMessage("{}")
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
dataMap["data"] = json.RawMessage("{}")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理sxbzxr数据(失信被执行人)
|
|
|
|
|
sxbzxrArray := dataResult.Get("sxbzxr").Array()
|
|
|
|
|
if len(sxbzxrArray) > 0 {
|
|
|
|
|
sxbzxrList := sxbzxrArray[0].Get("sxbzxr")
|
|
|
|
|
if sxbzxrList.Exists() && len(sxbzxrList.Array()) > 0 {
|
|
|
|
|
dataMap["sxbzxr"] = json.RawMessage(sxbzxrList.Raw)
|
|
|
|
|
} else {
|
|
|
|
|
dataMap["sxbzxr"] = json.RawMessage("[]")
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
dataMap["sxbzxr"] = json.RawMessage("[]")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理xgbzxr数据(限高被执行人)
|
|
|
|
|
xgbzxrArray := dataResult.Get("xgbzxr").Array()
|
|
|
|
|
if len(xgbzxrArray) > 0 {
|
|
|
|
|
xgbzxrList := xgbzxrArray[0].Get("xgbzxr")
|
|
|
|
|
if xgbzxrList.Exists() && len(xgbzxrList.Array()) > 0 {
|
|
|
|
|
dataMap["xgbzxr"] = json.RawMessage(xgbzxrList.Raw)
|
|
|
|
|
} else {
|
|
|
|
|
dataMap["xgbzxr"] = json.RawMessage("[]")
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
dataMap["xgbzxr"] = json.RawMessage("[]")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result, err := sonic.Marshal(dataMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("序列化预处理数据失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
2025-04-23 17:48:38 +08:00
|
|
|
|
Data: result,
|
2025-03-21 15:47:11 +08:00
|
|
|
|
}, nil
|
2025-03-16 00:36:13 +08:00
|
|
|
|
}
|
2025-03-20 02:03:28 +08:00
|
|
|
|
|
|
|
|
|
// 出境限制查询
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessCOM187Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-20 02:03:28 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
if !name.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, COM187, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"keyword": name.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("COM187", request)
|
2025-03-21 20:39:02 +08:00
|
|
|
|
if err != nil && err != ErrEmptyResult {
|
2025-03-20 02:03:28 +08:00
|
|
|
|
return nil, fmt.Errorf("出境限制查询失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-03-20 02:03:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 手机月消费档次查询
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessMOB035Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-20 02:03:28 +08:00
|
|
|
|
mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
if !mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, MOB035, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"mobile": mobile.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("MOB035", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("手机月消费档次查询失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-03-20 02:03:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 学历信息验证
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessPCB915Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-20 02:03:28 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
certificateNumber := gjson.GetBytes(params, "certificate_number")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() || !certificateNumber.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, PCB915, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"name": name.String(),
|
|
|
|
|
"cardNo": idCard.String(),
|
|
|
|
|
"certificateNo": certificateNumber.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("PCB915", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("学历信息验证失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-03-20 02:03:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 反诈反赌风险核验
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessRIS031Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-20 02:03:28 +08:00
|
|
|
|
keyword := gjson.GetBytes(params, "keyword")
|
|
|
|
|
typeName := gjson.GetBytes(params, "type")
|
|
|
|
|
|
|
|
|
|
if !keyword.Exists() || !typeName.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, RIS031, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"keyWord": keyword.String(),
|
|
|
|
|
"type": typeName.Int(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("RIS031", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("反诈反赌风险核验失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-03-20 02:03:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 手机号空号检测
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessPCB601Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-20 02:03:28 +08:00
|
|
|
|
mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
if !mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, PCB601, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"mobile": mobile.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("PCB601", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("手机号空号检测失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-03-20 02:03:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 银行卡归属地查询
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessPCB148Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-20 02:03:28 +08:00
|
|
|
|
bankCard := gjson.GetBytes(params, "bank_card")
|
|
|
|
|
if !bankCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, PCB148, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"cardId": bankCard.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("PCB148", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("银行卡归属地查询失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-03-20 02:03:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 银行卡姓名二要素验证
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessFIN011Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-20 02:03:28 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
bankCard := gjson.GetBytes(params, "bank_card")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !bankCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, FIN011, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"name": name.String(),
|
|
|
|
|
"cardId": bankCard.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("FIN011", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("银行卡姓名二要素验证失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-03-20 02:03:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 银行卡号码二要素验证
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessFIN020Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-20 02:03:28 +08:00
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
bankCard := gjson.GetBytes(params, "bank_card")
|
|
|
|
|
|
|
|
|
|
if !idCard.Exists() || !bankCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, FIN020, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"cardNo": idCard.String(),
|
|
|
|
|
"cardId": bankCard.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("FIN020", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("银行卡号码二要素验证失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-03-20 02:03:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 银行卡三要素综合验证
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessFIN018Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-20 02:03:28 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
bankCard := gjson.GetBytes(params, "bank_card")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() || !bankCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, FIN018, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"name": name.String(),
|
|
|
|
|
"cardNo": idCard.String(),
|
|
|
|
|
"cardId": bankCard.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("FIN018", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("银行卡三要素综合验证失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-03-20 02:03:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-04-02 19:06:13 +08:00
|
|
|
|
// 高风险特殊手机号
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessMOB032Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-20 02:03:28 +08:00
|
|
|
|
mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
if !mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, MOB032, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"mobile": mobile.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("MOB032", request)
|
|
|
|
|
if err != nil {
|
2025-04-02 19:06:13 +08:00
|
|
|
|
return nil, fmt.Errorf("高风险特殊手机号失败: %+v", err)
|
2025-03-20 02:03:28 +08:00
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-03-20 02:03:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 手机号贩毒反诈风险查询
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessFIN032Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-20 02:03:28 +08:00
|
|
|
|
keyword := gjson.GetBytes(params, "keyword")
|
|
|
|
|
typeName := gjson.GetBytes(params, "type")
|
|
|
|
|
|
|
|
|
|
if !keyword.Exists() || !typeName.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, FIN032, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"keyWord": keyword.String(),
|
|
|
|
|
"type": typeName.Int(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("FIN032", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("手机号贩毒反诈风险查询失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-03-20 02:03:28 +08:00
|
|
|
|
}
|
2025-03-20 15:57:46 +08:00
|
|
|
|
|
|
|
|
|
// 技能资格证书
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessHRD004Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-20 15:57:46 +08:00
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, HRD004, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"name": name.String(),
|
|
|
|
|
"cardNo": idCard.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("HRD004", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("HRD004请求失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-03-20 15:57:46 +08:00
|
|
|
|
}
|
2025-03-20 20:32:57 +08:00
|
|
|
|
|
|
|
|
|
// 手机归属地查询
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessMobilelocalRequest(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-20 20:32:57 +08:00
|
|
|
|
mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
if !mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, mobilelocal, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"phone": mobile.String(),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp, err := a.tianjuService.Request("mobilelocal", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("手机归属地查询失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-03-20 20:32:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 身份证归属地查询
|
2025-03-21 15:47:11 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessSfzRequest(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
2025-03-20 20:32:57 +08:00
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
if !idCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, sfz, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"idcard": idCard.String(),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp, err := a.tianjuService.Request("sfz", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("身份证归属地查询失败: %+v", err)
|
|
|
|
|
}
|
2025-03-21 15:47:11 +08:00
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
2025-03-20 20:32:57 +08:00
|
|
|
|
}
|
2025-04-02 19:06:13 +08:00
|
|
|
|
func (a *ApiRequestService) ProcessIDV044Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
if !idCard.Exists() || !name.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, IDV044, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"cardNo": idCard.String(),
|
|
|
|
|
"name": name.String(),
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.yushanService.request("IDV044", request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("婚姻状态查询失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resp,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
2025-04-23 17:48:38 +08:00
|
|
|
|
|
|
|
|
|
// PersonEnterprisePro 人企业关系加强版
|
|
|
|
|
func (a *ApiRequestService) ProcessPersonEnterpriseProRequest(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
// 设置最大调用次数上限
|
|
|
|
|
maxApiCalls := 20 // 允许最多查询20个企业
|
|
|
|
|
|
|
|
|
|
if !idCard.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, PersonEnterprisePro, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"pid": crypto.Md5Encrypt(idCard.String()),
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.G05HZ01CallAPI("G05HZ01", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理股东人企关系的响应数据
|
|
|
|
|
code := gjson.GetBytes(resp, "code")
|
|
|
|
|
if !code.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("响应中缺少 code 字段")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 判断 code 是否等于 "0000"
|
|
|
|
|
if code.String() == "0000" {
|
|
|
|
|
// 获取 data 字段的值
|
|
|
|
|
data := gjson.GetBytes(resp, "data")
|
|
|
|
|
if !data.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("响应中缺少 data 字段")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用gjson获取企业列表
|
|
|
|
|
datalistResult := gjson.Get(data.Raw, "datalist")
|
|
|
|
|
if !datalistResult.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("datalist字段不存在")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取所有企业并进行排序
|
|
|
|
|
companies := datalistResult.Array()
|
|
|
|
|
|
|
|
|
|
// 创建企业对象切片,用于排序
|
|
|
|
|
type CompanyWithPriority struct {
|
|
|
|
|
Index int
|
|
|
|
|
Data gjson.Result
|
|
|
|
|
RelationshipVal int // 关系权重值
|
|
|
|
|
RelationCount int // 关系数量
|
|
|
|
|
AdminPenalty int // 行政处罚数量
|
|
|
|
|
Executed int // 被执行人数量
|
|
|
|
|
Dishonest int // 失信被执行人数量
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
companiesWithPriority := make([]CompanyWithPriority, 0, len(companies))
|
|
|
|
|
|
|
|
|
|
// 遍历企业,计算优先级
|
|
|
|
|
for i, companyJson := range companies {
|
|
|
|
|
// 统计行政处罚、被执行人、失信被执行人
|
|
|
|
|
adminPenalty := 0
|
|
|
|
|
executed := 0
|
|
|
|
|
dishonest := 0
|
|
|
|
|
|
|
|
|
|
// 检查行政处罚字段是否存在并获取数组长度
|
|
|
|
|
adminPenaltyResult := companyJson.Get("adminPenalty")
|
|
|
|
|
if adminPenaltyResult.Exists() && adminPenaltyResult.IsArray() {
|
|
|
|
|
adminPenalty = len(adminPenaltyResult.Array())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查被执行人字段是否存在并获取数组长度
|
|
|
|
|
executedPersonResult := companyJson.Get("executedPerson")
|
|
|
|
|
if executedPersonResult.Exists() && executedPersonResult.IsArray() {
|
|
|
|
|
executed = len(executedPersonResult.Array())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查失信被执行人字段是否存在并获取数组长度
|
|
|
|
|
dishonestExecutedPersonResult := companyJson.Get("dishonestExecutedPerson")
|
|
|
|
|
if dishonestExecutedPersonResult.Exists() && dishonestExecutedPersonResult.IsArray() {
|
|
|
|
|
dishonest = len(dishonestExecutedPersonResult.Array())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 计算relationship权重
|
|
|
|
|
relationshipVal := 0
|
|
|
|
|
relationCount := 0
|
|
|
|
|
|
|
|
|
|
// 获取relationship数组
|
|
|
|
|
relationshipResult := companyJson.Get("relationship")
|
|
|
|
|
if relationshipResult.Exists() && relationshipResult.IsArray() {
|
|
|
|
|
relationships := relationshipResult.Array()
|
|
|
|
|
// 统计各类关系的数量和权重
|
|
|
|
|
for _, rel := range relationships {
|
|
|
|
|
relationCount++
|
|
|
|
|
relStr := rel.String()
|
|
|
|
|
|
|
|
|
|
// 根据关系类型设置权重,权重顺序:
|
|
|
|
|
// 股东(6) > 历史股东(5) > 法人(4) > 历史法人(3) > 高管(2) > 历史高管(1)
|
|
|
|
|
switch relStr {
|
|
|
|
|
case "sh": // 股东
|
|
|
|
|
if relationshipVal < 6 {
|
|
|
|
|
relationshipVal = 6
|
|
|
|
|
}
|
|
|
|
|
case "his_sh": // 历史股东
|
|
|
|
|
if relationshipVal < 5 {
|
|
|
|
|
relationshipVal = 5
|
|
|
|
|
}
|
|
|
|
|
case "lp": // 法人
|
|
|
|
|
if relationshipVal < 4 {
|
|
|
|
|
relationshipVal = 4
|
|
|
|
|
}
|
|
|
|
|
case "his_lp": // 历史法人
|
|
|
|
|
if relationshipVal < 3 {
|
|
|
|
|
relationshipVal = 3
|
|
|
|
|
}
|
|
|
|
|
case "tm": // 高管
|
|
|
|
|
if relationshipVal < 2 {
|
|
|
|
|
relationshipVal = 2
|
|
|
|
|
}
|
|
|
|
|
case "his_tm": // 历史高管
|
|
|
|
|
if relationshipVal < 1 {
|
|
|
|
|
relationshipVal = 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
companiesWithPriority = append(companiesWithPriority, CompanyWithPriority{
|
|
|
|
|
Index: i,
|
|
|
|
|
Data: companyJson,
|
|
|
|
|
RelationshipVal: relationshipVal,
|
|
|
|
|
RelationCount: relationCount,
|
|
|
|
|
AdminPenalty: adminPenalty,
|
|
|
|
|
Executed: executed,
|
|
|
|
|
Dishonest: dishonest,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 按优先级排序
|
|
|
|
|
sort.Slice(companiesWithPriority, func(i, j int) bool {
|
|
|
|
|
// 首先根据是否有失信被执行人排序
|
|
|
|
|
if companiesWithPriority[i].Dishonest != companiesWithPriority[j].Dishonest {
|
|
|
|
|
return companiesWithPriority[i].Dishonest > companiesWithPriority[j].Dishonest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 然后根据是否有被执行人排序
|
|
|
|
|
if companiesWithPriority[i].Executed != companiesWithPriority[j].Executed {
|
|
|
|
|
return companiesWithPriority[i].Executed > companiesWithPriority[j].Executed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 然后根据是否有行政处罚排序
|
|
|
|
|
if companiesWithPriority[i].AdminPenalty != companiesWithPriority[j].AdminPenalty {
|
|
|
|
|
return companiesWithPriority[i].AdminPenalty > companiesWithPriority[j].AdminPenalty
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 然后按relationship类型排序
|
|
|
|
|
if companiesWithPriority[i].RelationshipVal != companiesWithPriority[j].RelationshipVal {
|
|
|
|
|
return companiesWithPriority[i].RelationshipVal > companiesWithPriority[j].RelationshipVal
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 最后按relationship数量排序
|
|
|
|
|
return companiesWithPriority[i].RelationCount > companiesWithPriority[j].RelationCount
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 限制处理的企业数量
|
|
|
|
|
processCount := len(companiesWithPriority)
|
|
|
|
|
if processCount > maxApiCalls {
|
|
|
|
|
processCount = maxApiCalls
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 只处理前N个优先级高的企业
|
|
|
|
|
prioritizedCompanies := companiesWithPriority[:processCount]
|
|
|
|
|
|
|
|
|
|
// 使用WaitGroup和chan处理并发
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
results := make(chan struct {
|
|
|
|
|
index int
|
|
|
|
|
data []byte
|
|
|
|
|
err error
|
|
|
|
|
}, processCount)
|
|
|
|
|
|
|
|
|
|
// 对按优先级排序的前N个企业进行涉诉信息查询
|
|
|
|
|
for _, company := range prioritizedCompanies {
|
|
|
|
|
wg.Add(1)
|
|
|
|
|
go func(origIndex int, companyInfo gjson.Result) {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
logx.Infof("开始处理企业[%d],企业名称: %s,统一社会信用代码: %s", origIndex, companyInfo.Get("basicInfo.name").String(), companyInfo.Get("basicInfo.creditCode").String())
|
|
|
|
|
// 提取企业名称和统一社会信用代码
|
|
|
|
|
orgName := companyInfo.Get("basicInfo.name")
|
|
|
|
|
creditCode := companyInfo.Get("basicInfo.creditCode")
|
|
|
|
|
|
|
|
|
|
if !orgName.Exists() || !creditCode.Exists() {
|
|
|
|
|
results <- struct {
|
|
|
|
|
index int
|
|
|
|
|
data []byte
|
|
|
|
|
err error
|
|
|
|
|
}{origIndex, nil, fmt.Errorf("企业名称或统一社会信用代码不存在")}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解析原始公司信息为map
|
|
|
|
|
var companyMap map[string]interface{}
|
|
|
|
|
if err := json.Unmarshal([]byte(companyInfo.Raw), &companyMap); err != nil {
|
|
|
|
|
results <- struct {
|
|
|
|
|
index int
|
|
|
|
|
data []byte
|
|
|
|
|
err error
|
|
|
|
|
}{origIndex, nil, fmt.Errorf("解析企业信息失败: %v", err)}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构造调用Q03SC01的参数
|
|
|
|
|
q03Params, err := json.Marshal(map[string]string{
|
|
|
|
|
"ent_name": orgName.String(),
|
|
|
|
|
"ent_code": creditCode.String(),
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
// 参数构造失败,但不影响整体处理
|
|
|
|
|
logx.Errorf("构造企业[%s]涉诉查询参数失败: %v", orgName.String(), err)
|
|
|
|
|
companyMap["lawsuitInfo"] = map[string]interface{}{}
|
|
|
|
|
} else {
|
|
|
|
|
// 调用Q03SC01接口获取企业涉诉信息
|
|
|
|
|
lawsuitData, err := a.ProcessQ03SC01Request(ctx, q03Params)
|
|
|
|
|
// 无论是否有错误,都继续处理
|
|
|
|
|
if err != nil {
|
|
|
|
|
// 可能是正常没有涉诉数据,设置为空对象
|
|
|
|
|
logx.Infof("企业[%s]涉诉信息查询结果: %v", orgName.String(), err)
|
|
|
|
|
companyMap["lawsuitInfo"] = map[string]interface{}{}
|
|
|
|
|
} else if len(lawsuitData.Data) == 0 || string(lawsuitData.Data) == "{}" || string(lawsuitData.Data) == "null" {
|
|
|
|
|
// 无涉诉数据
|
|
|
|
|
companyMap["lawsuitInfo"] = map[string]interface{}{}
|
|
|
|
|
} else {
|
|
|
|
|
// 解析涉诉信息
|
|
|
|
|
var lawsuitInfo interface{}
|
|
|
|
|
if err := json.Unmarshal(lawsuitData.Data, &lawsuitInfo); err != nil {
|
|
|
|
|
logx.Errorf("解析企业[%s]涉诉信息失败: %v", orgName.String(), err)
|
|
|
|
|
companyMap["lawsuitInfo"] = map[string]interface{}{}
|
|
|
|
|
} else {
|
|
|
|
|
// 添加涉诉信息到企业信息中
|
|
|
|
|
companyMap["lawsuitInfo"] = lawsuitInfo
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 序列化更新后的企业信息
|
|
|
|
|
companyData, err := json.Marshal(companyMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
results <- struct {
|
|
|
|
|
index int
|
|
|
|
|
data []byte
|
|
|
|
|
err error
|
|
|
|
|
}{origIndex, nil, fmt.Errorf("序列化企业信息失败: %v", err)}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
results <- struct {
|
|
|
|
|
index int
|
|
|
|
|
data []byte
|
|
|
|
|
err error
|
|
|
|
|
}{origIndex, companyData, nil}
|
|
|
|
|
}(company.Index, company.Data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 关闭结果通道
|
|
|
|
|
go func() {
|
|
|
|
|
wg.Wait()
|
|
|
|
|
close(results)
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
// 解析原始数据为map
|
|
|
|
|
var dataMap map[string]interface{}
|
|
|
|
|
if err := json.Unmarshal([]byte(data.Raw), &dataMap); err != nil {
|
|
|
|
|
return nil, fmt.Errorf("解析data字段失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取原始企业列表
|
|
|
|
|
originalDatalist, ok := dataMap["datalist"].([]interface{})
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, fmt.Errorf("无法获取原始企业列表")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建结果映射,用于保存已处理的企业
|
|
|
|
|
processedCompanies := make(map[int]interface{})
|
|
|
|
|
|
|
|
|
|
// 收集处理过的企业数据
|
|
|
|
|
for result := range results {
|
|
|
|
|
if result.err != nil {
|
|
|
|
|
logx.Errorf("处理企业失败: %v", result.err)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if result.data != nil {
|
|
|
|
|
var companyMap interface{}
|
|
|
|
|
if err := json.Unmarshal(result.data, &companyMap); err == nil {
|
|
|
|
|
processedCompanies[result.index] = companyMap
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新企业列表
|
|
|
|
|
// 处理过的用新数据,未处理的保留原样
|
|
|
|
|
updatedDatalist := make([]interface{}, len(originalDatalist))
|
|
|
|
|
for i, company := range originalDatalist {
|
|
|
|
|
if processed, exists := processedCompanies[i]; exists {
|
|
|
|
|
// 已处理的企业,使用新数据
|
|
|
|
|
updatedDatalist[i] = processed
|
|
|
|
|
} else {
|
|
|
|
|
// 未处理的企业,保留原始数据并添加空的涉诉信息
|
|
|
|
|
companyMap, ok := company.(map[string]interface{})
|
|
|
|
|
if ok {
|
|
|
|
|
// 为未处理的企业添加空的涉诉信息
|
|
|
|
|
companyMap["lawsuitInfo"] = map[string]interface{}{}
|
|
|
|
|
updatedDatalist[i] = companyMap
|
|
|
|
|
} else {
|
|
|
|
|
updatedDatalist[i] = company
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新原始数据中的企业列表
|
|
|
|
|
dataMap["datalist"] = updatedDatalist
|
|
|
|
|
|
|
|
|
|
// 序列化最终结果
|
|
|
|
|
result, err := json.Marshal(dataMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("序列化最终结果失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: result,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// code不等于"0000",返回错误
|
|
|
|
|
return nil, fmt.Errorf("响应code错误: %s", code.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *ApiRequestService) ProcessBehaviorRiskScanRequest(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() || !mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, BehaviorRiskScan, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
type apiResult struct {
|
|
|
|
|
name string
|
|
|
|
|
data []byte
|
|
|
|
|
err error
|
|
|
|
|
}
|
|
|
|
|
results := make(chan apiResult, 5) // 5个风险检测项
|
|
|
|
|
|
|
|
|
|
// 并行调用五个不同的风险检测API
|
|
|
|
|
wg.Add(4)
|
|
|
|
|
|
|
|
|
|
// 黑灰产检测
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
data, err := a.ProcessG30BJ05Request(ctx, params)
|
|
|
|
|
results <- apiResult{name: "black_gray_level", data: data.Data, err: err}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
// 电诈风险预警
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
data, err := a.ProcessG31BJ05Request(ctx, params)
|
|
|
|
|
results <- apiResult{name: "telefraud_level", data: data.Data, err: err}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
// 团伙欺诈排查
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
data, err := a.ProcessG32BJ05Request(ctx, params)
|
|
|
|
|
results <- apiResult{name: "fraud_group", data: data.Data, err: err}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
// // 反诈反赌核验
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
data, err := a.ProcessRIS031Request(ctx, params)
|
|
|
|
|
results <- apiResult{name: "anti_fraud_gaming", data: data.Data, err: err}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
// 风险等级
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
data, err := a.ProcessG34BJ03Request(ctx, params)
|
|
|
|
|
results <- apiResult{name: "risk_level", data: data.Data, err: err}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
// 关闭结果通道
|
|
|
|
|
go func() {
|
|
|
|
|
wg.Wait()
|
|
|
|
|
close(results)
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
// 收集所有结果
|
|
|
|
|
resultMap := make(map[string]interface{})
|
|
|
|
|
var errors []string
|
|
|
|
|
|
|
|
|
|
for result := range results {
|
|
|
|
|
if result.err != nil {
|
|
|
|
|
// 记录错误但继续处理其他结果
|
|
|
|
|
errors = append(errors, fmt.Sprintf("%s: %v", result.name, result.err))
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解析JSON结果并添加到结果映射
|
|
|
|
|
var parsedData interface{}
|
|
|
|
|
if err := json.Unmarshal(result.data, &parsedData); err != nil {
|
|
|
|
|
errors = append(errors, fmt.Sprintf("解析%s数据失败: %v", result.name, err))
|
|
|
|
|
} else {
|
|
|
|
|
resultMap[result.name] = parsedData
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 添加错误信息到结果中(如果存在)
|
|
|
|
|
if len(errors) > 0 {
|
|
|
|
|
resultMap["errors"] = errors
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 序列化最终结果
|
|
|
|
|
finalResult, err := json.Marshal(resultMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("序列化行为风险扫描结果失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: finalResult,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// G30BJ05 黑灰产
|
|
|
|
|
func (a *ApiRequestService) ProcessG30BJ05Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
Mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() || !Mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G30BJ05, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"name": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
"id": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
"cell": a.westDexService.Encrypt(Mobile.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G30BJ05", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
fmt.Println(resp)
|
|
|
|
|
flagBlackgraylevel := gjson.GetBytes(resp, "flag_blackgraylevel")
|
|
|
|
|
if !flagBlackgraylevel.Exists() || flagBlackgraylevel.String() != "1" {
|
|
|
|
|
return nil, fmt.Errorf("自然人黑灰产信息查询失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bglLevel := gjson.GetBytes(resp, "bgl_level")
|
|
|
|
|
if !bglLevel.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("bgl_level 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: []byte(bglLevel.Raw),
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// G31BJ05 电诈风险预警
|
|
|
|
|
func (a *ApiRequestService) ProcessG31BJ05Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
Mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() || !Mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G31BJ05, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"name": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
"id": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
"cell": a.westDexService.Encrypt(Mobile.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G31BJ05", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
fmt.Println(resp)
|
|
|
|
|
flagTelefraudpredictstd := gjson.GetBytes(resp, "flag_telefraudpredictstd")
|
|
|
|
|
if !flagTelefraudpredictstd.Exists() || flagTelefraudpredictstd.String() != "1" {
|
|
|
|
|
return nil, fmt.Errorf("自然人电诈风险预警查询失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tfpsLevel := gjson.GetBytes(resp, "tfps_level")
|
|
|
|
|
if !tfpsLevel.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("tfps_level 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: []byte(tfpsLevel.Raw),
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// G32BJ05 团伙欺诈排查
|
|
|
|
|
func (a *ApiRequestService) ProcessG32BJ05Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
Mobile := gjson.GetBytes(params, "mobile")
|
|
|
|
|
|
|
|
|
|
if !name.Exists() || !idCard.Exists() || !Mobile.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G32BJ05, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"name": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
"id": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
"cell": a.westDexService.Encrypt(Mobile.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G32BJ05", request)
|
|
|
|
|
if callApiErr != nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
flagFraudrelation := gjson.GetBytes(resp, "flag_fraudrelation")
|
|
|
|
|
if !flagFraudrelation.Exists() || flagFraudrelation.String() != "1" {
|
|
|
|
|
return nil, fmt.Errorf("自然人团伙欺诈排查查询失败")
|
|
|
|
|
}
|
|
|
|
|
frgListLevel := gjson.GetBytes(resp, "frg_list_level")
|
|
|
|
|
if !frgListLevel.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("frg_list_level 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
frgGroupNum := gjson.GetBytes(resp, "frg_group_num")
|
|
|
|
|
if !frgGroupNum.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("frg_group_num 字段不存在")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构建包含两个字段的JSON响应
|
|
|
|
|
result := map[string]interface{}{
|
|
|
|
|
"frg_list_level": frgListLevel.Value(),
|
|
|
|
|
"frg_group_num": frgGroupNum.Value(),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resultJSON, err := json.Marshal(result)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("序列化结果失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: resultJSON,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
func (a *ApiRequestService) ProcessG09XM02Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
if !idCard.Exists() || !name.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G09XM02, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"idCard": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
"name": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.westDexService.CallAPI("G09XM02", request)
|
|
|
|
|
if err != nil && resp == nil {
|
|
|
|
|
return nil, fmt.Errorf("婚姻状态查询失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
result := gjson.GetBytes(resp, "data.data")
|
|
|
|
|
if !result.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("婚姻状态查询失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取原始结果
|
|
|
|
|
rawResult := result.String()
|
|
|
|
|
|
|
|
|
|
// 根据结果转换状态码
|
|
|
|
|
var statusCode string
|
|
|
|
|
switch {
|
|
|
|
|
case strings.HasPrefix(rawResult, "INR"):
|
|
|
|
|
statusCode = "0" // 匹配不成功
|
|
|
|
|
case strings.HasPrefix(rawResult, "IA"):
|
|
|
|
|
statusCode = "1" // 结婚
|
|
|
|
|
case strings.HasPrefix(rawResult, "IB"):
|
|
|
|
|
statusCode = "2" // 离婚
|
|
|
|
|
default:
|
|
|
|
|
return nil, fmt.Errorf("婚姻状态查询失败,未知状态码: %s", statusCode)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构建新的返回结果
|
|
|
|
|
response := map[string]string{
|
|
|
|
|
"status": statusCode,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 序列化为JSON
|
|
|
|
|
jsonResponse, err := json.Marshal(response)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("序列化结果失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: jsonResponse,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *ApiRequestService) ProcessG10XM02Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
|
|
|
|
// 提取男方和女方信息
|
|
|
|
|
nameMan := gjson.GetBytes(params, "nameMan")
|
|
|
|
|
idCardMan := gjson.GetBytes(params, "idCardMan")
|
|
|
|
|
nameWoman := gjson.GetBytes(params, "nameWoman")
|
|
|
|
|
idCardWoman := gjson.GetBytes(params, "idCardWoman")
|
|
|
|
|
|
|
|
|
|
// 校验是否存在必要参数
|
|
|
|
|
if !nameMan.Exists() || !idCardMan.Exists() || !nameWoman.Exists() || !idCardWoman.Exists() {
|
|
|
|
|
return nil, errors.New("请求参数缺失:需要提供男方和女方的姓名及身份证号")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构造请求数据
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"idCardMan": a.westDexService.Encrypt(idCardMan.String()),
|
|
|
|
|
"nameMan": a.westDexService.Encrypt(nameMan.String()),
|
|
|
|
|
"idCardWoman": a.westDexService.Encrypt(idCardWoman.String()),
|
|
|
|
|
"nameWoman": a.westDexService.Encrypt(nameWoman.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 调用 API
|
|
|
|
|
resp, callApiErr := a.westDexService.CallAPI("G10XM02", request)
|
|
|
|
|
if callApiErr != nil && resp == nil {
|
|
|
|
|
return nil, callApiErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result := gjson.GetBytes(resp, "data.data")
|
|
|
|
|
if !result.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("婚姻状态查询失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取原始结果
|
|
|
|
|
rawResult := result.String()
|
|
|
|
|
|
|
|
|
|
// 根据结果转换状态码
|
|
|
|
|
var statusCode string
|
|
|
|
|
switch {
|
|
|
|
|
case strings.HasPrefix(rawResult, "INR"):
|
|
|
|
|
statusCode = "0" // 匹配不成功
|
|
|
|
|
case strings.HasPrefix(rawResult, "IA"):
|
|
|
|
|
statusCode = "1" // 结婚
|
|
|
|
|
case strings.HasPrefix(rawResult, "IB"):
|
|
|
|
|
statusCode = "2" // 离婚
|
|
|
|
|
default:
|
|
|
|
|
return nil, fmt.Errorf("婚姻状态查询失败,未知状态码: %s", statusCode)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构建新的返回结果
|
|
|
|
|
response := map[string]string{
|
|
|
|
|
"status": statusCode,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 序列化为JSON
|
|
|
|
|
jsonResponse, err := json.Marshal(response)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("序列化结果失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: jsonResponse,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
func (a *ApiRequestService) ProcessG11BJ06Request(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
|
|
|
|
idCard := gjson.GetBytes(params, "id_card")
|
|
|
|
|
name := gjson.GetBytes(params, "name")
|
|
|
|
|
if !idCard.Exists() || !name.Exists() {
|
|
|
|
|
return nil, errors.New("api请求, G11BJ06, 获取相关参数失败")
|
|
|
|
|
}
|
|
|
|
|
request := map[string]interface{}{
|
|
|
|
|
"data": map[string]interface{}{
|
|
|
|
|
"id_card_value": a.westDexService.Encrypt(idCard.String()),
|
|
|
|
|
"name_value": a.westDexService.Encrypt(name.String()),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resp, err := a.westDexService.CallAPI("G11BJ06", request)
|
|
|
|
|
if err != nil && resp == nil {
|
|
|
|
|
return nil, fmt.Errorf("教育经历核验查询失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解析响应
|
|
|
|
|
codeResult := gjson.GetBytes(resp, "data.education_background.code")
|
|
|
|
|
if !codeResult.Exists() {
|
|
|
|
|
return nil, fmt.Errorf("教育经历核验查询失败: 返回数据缺少code字段")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
code := codeResult.String()
|
|
|
|
|
|
|
|
|
|
var result map[string]interface{}
|
|
|
|
|
|
|
|
|
|
switch code {
|
|
|
|
|
case "9100":
|
|
|
|
|
// 查询成功有结果
|
|
|
|
|
eduResultArray := gjson.GetBytes(resp, "data.education_background.data").Array()
|
|
|
|
|
var processedEduData []interface{}
|
|
|
|
|
|
|
|
|
|
// 提取每个元素中Raw字段的实际内容
|
|
|
|
|
for _, item := range eduResultArray {
|
|
|
|
|
var eduInfo interface{}
|
|
|
|
|
if err := json.Unmarshal([]byte(item.Raw), &eduInfo); err != nil {
|
|
|
|
|
return nil, fmt.Errorf("解析教育信息失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
processedEduData = append(processedEduData, eduInfo)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = map[string]interface{}{
|
|
|
|
|
"data": processedEduData,
|
|
|
|
|
"status": 1,
|
|
|
|
|
}
|
|
|
|
|
case "9000":
|
|
|
|
|
// 查询成功无结果
|
|
|
|
|
result = map[string]interface{}{
|
|
|
|
|
"data": []interface{}{},
|
|
|
|
|
"status": 0,
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
// 其他情况视为错误
|
|
|
|
|
errMsg := gjson.GetBytes(resp, "data.education_background.msg").String()
|
|
|
|
|
return nil, fmt.Errorf("教育经历核验查询失败: %s (code: %s)", errMsg, code)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将结果转为JSON字节
|
|
|
|
|
jsonResult, err := json.Marshal(result)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("处理教育经历查询结果失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &APIInternalResult{
|
|
|
|
|
Data: jsonResult,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|