1428 lines
43 KiB
Go
1428 lines
43 KiB
Go
package service
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"errors"
|
||
"fmt"
|
||
"io"
|
||
"net/http"
|
||
"net/url"
|
||
"qnc-server/app/user/cmd/api/internal/config"
|
||
"qnc-server/app/user/model"
|
||
"qnc-server/pkg/lzkit/crypto"
|
||
"qnc-server/pkg/lzkit/lzUtils"
|
||
"strings"
|
||
"sync"
|
||
"sync/atomic"
|
||
"time"
|
||
|
||
"github.com/Masterminds/squirrel"
|
||
"github.com/bytedance/sonic"
|
||
"github.com/tidwall/gjson"
|
||
"github.com/zeromicro/go-zero/core/logx"
|
||
)
|
||
|
||
type ApiRequestService struct {
|
||
config config.Config
|
||
westDexService *WestDexService
|
||
yushanService *YushanService
|
||
featureModel model.FeatureModel
|
||
productFeatureModel model.ProductFeatureModel
|
||
}
|
||
|
||
// NewApiRequestService 是一个构造函数,用于初始化 ApiRequestService
|
||
func NewApiRequestService(c config.Config, westDexService *WestDexService, yushanService *YushanService, featureModel model.FeatureModel, productFeatureModel model.ProductFeatureModel) *ApiRequestService {
|
||
return &ApiRequestService{
|
||
config: c,
|
||
featureModel: featureModel,
|
||
productFeatureModel: productFeatureModel,
|
||
westDexService: westDexService,
|
||
yushanService: yushanService,
|
||
}
|
||
}
|
||
|
||
type APIResponseData struct {
|
||
ApiID string `json:"apiID"`
|
||
Data json.RawMessage `json:"data"` // 这里用 RawMessage 来存储原始的 data
|
||
Sort int64 `json:"sort"`
|
||
Success bool `json:"success"`
|
||
Timestamp string `json:"timestamp"`
|
||
Error string `json:"error,omitempty"`
|
||
}
|
||
|
||
// ProcessRequests 处理请求
|
||
func (a *ApiRequestService) ProcessRequests(params []byte, productID int64) ([]byte, error) {
|
||
var ctx, cancel = context.WithCancel(context.Background())
|
||
defer cancel()
|
||
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
|
||
isImportantMap := make(map[int64]int64, len(productFeatureList))
|
||
sortMap := make(map[int64]int64, len(productFeatureList)) // 新增
|
||
for _, pf := range productFeatureList {
|
||
featureIDs = append(featureIDs, pf.FeatureId)
|
||
isImportantMap[pf.FeatureId] = pf.IsImportant
|
||
sortMap[pf.FeatureId] = pf.Sort // 新增
|
||
}
|
||
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
|
||
errorLimit = len(featureList)
|
||
retryNum = 5
|
||
)
|
||
|
||
for i, feature := range featureList {
|
||
wg.Add(1)
|
||
go func(i int, feature *model.Feature) {
|
||
defer wg.Done()
|
||
|
||
select {
|
||
case <-ctx.Done():
|
||
return
|
||
default:
|
||
}
|
||
result := APIResponseData{
|
||
ApiID: feature.ApiId,
|
||
Success: false,
|
||
Sort: sortMap[feature.Id],
|
||
}
|
||
timestamp := time.Now().Format("2006-01-02 15:04:05")
|
||
var (
|
||
resp json.RawMessage
|
||
preprocessErr error
|
||
)
|
||
// 若 isImportantMap[feature.ID] == 1,则表示需要在出错时重试
|
||
isImportant := isImportantMap[feature.Id] == 1
|
||
tryCount := 0
|
||
for {
|
||
tryCount++
|
||
resp, preprocessErr = a.PreprocessRequestApi(params, feature.ApiId)
|
||
if preprocessErr == nil {
|
||
break
|
||
}
|
||
if isImportant && tryCount < retryNum {
|
||
continue
|
||
} else {
|
||
break
|
||
}
|
||
}
|
||
if preprocessErr != nil {
|
||
result.Timestamp = timestamp
|
||
result.Error = preprocessErr.Error()
|
||
result.Data = resp
|
||
resultsCh <- result
|
||
errorsCh <- fmt.Errorf("请求失败: %v", preprocessErr)
|
||
atomic.AddInt32(&errorCount, 1)
|
||
if atomic.LoadInt32(&errorCount) >= int32(errorLimit) {
|
||
cancel()
|
||
}
|
||
return
|
||
}
|
||
|
||
result.Data = resp
|
||
result.Success = true
|
||
result.Timestamp = timestamp
|
||
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
|
||
}
|
||
|
||
// ------------------------------------请求处理器--------------------------
|
||
var requestProcessors = map[string]func(*ApiRequestService, []byte) ([]byte, error){
|
||
"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,
|
||
"CAR061": (*ApiRequestService).ProcessCAR061Request,
|
||
"G10SC02": (*ApiRequestService).ProcessG10SC02Request,
|
||
"G03HZ01": (*ApiRequestService).ProcessG03HZ01Request,
|
||
"G02BJ02": (*ApiRequestService).ProcessG02BJ02Request,
|
||
"G19BJ02": (*ApiRequestService).ProcessG19BJ02Request,
|
||
"G20GZ01": (*ApiRequestService).ProcessG20GZ01Request,
|
||
"CAR074": (*ApiRequestService).ProcessCAR074Request,
|
||
"CAR058": (*ApiRequestService).ProcessCAR058Request,
|
||
"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,
|
||
}
|
||
|
||
// PreprocessRequestApi 调用指定的请求处理函数
|
||
func (a *ApiRequestService) PreprocessRequestApi(params []byte, apiID string) ([]byte, error) {
|
||
if processor, exists := requestProcessors[apiID]; exists {
|
||
return processor(a, params) // 调用 ApiRequestService 方法
|
||
}
|
||
|
||
return nil, errors.New("api请求, 未找到相应的处理程序")
|
||
}
|
||
|
||
func (a *ApiRequestService) ProcessG09SC02Request(params []byte) ([]byte, error) {
|
||
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
|
||
}
|
||
return jsonResponse, nil
|
||
} else {
|
||
return nil, errors.New("查询为空")
|
||
}
|
||
}
|
||
|
||
func (a *ApiRequestService) ProcessG27BJ05Request(params []byte) ([]byte, 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请求, 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)
|
||
}
|
||
return modifiedData, nil
|
||
}
|
||
|
||
func (a *ApiRequestService) ProcessG26BJ05Request(params []byte) ([]byte, 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请求, 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)
|
||
}
|
||
return modifiedData, nil
|
||
}
|
||
|
||
func (a *ApiRequestService) ProcessG34BJ03Request(params []byte) ([]byte, error) {
|
||
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
|
||
}
|
||
return jsonResponse, nil
|
||
} else {
|
||
return nil, errors.New("查询为空")
|
||
}
|
||
}
|
||
|
||
func (a *ApiRequestService) ProcessG35SC01Request(params []byte) ([]byte, error) {
|
||
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 字段不存在或类型错误")
|
||
}
|
||
|
||
if innerData == "" || innerData == "{}" || innerData == "[]" {
|
||
innerData = "{}"
|
||
}
|
||
|
||
// 第四步:解析内层 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)
|
||
}
|
||
|
||
return finalDataBytes, nil
|
||
}
|
||
|
||
func (a *ApiRequestService) ProcessG28BJ05Request(params []byte) ([]byte, 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请求, 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)
|
||
}
|
||
return modifiedData, nil
|
||
}
|
||
|
||
func (a *ApiRequestService) ProcessG05HZ01Request(params []byte) ([]byte, error) {
|
||
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 字段的内容
|
||
return []byte(data.Raw), nil
|
||
}
|
||
|
||
// code 不等于 "0000",返回错误
|
||
return nil, fmt.Errorf("响应code错误%s", code.String())
|
||
}
|
||
|
||
func (a *ApiRequestService) ProcessQ23SC01Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return finalDataBytes, nil
|
||
}
|
||
|
||
func (a *ApiRequestService) ProcessG15BJ02Request(params []byte) ([]byte, 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请求, 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 {
|
||
return resp, nil
|
||
}
|
||
|
||
return nil, fmt.Errorf("三要素核验失败: %+v", resp)
|
||
}
|
||
|
||
func (a *ApiRequestService) ProcessG17BJ02Request(params []byte) ([]byte, error) {
|
||
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 {
|
||
return resp, nil
|
||
}
|
||
|
||
return nil, fmt.Errorf("手机二要素核验失败: %+v", resp)
|
||
}
|
||
|
||
func (a *ApiRequestService) ProcessG08SC02Request(params []byte) ([]byte, error) {
|
||
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
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
func (a *ApiRequestService) ProcessKZEYSRequest(params []byte) ([]byte, error) {
|
||
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
|
||
// 成功返回
|
||
return []byte(dataRaw), nil
|
||
}
|
||
|
||
// 人车核验
|
||
func (a *ApiRequestService) ProcessP_C_B332Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 车辆出险信息
|
||
func (a *ApiRequestService) ProcessCAR074Request(params []byte) ([]byte, error) {
|
||
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 {
|
||
return nil, fmt.Errorf("车辆出险信息查询失败: %+v", err)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 车辆维保记录
|
||
func (a *ApiRequestService) ProcessCAR058Request(params []byte) ([]byte, error) {
|
||
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 {
|
||
return nil, fmt.Errorf("人车核验查询失败: %+v", err)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 车架号查车
|
||
func (a *ApiRequestService) ProcessCAR079Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 车辆过户次数
|
||
func (a *ApiRequestService) ProcessCAR066Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 车辆估值
|
||
func (a *ApiRequestService) ProcessCAR100Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 银行卡黑名单
|
||
func (a *ApiRequestService) ProcessFIN019Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 名下车辆
|
||
func (a *ApiRequestService) ProcessCAR061Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
func (a *ApiRequestService) ProcessG10SC02Request(params []byte) ([]byte, 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{}{
|
||
"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
|
||
}
|
||
return jsonResponse, nil
|
||
} else {
|
||
return nil, errors.New("查询为空")
|
||
}
|
||
}
|
||
|
||
// 手机号码风险
|
||
func (a *ApiRequestService) ProcessG03HZ01Request(params []byte) ([]byte, error) {
|
||
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))
|
||
}
|
||
return []byte(data.Raw), nil
|
||
}
|
||
|
||
// 手机在网时长
|
||
func (a *ApiRequestService) ProcessG02BJ02Request(params []byte) ([]byte, error) {
|
||
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))
|
||
}
|
||
return []byte(data.Raw), nil
|
||
}
|
||
|
||
// 手机二次卡
|
||
func (a *ApiRequestService) ProcessG19BJ02Request(params []byte) ([]byte, error) {
|
||
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))
|
||
}
|
||
return []byte(data.Raw), nil
|
||
}
|
||
|
||
// 银行卡四要素
|
||
func (a *ApiRequestService) ProcessG20GZ01Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
|
||
return resultBytes, nil
|
||
}
|
||
|
||
// G37SC01 自然人失信信息
|
||
func (a *ApiRequestService) ProcessG37SC01Request(params []byte) ([]byte, error) {
|
||
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 字段不存在")
|
||
}
|
||
return []byte(sxbzxr.Raw), nil
|
||
}
|
||
|
||
// G36SC01 自然人限高信息
|
||
func (a *ApiRequestService) ProcessG36SC01Request(params []byte) ([]byte, error) {
|
||
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 字段不存在")
|
||
}
|
||
return []byte(xgbzxr.Raw), nil
|
||
}
|
||
|
||
// G22SC01 自然人司法模型
|
||
func (a *ApiRequestService) ProcessG22SC01Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return marshal, nil
|
||
}
|
||
|
||
// Q03SC01 企业涉诉信息
|
||
func (a *ApiRequestService) ProcessQ03SC01Request(params []byte) ([]byte, error) {
|
||
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 字段不存在")
|
||
}
|
||
|
||
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)
|
||
}
|
||
return marshal, nil
|
||
}
|
||
|
||
// 出境限制查询
|
||
func (a *ApiRequestService) ProcessCOM187Request(params []byte) ([]byte, error) {
|
||
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)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("出境限制查询失败: %+v", err)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 手机月消费档次查询
|
||
func (a *ApiRequestService) ProcessMOB035Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 学历信息验证
|
||
func (a *ApiRequestService) ProcessPCB915Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 反诈反赌风险核验
|
||
func (a *ApiRequestService) ProcessRIS031Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 手机号空号检测
|
||
func (a *ApiRequestService) ProcessPCB601Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 银行卡归属地查询
|
||
func (a *ApiRequestService) ProcessPCB148Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 银行卡姓名二要素验证
|
||
func (a *ApiRequestService) ProcessFIN011Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 银行卡号码二要素验证
|
||
func (a *ApiRequestService) ProcessFIN020Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 银行卡三要素综合验证
|
||
func (a *ApiRequestService) ProcessFIN018Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 手机号码风险评估
|
||
func (a *ApiRequestService) ProcessMOB032Request(params []byte) ([]byte, error) {
|
||
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 {
|
||
return nil, fmt.Errorf("手机号码风险评估失败: %+v", err)
|
||
}
|
||
return resp, nil
|
||
}
|
||
|
||
// 手机号贩毒反诈风险查询
|
||
func (a *ApiRequestService) ProcessFIN032Request(params []byte) ([]byte, error) {
|
||
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)
|
||
}
|
||
return resp, nil
|
||
}
|