fix
This commit is contained in:
@@ -60,8 +60,6 @@ Applepay:
|
|||||||
LoadPrivateKeyPath: "etc/merchant/AuthKey_LAY65829DQ.p8"
|
LoadPrivateKeyPath: "etc/merchant/AuthKey_LAY65829DQ.p8"
|
||||||
Ali:
|
Ali:
|
||||||
Code: "d55b58829efb41c8aa8e86769cba4844"
|
Code: "d55b58829efb41c8aa8e86769cba4844"
|
||||||
SystemConfig:
|
|
||||||
ThreeVerify: false
|
|
||||||
AdminConfig:
|
AdminConfig:
|
||||||
AccessSecret: "jK8nP3qR7tV2xZ5aB9cD1eF6gH4iJ0kL8mN5oP6qR7sT"
|
AccessSecret: "jK8nP3qR7tV2xZ5aB9cD1eF6gH4iJ0kL8mN5oP6qR7sT"
|
||||||
AccessExpire: 604800
|
AccessExpire: 604800
|
||||||
@@ -87,3 +85,8 @@ Log:
|
|||||||
- "stat" # 统计日志
|
- "stat" # 统计日志
|
||||||
- "business" # 业务日志
|
- "business" # 业务日志
|
||||||
- "security" # 安全日志
|
- "security" # 安全日志
|
||||||
|
Tianyuanapi:
|
||||||
|
AccessID: "3c042bb99b240ccc"
|
||||||
|
Key: "2732f526167c2de9b8dc6aa0f24ba8b7"
|
||||||
|
BaseURL: "https://api.tianyuanapi.com"
|
||||||
|
Timeout: 60
|
||||||
|
|||||||
@@ -62,8 +62,6 @@ Applepay:
|
|||||||
LoadPrivateKeyPath: "etc/merchant/AuthKey_LAY65829DQ.p8"
|
LoadPrivateKeyPath: "etc/merchant/AuthKey_LAY65829DQ.p8"
|
||||||
Ali:
|
Ali:
|
||||||
Code: "d55b58829efb41c8aa8e86769cba4844"
|
Code: "d55b58829efb41c8aa8e86769cba4844"
|
||||||
SystemConfig:
|
|
||||||
ThreeVerify: false
|
|
||||||
AdminConfig:
|
AdminConfig:
|
||||||
AccessSecret: "jK8nP3qR7tV2xZ5aB9cD1eF6gH4iJ0kL8mN5oP6qR7sT"
|
AccessSecret: "jK8nP3qR7tV2xZ5aB9cD1eF6gH4iJ0kL8mN5oP6qR7sT"
|
||||||
AccessExpire: 604800
|
AccessExpire: 604800
|
||||||
@@ -74,3 +72,8 @@ CleanTask:
|
|||||||
Enabled: true
|
Enabled: true
|
||||||
Time: "0 3 * * *"
|
Time: "0 3 * * *"
|
||||||
Days: 15
|
Days: 15
|
||||||
|
Tianyuanapi:
|
||||||
|
AccessID: "3c042bb99b240ccc"
|
||||||
|
Key: "2732f526167c2de9b8dc6aa0f24ba8b7"
|
||||||
|
BaseURL: "https://api.tianyuanapi.com"
|
||||||
|
Timeout: 60
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ type Config struct {
|
|||||||
WestConfig WestConfig
|
WestConfig WestConfig
|
||||||
YushanConfig YushanConfig
|
YushanConfig YushanConfig
|
||||||
TianjuConfig TianjuConfig
|
TianjuConfig TianjuConfig
|
||||||
SystemConfig SystemConfig
|
|
||||||
AdminConfig AdminConfig
|
AdminConfig AdminConfig
|
||||||
AdminPromotion AdminPromotion
|
AdminPromotion AdminPromotion
|
||||||
CleanTask CleanTask
|
CleanTask CleanTask
|
||||||
|
Tianyuanapi TianyuanapiConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// JwtAuth 用于 JWT 鉴权配置
|
// JwtAuth 用于 JWT 鉴权配置
|
||||||
@@ -91,9 +91,6 @@ type TianjuConfig struct {
|
|||||||
ApiKey string
|
ApiKey string
|
||||||
BaseURL string
|
BaseURL string
|
||||||
}
|
}
|
||||||
type SystemConfig struct {
|
|
||||||
ThreeVerify bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type AdminConfig struct {
|
type AdminConfig struct {
|
||||||
AccessSecret string
|
AccessSecret string
|
||||||
@@ -109,3 +106,9 @@ type CleanTask struct {
|
|||||||
Time string
|
Time string
|
||||||
Days int
|
Days int
|
||||||
}
|
}
|
||||||
|
type TianyuanapiConfig struct {
|
||||||
|
AccessID string
|
||||||
|
Key string
|
||||||
|
BaseURL string
|
||||||
|
Timeout int64
|
||||||
|
}
|
||||||
|
|||||||
@@ -75,15 +75,10 @@ func (l *QueryServiceLogic) VerifyCode(mobile string, code string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 二、三要素验证
|
// 三要素验证
|
||||||
func (l *QueryServiceLogic) Verify(Name string, IDCard string, Mobile string) error {
|
func (l *QueryServiceLogic) Verify(Name string, IDCard string, Mobile string) error {
|
||||||
if l.svcCtx.Config.SystemConfig.ThreeVerify {
|
// 三要素验证
|
||||||
// 三要素验证
|
return l.VerifyThreeFactors(Name, IDCard, Mobile)
|
||||||
return l.VerifyThreeFactors(Name, IDCard, Mobile)
|
|
||||||
} else {
|
|
||||||
// 二要素验证
|
|
||||||
return l.VerifyTwoFactors(Name, IDCard)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// VerifyTwoFactors 二要素验证
|
// VerifyTwoFactors 二要素验证
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -15,9 +14,9 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
"tyc-server/app/main/api/internal/config"
|
"tyc-server/app/main/api/internal/config"
|
||||||
|
tianyuanapi "tyc-server/app/main/api/internal/service/tianyuanapi_sdk"
|
||||||
"tyc-server/app/main/model"
|
"tyc-server/app/main/model"
|
||||||
"tyc-server/pkg/lzkit/crypto"
|
"tyc-server/pkg/lzkit/crypto"
|
||||||
"tyc-server/pkg/lzkit/lzUtils"
|
|
||||||
|
|
||||||
"github.com/Masterminds/squirrel"
|
"github.com/Masterminds/squirrel"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
@@ -29,12 +28,13 @@ type ApiRequestService struct {
|
|||||||
westDexService *WestDexService
|
westDexService *WestDexService
|
||||||
yushanService *YushanService
|
yushanService *YushanService
|
||||||
tianjuService *TianjuService
|
tianjuService *TianjuService
|
||||||
|
tianyuanapiService *tianyuanapi.Client
|
||||||
featureModel model.FeatureModel
|
featureModel model.FeatureModel
|
||||||
productFeatureModel model.ProductFeatureModel
|
productFeatureModel model.ProductFeatureModel
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewApiRequestService 是一个构造函数,用于初始化 ApiRequestService
|
// NewApiRequestService 是一个构造函数,用于初始化 ApiRequestService
|
||||||
func NewApiRequestService(c config.Config, westDexService *WestDexService, yushanService *YushanService, tianjuService *TianjuService, featureModel model.FeatureModel, productFeatureModel model.ProductFeatureModel) *ApiRequestService {
|
func NewApiRequestService(c config.Config, westDexService *WestDexService, yushanService *YushanService, tianjuService *TianjuService, tianyuanapiService *tianyuanapi.Client, featureModel model.FeatureModel, productFeatureModel model.ProductFeatureModel) *ApiRequestService {
|
||||||
return &ApiRequestService{
|
return &ApiRequestService{
|
||||||
config: c,
|
config: c,
|
||||||
featureModel: featureModel,
|
featureModel: featureModel,
|
||||||
@@ -42,6 +42,7 @@ func NewApiRequestService(c config.Config, westDexService *WestDexService, yusha
|
|||||||
westDexService: westDexService,
|
westDexService: westDexService,
|
||||||
yushanService: yushanService,
|
yushanService: yushanService,
|
||||||
tianjuService: tianjuService,
|
tianjuService: tianjuService,
|
||||||
|
tianyuanapiService: tianyuanapiService,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,14 +266,16 @@ func (a *ApiRequestService) ProcessG09SC02Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"name": name.String(),
|
||||||
"certNumMan": a.westDexService.Encrypt(idCard.String()),
|
"id_card": idCard.String(),
|
||||||
"nameMan": a.westDexService.Encrypt(name.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G09SC02", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("IVYZ5733", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
result := gjson.GetBytes(resp, "data.0.maritalStatus")
|
result := gjson.GetBytes(resp, "data.0.maritalStatus")
|
||||||
|
|
||||||
@@ -300,15 +303,17 @@ func (a *ApiRequestService) ProcessG27BJ05Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"name": name.String(),
|
||||||
"id": a.westDexService.Encrypt(idCard.String()),
|
"id_card": idCard.String(),
|
||||||
"name": a.westDexService.Encrypt(name.String()),
|
"mobile_no": mobile.String(),
|
||||||
"cell": a.westDexService.Encrypt(mobile.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G27BJ05", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("JRZQ0A03", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
// 获取 code 字段
|
// 获取 code 字段
|
||||||
codeResult := gjson.GetBytes(resp, "code")
|
codeResult := gjson.GetBytes(resp, "code")
|
||||||
@@ -355,16 +360,18 @@ func (a *ApiRequestService) ProcessG26BJ05Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"name": name.String(),
|
||||||
"id": a.westDexService.Encrypt(idCard.String()),
|
"id_card": idCard.String(),
|
||||||
"name": a.westDexService.Encrypt(name.String()),
|
"mobile_no": mobile.String(),
|
||||||
"cell": a.westDexService.Encrypt(mobile.String()),
|
"time_range": "5",
|
||||||
"time_range": 5,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G26BJ05", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("G26BJ05", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
codeResult := gjson.GetBytes(resp, "code")
|
codeResult := gjson.GetBytes(resp, "code")
|
||||||
if !codeResult.Exists() {
|
if !codeResult.Exists() {
|
||||||
@@ -409,14 +416,16 @@ func (a *ApiRequestService) ProcessG34BJ03Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"id_card": idCard.String(),
|
||||||
"id_card": a.westDexService.Encrypt(idCard.String()),
|
"name": name.String(),
|
||||||
"name": a.westDexService.Encrypt(name.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G34BJ03", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("FLXG0V3B", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
dataResult := gjson.GetBytes(resp, "negative_info.data.risk_level")
|
dataResult := gjson.GetBytes(resp, "negative_info.data.risk_level")
|
||||||
if dataResult.Exists() {
|
if dataResult.Exists() {
|
||||||
@@ -443,15 +452,16 @@ func (a *ApiRequestService) ProcessG35SC01Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"id_card": idCard.String(),
|
||||||
"idcard": a.westDexService.Encrypt(idCard.String()),
|
"name": name.String(),
|
||||||
"name": a.westDexService.Encrypt(name.String()),
|
|
||||||
"inquired_auth": a.westDexService.GetDateRange(),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G35SC01", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("FLXGCA3D", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
// 第一步:提取外层的 data 字段
|
// 第一步:提取外层的 data 字段
|
||||||
dataResult := gjson.GetBytes(resp, "data")
|
dataResult := gjson.GetBytes(resp, "data")
|
||||||
@@ -501,15 +511,17 @@ func (a *ApiRequestService) ProcessG28BJ05Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"name": name.String(),
|
||||||
"id": a.westDexService.Encrypt(idCard.String()),
|
"id_card": idCard.String(),
|
||||||
"name": a.westDexService.Encrypt(name.String()),
|
"mobile_no": mobile.String(),
|
||||||
"cell": a.westDexService.Encrypt(mobile.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G28BJ05", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("JRZQ8203", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
// 获取 code 字段
|
// 获取 code 字段
|
||||||
codeResult := gjson.GetBytes(resp, "code")
|
codeResult := gjson.GetBytes(resp, "code")
|
||||||
@@ -592,17 +604,19 @@ func (a *ApiRequestService) ProcessQ23SC01Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"ent_code": entCode.String(),
|
||||||
"uscc": a.westDexService.Encrypt(entCode.String()),
|
"ent_name": entName.String(),
|
||||||
"org_name": a.westDexService.Encrypt(entName.String()),
|
"inquired_auth": a.westDexService.GetDateRange(),
|
||||||
"inquired_auth": a.westDexService.GetDateRange(),
|
}
|
||||||
},
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("QYGL8261", request)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("Q23SC01", request)
|
|
||||||
logx.Infof("企业涉诉返回%+v", string(resp))
|
logx.Infof("企业涉诉返回%+v", string(resp))
|
||||||
if callApiErr != nil {
|
|
||||||
return nil, callApiErr
|
|
||||||
}
|
|
||||||
// 第一步:提取外层的 data 字段
|
// 第一步:提取外层的 data 字段
|
||||||
dataResult := gjson.GetBytes(resp, "data")
|
dataResult := gjson.GetBytes(resp, "data")
|
||||||
if !dataResult.Exists() {
|
if !dataResult.Exists() {
|
||||||
@@ -652,15 +666,17 @@ func (a *ApiRequestService) ProcessG15BJ02Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"name": name.String(),
|
||||||
"name": a.westDexService.Encrypt(name.String()),
|
"id_card": idCard.String(),
|
||||||
"idNo": a.westDexService.Encrypt(idCard.String()),
|
"mobile_no": mobile.String(),
|
||||||
"phone": a.westDexService.Encrypt(mobile.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G15BJ02", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("YYSY6F2E", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
dataResult := gjson.GetBytes(resp, "data.code")
|
dataResult := gjson.GetBytes(resp, "data.code")
|
||||||
if !dataResult.Exists() {
|
if !dataResult.Exists() {
|
||||||
@@ -686,14 +702,16 @@ func (a *ApiRequestService) ProcessG17BJ02Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"name": name.String(),
|
||||||
"name": a.westDexService.Encrypt(name.String()),
|
"mobile_no": mobile.String(),
|
||||||
"phone": a.westDexService.Encrypt(mobile.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G17BJ02", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("YYSYBE08", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
dataResult := gjson.GetBytes(resp, "data.code")
|
dataResult := gjson.GetBytes(resp, "data.code")
|
||||||
if !dataResult.Exists() {
|
if !dataResult.Exists() {
|
||||||
@@ -719,14 +737,16 @@ func (a *ApiRequestService) ProcessG08SC02Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"name": name.String(),
|
||||||
"xm": a.westDexService.Encrypt(name.String()),
|
"id_card": idCard.String(),
|
||||||
"gmsfzhm": a.westDexService.Encrypt(idCard.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G08SC02", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("IVYZ385E", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
return &APIInternalResult{
|
return &APIInternalResult{
|
||||||
Data: resp,
|
Data: resp,
|
||||||
@@ -1081,42 +1101,57 @@ func (a *ApiRequestService) ProcessG10SC02Request(ctx context.Context, params []
|
|||||||
|
|
||||||
// 构造请求数据
|
// 构造请求数据
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"man_id_card": idCardMan.String(),
|
||||||
"certNumMan": a.westDexService.Encrypt(idCardMan.String()),
|
"man_name": nameMan.String(),
|
||||||
"nameMan": a.westDexService.Encrypt(nameMan.String()),
|
"woman_id_card": idCardWoman.String(),
|
||||||
"certNumWoman": a.westDexService.Encrypt(idCardWoman.String()),
|
"woman_name": nameWoman.String(),
|
||||||
"nameWoman": a.westDexService.Encrypt(nameWoman.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用 API
|
// 调用 API
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G10SC02", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("IVYZ9363", request)
|
||||||
if callApiErr != nil {
|
if err != nil && tianyuanapiResp == nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析响应数据
|
result := gjson.GetBytes(resp, "data.data")
|
||||||
code := gjson.GetBytes(resp, "code").String()
|
if !result.Exists() {
|
||||||
|
return nil, fmt.Errorf("婚姻状态查询失败")
|
||||||
// 状态码校验
|
|
||||||
if code != "200" {
|
|
||||||
return nil, fmt.Errorf("婚姻查询失败:%s", string(resp))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result := gjson.GetBytes(resp, "data.0.maritalStatus")
|
// 获取原始结果
|
||||||
|
rawResult := result.String()
|
||||||
|
|
||||||
if result.Exists() {
|
// 根据结果转换状态码
|
||||||
responseMap := map[string]string{"status": result.String()}
|
var statusCode string
|
||||||
jsonResponse, err := json.Marshal(responseMap)
|
switch {
|
||||||
if err != nil {
|
case strings.HasPrefix(rawResult, "INR"):
|
||||||
return nil, err
|
statusCode = "0" // 匹配不成功
|
||||||
}
|
case strings.HasPrefix(rawResult, "IA"):
|
||||||
return &APIInternalResult{
|
statusCode = "1" // 结婚
|
||||||
Data: jsonResponse,
|
case strings.HasPrefix(rawResult, "IB"):
|
||||||
}, nil
|
statusCode = "2" // 离婚
|
||||||
} else {
|
default:
|
||||||
return nil, errors.New("查询为空")
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 手机号码风险
|
// 手机号码风险
|
||||||
@@ -1128,13 +1163,15 @@ func (a *ApiRequestService) ProcessG03HZ01Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"mobile_no": mobile.String(),
|
||||||
"mobile": a.westDexService.Encrypt(mobile.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G03HZ01", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("FLXG54F5", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
// 获取 code 字段
|
// 获取 code 字段
|
||||||
codeResult := gjson.GetBytes(resp, "code")
|
codeResult := gjson.GetBytes(resp, "code")
|
||||||
@@ -1159,13 +1196,15 @@ func (a *ApiRequestService) ProcessG02BJ02Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"mobile_no": mobile.String(),
|
||||||
"phone": a.westDexService.Encrypt(mobile.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G02BJ02", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("YYSY4B37", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
// 获取 code 字段
|
// 获取 code 字段
|
||||||
codeResult := gjson.GetBytes(resp, "code")
|
codeResult := gjson.GetBytes(resp, "code")
|
||||||
@@ -1191,14 +1230,16 @@ func (a *ApiRequestService) ProcessG19BJ02Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"mobile_no": mobile.String(),
|
||||||
"phone": a.westDexService.Encrypt(mobile.String()),
|
"start_date": startDate.String(),
|
||||||
"startDate": startDate.String(),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G19BJ02", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("YYSYF7DB", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
// 获取 code 字段
|
// 获取 code 字段
|
||||||
codeResult := gjson.GetBytes(resp, "code")
|
codeResult := gjson.GetBytes(resp, "code")
|
||||||
@@ -1226,16 +1267,18 @@ func (a *ApiRequestService) ProcessG20GZ01Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"name": name.String(),
|
||||||
"name": a.westDexService.Encrypt(name.String()),
|
"id_card": idCard.String(),
|
||||||
"idcard": a.westDexService.Encrypt(idCard.String()),
|
"bank_card": bankCard.String(),
|
||||||
"acc_no": a.westDexService.Encrypt(bankCard.String()),
|
"mobile_no": mobile.String(),
|
||||||
"mobile": a.westDexService.Encrypt(mobile.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G20GZ01", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("JRZQDCBE", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
// 获取 code 字段
|
// 获取 code 字段
|
||||||
codeResult := gjson.GetBytes(resp, "code")
|
codeResult := gjson.GetBytes(resp, "code")
|
||||||
@@ -1248,7 +1291,7 @@ func (a *ApiRequestService) ProcessG20GZ01Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
// 解析 data.Raw 字符串为接口类型
|
// 解析 data.Raw 字符串为接口类型
|
||||||
var parsedData interface{}
|
var parsedData interface{}
|
||||||
err := json.Unmarshal([]byte(data.String()), &parsedData)
|
err = json.Unmarshal([]byte(data.String()), &parsedData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("解析 data 失败: %v", err)
|
return nil, fmt.Errorf("解析 data 失败: %v", err)
|
||||||
}
|
}
|
||||||
@@ -1274,29 +1317,21 @@ func (a *ApiRequestService) ProcessG37SC01Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"name": name.String(),
|
||||||
"name": a.westDexService.Encrypt(name.String()),
|
"id_card": idCard.String(),
|
||||||
"idcard": a.westDexService.Encrypt(idCard.String()),
|
|
||||||
"auth_authorizeFileCode": a.westDexService.Encrypt("CON0120250730743901"),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G37SC01", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("FLXG8A3F", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
}
|
}
|
||||||
parseResult, parseErr := lzUtils.ParseJsonResponse(resp)
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
if parseErr != nil {
|
if err != nil {
|
||||||
return nil, parseErr
|
return nil, err
|
||||||
}
|
|
||||||
// 通过gjson获取指定路径的数据
|
|
||||||
contentResult := gjson.GetBytes(parseResult, "G37SC0101.G37SC0102.content")
|
|
||||||
if contentResult.Exists() {
|
|
||||||
return &APIInternalResult{
|
|
||||||
Data: []byte(contentResult.Raw),
|
|
||||||
}, nil
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("找不到数据")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return &APIInternalResult{
|
||||||
|
Data: resp,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// G36SC01 自然人限高信息
|
// G36SC01 自然人限高信息
|
||||||
@@ -1309,29 +1344,21 @@ func (a *ApiRequestService) ProcessG36SC01Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"name": name.String(),
|
||||||
"name": a.westDexService.Encrypt(name.String()),
|
"id_card": idCard.String(),
|
||||||
"idcard": a.westDexService.Encrypt(idCard.String()),
|
|
||||||
"auth_authorizeFileCode": a.westDexService.Encrypt("CON0120250730743901"),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G36SC01", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("FLXG5B2E", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
}
|
}
|
||||||
parseResult, parseErr := lzUtils.ParseJsonResponse(resp)
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
if parseErr != nil {
|
if err != nil {
|
||||||
return nil, parseErr
|
return nil, err
|
||||||
}
|
|
||||||
// 通过gjson获取指定路径的数据
|
|
||||||
contentResult := gjson.GetBytes(parseResult, "G36SC0101.G36SC0102.content")
|
|
||||||
if contentResult.Exists() {
|
|
||||||
return &APIInternalResult{
|
|
||||||
Data: []byte(contentResult.Raw),
|
|
||||||
}, nil
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("找不到数据")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return &APIInternalResult{
|
||||||
|
Data: resp,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// G22SC01 自然人司法模型
|
// G22SC01 自然人司法模型
|
||||||
@@ -1344,32 +1371,21 @@ func (a *ApiRequestService) ProcessG22SC01Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"name": name.String(),
|
||||||
"name": a.westDexService.Encrypt(name.String()),
|
"id_card": idCard.String(),
|
||||||
"idcard": a.westDexService.Encrypt(idCard.String()),
|
|
||||||
"auth_authorizeFileCode": a.westDexService.Encrypt("CON0120250730743901"),
|
|
||||||
"inquired_auth": fmt.Sprintf("authed:%s", a.westDexService.GetDateRange()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
log.Printf("G22SC01 request: %+v", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("FLXG0V4B", request)
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G22SC01", request)
|
if err != nil {
|
||||||
if callApiErr != nil {
|
return nil, err
|
||||||
return nil, callApiErr
|
|
||||||
}
|
}
|
||||||
// 正常返回 - 不管有没有deps.Options.Json都进行ParseJsonResponse
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
parseResult, parseErr := lzUtils.ParseJsonResponse(resp)
|
if err != nil {
|
||||||
if parseErr != nil {
|
return nil, err
|
||||||
return nil, parseErr
|
|
||||||
}
|
|
||||||
// 通过gjson获取指定路径的数据
|
|
||||||
contentResult := gjson.GetBytes(parseResult, "G22SC0101.G22SC0102.content")
|
|
||||||
if contentResult.Exists() {
|
|
||||||
return &APIInternalResult{
|
|
||||||
Data: []byte(contentResult.Raw),
|
|
||||||
}, nil
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("找不到数据")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return &APIInternalResult{
|
||||||
|
Data: resp,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Q03SC01 企业涉诉信息
|
// Q03SC01 企业涉诉信息
|
||||||
@@ -1382,30 +1398,22 @@ func (a *ApiRequestService) ProcessQ03SC01Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"ent_code": entCode.String(),
|
||||||
"uscc": a.westDexService.Encrypt(entCode.String()),
|
"ent_name": entName.String(),
|
||||||
"org_name": a.westDexService.Encrypt(entName.String()),
|
"inquired_auth": fmt.Sprintf("authed:%s", a.westDexService.GetDateRange()),
|
||||||
"auth_authorizeFileCode": a.westDexService.Encrypt("CON0120250730743901"),
|
|
||||||
"inquired_auth": fmt.Sprintf("authed:%s", a.westDexService.GetDateRange()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("Q03SC01", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("QYGL8271", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
}
|
}
|
||||||
parseResult, parseErr := lzUtils.ParseJsonResponse(resp)
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
if parseErr != nil {
|
if err != nil {
|
||||||
return nil, parseErr
|
return nil, err
|
||||||
}
|
|
||||||
// 通过gjson获取指定路径的数据
|
|
||||||
contentResult := gjson.GetBytes(parseResult, "Q03SC0101.Q03SC0102.content")
|
|
||||||
if contentResult.Exists() {
|
|
||||||
return &APIInternalResult{
|
|
||||||
Data: []byte(contentResult.Raw),
|
|
||||||
}, nil
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("找不到数据")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return &APIInternalResult{
|
||||||
|
Data: resp,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 出境限制查询
|
// 出境限制查询
|
||||||
@@ -1729,16 +1737,17 @@ func (a *ApiRequestService) ProcessLayoutIdcardRequest(ctx context.Context, para
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"name": name.String(),
|
||||||
"xM": a.westDexService.Encrypt(name.String()),
|
"id_card": idCard.String(),
|
||||||
"gMSFZHM": a.westDexService.Encrypt(idCard.String()),
|
|
||||||
"customerNumber": a.config.WestConfig.SecretId,
|
|
||||||
"timeStamp": fmt.Sprintf("%d", time.Now().UnixNano()/int64(time.Millisecond)),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("layoutIdcard", request)
|
// 注意:layoutIdcard在api.json中没有对应的serviceId,需要根据实际情况调整
|
||||||
if callApiErr != nil {
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("YYSYBE08", request)
|
||||||
return nil, callApiErr
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
// 使用gjson获取resultCode
|
// 使用gjson获取resultCode
|
||||||
resultCode := gjson.GetBytes(resp, "ctidRequest.ctidAuth.resultCode")
|
resultCode := gjson.GetBytes(resp, "ctidRequest.ctidAuth.resultCode")
|
||||||
@@ -2222,15 +2231,17 @@ func (a *ApiRequestService) ProcessG30BJ05Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"name": name.String(),
|
||||||
"name": a.westDexService.Encrypt(name.String()),
|
"id_card": idCard.String(),
|
||||||
"id": a.westDexService.Encrypt(idCard.String()),
|
"mobile_no": Mobile.String(),
|
||||||
"cell": a.westDexService.Encrypt(Mobile.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G30BJ05", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("FLXGC9D1", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
fmt.Println(resp)
|
fmt.Println(resp)
|
||||||
flagBlackgraylevel := gjson.GetBytes(resp, "flag_blackgraylevel")
|
flagBlackgraylevel := gjson.GetBytes(resp, "flag_blackgraylevel")
|
||||||
@@ -2259,15 +2270,17 @@ func (a *ApiRequestService) ProcessG31BJ05Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"name": name.String(),
|
||||||
"name": a.westDexService.Encrypt(name.String()),
|
"id_card": idCard.String(),
|
||||||
"id": a.westDexService.Encrypt(idCard.String()),
|
"mobile_no": Mobile.String(),
|
||||||
"cell": a.westDexService.Encrypt(Mobile.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G31BJ05", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("FLXG9687", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
fmt.Println(resp)
|
fmt.Println(resp)
|
||||||
flagTelefraudpredictstd := gjson.GetBytes(resp, "flag_telefraudpredictstd")
|
flagTelefraudpredictstd := gjson.GetBytes(resp, "flag_telefraudpredictstd")
|
||||||
@@ -2296,15 +2309,17 @@ func (a *ApiRequestService) ProcessG32BJ05Request(ctx context.Context, params []
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"name": name.String(),
|
||||||
"name": a.westDexService.Encrypt(name.String()),
|
"id_card": idCard.String(),
|
||||||
"id": a.westDexService.Encrypt(idCard.String()),
|
"mobile_no": Mobile.String(),
|
||||||
"cell": a.westDexService.Encrypt(Mobile.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G32BJ05", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("FLXG162A", request)
|
||||||
if callApiErr != nil {
|
if err != nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
flagFraudrelation := gjson.GetBytes(resp, "flag_fraudrelation")
|
flagFraudrelation := gjson.GetBytes(resp, "flag_fraudrelation")
|
||||||
@@ -2342,16 +2357,19 @@ func (a *ApiRequestService) ProcessG09XM02Request(ctx context.Context, params []
|
|||||||
if !idCard.Exists() || !name.Exists() {
|
if !idCard.Exists() || !name.Exists() {
|
||||||
return nil, errors.New("api请求, G09XM02, 获取相关参数失败")
|
return nil, errors.New("api请求, G09XM02, 获取相关参数失败")
|
||||||
}
|
}
|
||||||
request := map[string]interface{}{
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("IVYZ5733", map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"id_card": idCard.String(),
|
||||||
"idCard": a.westDexService.Encrypt(idCard.String()),
|
"name": name.String(),
|
||||||
"name": a.westDexService.Encrypt(name.String()),
|
})
|
||||||
},
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
resp, err := a.westDexService.CallAPI("G09XM02", request)
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
if err != nil && resp == nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("婚姻状态查询失败: %v", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
result := gjson.GetBytes(resp, "data.data")
|
result := gjson.GetBytes(resp, "data.data")
|
||||||
if !result.Exists() {
|
if !result.Exists() {
|
||||||
return nil, fmt.Errorf("婚姻状态查询失败")
|
return nil, fmt.Errorf("婚姻状态查询失败")
|
||||||
@@ -2403,18 +2421,20 @@ func (a *ApiRequestService) ProcessG10XM02Request(ctx context.Context, params []
|
|||||||
|
|
||||||
// 构造请求数据
|
// 构造请求数据
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"man_id_card": idCardMan.String(),
|
||||||
"idCardMan": a.westDexService.Encrypt(idCardMan.String()),
|
"man_name": nameMan.String(),
|
||||||
"nameMan": a.westDexService.Encrypt(nameMan.String()),
|
"woman_id_card": idCardWoman.String(),
|
||||||
"idCardWoman": a.westDexService.Encrypt(idCardWoman.String()),
|
"woman_name": nameWoman.String(),
|
||||||
"nameWoman": a.westDexService.Encrypt(nameWoman.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用 API
|
// 调用 API
|
||||||
resp, callApiErr := a.westDexService.CallAPI("G10XM02", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("IVYZ9363", request)
|
||||||
if callApiErr != nil && resp == nil {
|
if err != nil && tianyuanapiResp == nil {
|
||||||
return nil, callApiErr
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
result := gjson.GetBytes(resp, "data.data")
|
result := gjson.GetBytes(resp, "data.data")
|
||||||
@@ -2460,15 +2480,17 @@ func (a *ApiRequestService) ProcessG11BJ06Request(ctx context.Context, params []
|
|||||||
return nil, errors.New("api请求, G11BJ06, 获取相关参数失败")
|
return nil, errors.New("api请求, G11BJ06, 获取相关参数失败")
|
||||||
}
|
}
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"id_card": name.String(),
|
||||||
"id_card_value": a.westDexService.Encrypt(idCard.String()),
|
"name": name.String(),
|
||||||
"name_value": a.westDexService.Encrypt(name.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, err := a.westDexService.CallAPI("G11BJ06", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("IVYZ9A2B", request)
|
||||||
if err != nil && resp == nil {
|
if err != nil && tianyuanapiResp == nil {
|
||||||
return nil, fmt.Errorf("教育经历核验查询失败: %v", err)
|
return nil, fmt.Errorf("教育经历核验查询失败: %v", err)
|
||||||
}
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// 解析响应
|
// 解析响应
|
||||||
codeResult := gjson.GetBytes(resp, "data.education_background.code")
|
codeResult := gjson.GetBytes(resp, "data.education_background.code")
|
||||||
@@ -2529,16 +2551,18 @@ func (a *ApiRequestService) ProcessG29BJ05Request(ctx context.Context, params []
|
|||||||
return nil, errors.New("api请求, G29BJ05, 获取相关参数失败")
|
return nil, errors.New("api请求, G29BJ05, 获取相关参数失败")
|
||||||
}
|
}
|
||||||
request := map[string]interface{}{
|
request := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"id_card": idCard.String(),
|
||||||
"id": a.westDexService.Encrypt(idCard.String()),
|
"name": name.String(),
|
||||||
"name": a.westDexService.Encrypt(name.String()),
|
"mobile_no": mobile.String(),
|
||||||
"cell": a.westDexService.Encrypt(mobile.String()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resp, err := a.westDexService.CallAPI("G29BJ05", request)
|
tianyuanapiResp, err := a.tianyuanapiService.CallInterface("JRZQ4AA8", request)
|
||||||
if err != nil && resp == nil {
|
if err != nil && tianyuanapiResp == nil {
|
||||||
return nil, fmt.Errorf("偿贷压力查询失败: %v", err)
|
return nil, fmt.Errorf("偿贷压力查询失败: %v", err)
|
||||||
}
|
}
|
||||||
|
resp, err := convertTianyuanResponse(tianyuanapiResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
// 获取响应码和偿贷压力标志
|
// 获取响应码和偿贷压力标志
|
||||||
code := gjson.GetBytes(resp, "code").String()
|
code := gjson.GetBytes(resp, "code").String()
|
||||||
flagDebtRepayStress := gjson.GetBytes(resp, "flag_debtrepaystress").String()
|
flagDebtRepayStress := gjson.GetBytes(resp, "flag_debtrepaystress").String()
|
||||||
@@ -2565,3 +2589,8 @@ func (a *ApiRequestService) ProcessG29BJ05Request(ctx context.Context, params []
|
|||||||
Data: jsonResult,
|
Data: jsonResult,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 辅助函数:将天远API响应转换为JSON字节数组
|
||||||
|
func convertTianyuanResponse(resp *tianyuanapi.Response) ([]byte, error) {
|
||||||
|
return json.Marshal(resp.Data)
|
||||||
|
}
|
||||||
|
|||||||
416
app/main/api/internal/service/tianyuanapi_sdk/client.go
Normal file
416
app/main/api/internal/service/tianyuanapi_sdk/client.go
Normal file
@@ -0,0 +1,416 @@
|
|||||||
|
package tianyuanapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/aes"
|
||||||
|
"crypto/cipher"
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// API调用相关错误类型
|
||||||
|
var (
|
||||||
|
ErrQueryEmpty = errors.New("查询为空")
|
||||||
|
ErrSystem = errors.New("接口异常")
|
||||||
|
ErrDecryptFail = errors.New("解密失败")
|
||||||
|
ErrRequestParam = errors.New("请求参数结构不正确")
|
||||||
|
ErrInvalidParam = errors.New("参数校验不正确")
|
||||||
|
ErrInvalidIP = errors.New("未经授权的IP")
|
||||||
|
ErrMissingAccessId = errors.New("缺少Access-Id")
|
||||||
|
ErrInvalidAccessId = errors.New("未经授权的AccessId")
|
||||||
|
ErrFrozenAccount = errors.New("账户已冻结")
|
||||||
|
ErrArrears = errors.New("账户余额不足,无法请求")
|
||||||
|
ErrProductNotFound = errors.New("产品不存在")
|
||||||
|
ErrProductDisabled = errors.New("产品已停用")
|
||||||
|
ErrNotSubscribed = errors.New("未订阅此产品")
|
||||||
|
ErrBusiness = errors.New("业务失败")
|
||||||
|
)
|
||||||
|
|
||||||
|
// 错误码映射 - 严格按照用户要求
|
||||||
|
var ErrorCodeMap = map[error]int{
|
||||||
|
ErrQueryEmpty: 1000,
|
||||||
|
ErrSystem: 1001,
|
||||||
|
ErrDecryptFail: 1002,
|
||||||
|
ErrRequestParam: 1003,
|
||||||
|
ErrInvalidParam: 1003,
|
||||||
|
ErrInvalidIP: 1004,
|
||||||
|
ErrMissingAccessId: 1005,
|
||||||
|
ErrInvalidAccessId: 1006,
|
||||||
|
ErrFrozenAccount: 1007,
|
||||||
|
ErrArrears: 1007,
|
||||||
|
ErrProductNotFound: 1008,
|
||||||
|
ErrProductDisabled: 1008,
|
||||||
|
ErrNotSubscribed: 1008,
|
||||||
|
ErrBusiness: 2001,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApiCallOptions API调用选项
|
||||||
|
type ApiCallOptions struct {
|
||||||
|
Json bool `json:"json,omitempty"` // 是否返回JSON格式
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client 天元API客户端
|
||||||
|
type Client struct {
|
||||||
|
accessID string
|
||||||
|
key string
|
||||||
|
baseURL string
|
||||||
|
timeout time.Duration
|
||||||
|
client *http.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config 客户端配置
|
||||||
|
type Config struct {
|
||||||
|
AccessID string // 访问ID
|
||||||
|
Key string // AES密钥(16进制)
|
||||||
|
BaseURL string // API基础URL
|
||||||
|
Timeout time.Duration // 超时时间
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request 请求参数
|
||||||
|
type Request struct {
|
||||||
|
InterfaceName string `json:"interfaceName"` // 接口名称
|
||||||
|
Params map[string]interface{} `json:"params"` // 请求参数
|
||||||
|
Timeout int `json:"timeout"` // 超时时间(毫秒)
|
||||||
|
Options *ApiCallOptions `json:"options"` // 调用选项
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApiResponse HTTP API响应
|
||||||
|
type ApiResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
TransactionID string `json:"transaction_id"` // 流水号
|
||||||
|
Data string `json:"data"` // 加密的数据
|
||||||
|
}
|
||||||
|
|
||||||
|
// Response Call方法的响应
|
||||||
|
type Response struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Success bool `json:"success"`
|
||||||
|
TransactionID string `json:"transaction_id"` // 流水号
|
||||||
|
Data map[string]interface{} `json:"data"` // 解密后的数据
|
||||||
|
Timeout int64 `json:"timeout"` // 请求耗时(毫秒)
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient 创建新的客户端实例
|
||||||
|
func NewClient(config Config) (*Client, error) {
|
||||||
|
// 参数校验
|
||||||
|
if config.AccessID == "" {
|
||||||
|
return nil, fmt.Errorf("accessID不能为空")
|
||||||
|
}
|
||||||
|
if config.Key == "" {
|
||||||
|
return nil, fmt.Errorf("key不能为空")
|
||||||
|
}
|
||||||
|
if config.BaseURL == "" {
|
||||||
|
config.BaseURL = "http://127.0.0.1:8080"
|
||||||
|
}
|
||||||
|
if config.Timeout == 0 {
|
||||||
|
config.Timeout = 60 * time.Second
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证密钥格式
|
||||||
|
if _, err := hex.DecodeString(config.Key); err != nil {
|
||||||
|
return nil, fmt.Errorf("无效的密钥格式,必须是16进制字符串: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Client{
|
||||||
|
accessID: config.AccessID,
|
||||||
|
key: config.Key,
|
||||||
|
baseURL: config.BaseURL,
|
||||||
|
timeout: config.Timeout,
|
||||||
|
client: &http.Client{
|
||||||
|
Timeout: config.Timeout,
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call 调用API接口
|
||||||
|
func (c *Client) Call(req Request) (*Response, error) {
|
||||||
|
startTime := time.Now()
|
||||||
|
|
||||||
|
// 参数校验
|
||||||
|
if err := c.validateRequest(req); err != nil {
|
||||||
|
return nil, fmt.Errorf("请求参数校验失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加密参数
|
||||||
|
jsonData, err := json.Marshal(req.Params)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("参数序列化失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
encryptedData, err := c.encrypt(string(jsonData))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("数据加密失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建请求体
|
||||||
|
requestBody := map[string]interface{}{
|
||||||
|
"data": encryptedData,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加选项
|
||||||
|
if req.Options != nil {
|
||||||
|
requestBody["options"] = req.Options
|
||||||
|
} else {
|
||||||
|
// 默认选项
|
||||||
|
defaultOptions := &ApiCallOptions{
|
||||||
|
Json: true,
|
||||||
|
}
|
||||||
|
requestBody["options"] = defaultOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
requestBodyBytes, err := json.Marshal(requestBody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("请求体序列化失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建HTTP请求
|
||||||
|
url := fmt.Sprintf("%s/api/v1/%s", c.baseURL, req.InterfaceName)
|
||||||
|
|
||||||
|
httpReq, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBodyBytes))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("创建HTTP请求失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置请求头
|
||||||
|
httpReq.Header.Set("Content-Type", "application/json")
|
||||||
|
httpReq.Header.Set("Access-Id", c.accessID)
|
||||||
|
httpReq.Header.Set("User-Agent", "TianyuanAPI-Go-SDK/1.0.0")
|
||||||
|
|
||||||
|
// 发送请求
|
||||||
|
resp, err := c.client.Do(httpReq)
|
||||||
|
if err != nil {
|
||||||
|
endTime := time.Now()
|
||||||
|
requestTime := endTime.Sub(startTime).Milliseconds()
|
||||||
|
return &Response{
|
||||||
|
Success: false,
|
||||||
|
Message: "请求失败",
|
||||||
|
Error: err.Error(),
|
||||||
|
Timeout: requestTime,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// 读取响应
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
endTime := time.Now()
|
||||||
|
requestTime := endTime.Sub(startTime).Milliseconds()
|
||||||
|
return &Response{
|
||||||
|
Success: false,
|
||||||
|
Message: "读取响应失败",
|
||||||
|
Error: err.Error(),
|
||||||
|
Timeout: requestTime,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析HTTP API响应
|
||||||
|
var apiResp ApiResponse
|
||||||
|
if err := json.Unmarshal(body, &apiResp); err != nil {
|
||||||
|
endTime := time.Now()
|
||||||
|
requestTime := endTime.Sub(startTime).Milliseconds()
|
||||||
|
return &Response{
|
||||||
|
Success: false,
|
||||||
|
Message: "响应解析失败",
|
||||||
|
Error: err.Error(),
|
||||||
|
Timeout: requestTime,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算请求耗时
|
||||||
|
endTime := time.Now()
|
||||||
|
requestTime := endTime.Sub(startTime).Milliseconds()
|
||||||
|
|
||||||
|
// 构建Call方法的响应
|
||||||
|
response := &Response{
|
||||||
|
Code: apiResp.Code,
|
||||||
|
Message: apiResp.Message,
|
||||||
|
Success: apiResp.Code == 0,
|
||||||
|
TransactionID: apiResp.TransactionID,
|
||||||
|
Timeout: requestTime,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果有加密数据,尝试解密
|
||||||
|
if apiResp.Data != "" {
|
||||||
|
decryptedData, err := c.decrypt(apiResp.Data)
|
||||||
|
if err == nil {
|
||||||
|
var decryptedMap map[string]interface{}
|
||||||
|
if json.Unmarshal([]byte(decryptedData), &decryptedMap) == nil {
|
||||||
|
response.Data = decryptedMap
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据响应码返回对应的错误
|
||||||
|
if apiResp.Code != 0 {
|
||||||
|
err := GetErrorByCode(apiResp.Code)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CallInterface 简化接口调用方法
|
||||||
|
func (c *Client) CallInterface(interfaceName string, params map[string]interface{}, options ...*ApiCallOptions) (*Response, error) {
|
||||||
|
var opts *ApiCallOptions
|
||||||
|
if len(options) > 0 {
|
||||||
|
opts = options[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
req := Request{
|
||||||
|
InterfaceName: interfaceName,
|
||||||
|
Params: params,
|
||||||
|
Timeout: 60000,
|
||||||
|
Options: opts,
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Call(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
// validateRequest 校验请求参数
|
||||||
|
func (c *Client) validateRequest(req Request) error {
|
||||||
|
if req.InterfaceName == "" {
|
||||||
|
return fmt.Errorf("interfaceName不能为空")
|
||||||
|
}
|
||||||
|
if req.Params == nil {
|
||||||
|
return fmt.Errorf("params不能为空")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// encrypt AES CBC加密
|
||||||
|
func (c *Client) encrypt(plainText string) (string, error) {
|
||||||
|
keyBytes, err := hex.DecodeString(c.key)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
block, err := aes.NewCipher(keyBytes)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成随机IV
|
||||||
|
iv := make([]byte, aes.BlockSize)
|
||||||
|
if _, err := io.ReadFull(rand.Reader, iv); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 填充数据
|
||||||
|
paddedData := c.pkcs7Pad([]byte(plainText), aes.BlockSize)
|
||||||
|
|
||||||
|
// 加密
|
||||||
|
ciphertext := make([]byte, len(iv)+len(paddedData))
|
||||||
|
copy(ciphertext, iv)
|
||||||
|
|
||||||
|
mode := cipher.NewCBCEncrypter(block, iv)
|
||||||
|
mode.CryptBlocks(ciphertext[len(iv):], paddedData)
|
||||||
|
|
||||||
|
return base64.StdEncoding.EncodeToString(ciphertext), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// decrypt AES CBC解密
|
||||||
|
func (c *Client) decrypt(encryptedText string) (string, error) {
|
||||||
|
keyBytes, err := hex.DecodeString(c.key)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
ciphertext, err := base64.StdEncoding.DecodeString(encryptedText)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
block, err := aes.NewCipher(keyBytes)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(ciphertext) < aes.BlockSize {
|
||||||
|
return "", fmt.Errorf("密文太短")
|
||||||
|
}
|
||||||
|
|
||||||
|
iv := ciphertext[:aes.BlockSize]
|
||||||
|
ciphertext = ciphertext[aes.BlockSize:]
|
||||||
|
|
||||||
|
if len(ciphertext)%aes.BlockSize != 0 {
|
||||||
|
return "", fmt.Errorf("密文长度不是块大小的倍数")
|
||||||
|
}
|
||||||
|
|
||||||
|
mode := cipher.NewCBCDecrypter(block, iv)
|
||||||
|
mode.CryptBlocks(ciphertext, ciphertext)
|
||||||
|
|
||||||
|
// 去除填充
|
||||||
|
unpaddedData, err := c.pkcs7Unpad(ciphertext)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(unpaddedData), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// pkcs7Pad PKCS7填充
|
||||||
|
func (c *Client) pkcs7Pad(data []byte, blockSize int) []byte {
|
||||||
|
padding := blockSize - len(data)%blockSize
|
||||||
|
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
|
||||||
|
return append(data, padtext...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// pkcs7Unpad PKCS7去除填充
|
||||||
|
func (c *Client) pkcs7Unpad(data []byte) ([]byte, error) {
|
||||||
|
length := len(data)
|
||||||
|
if length == 0 {
|
||||||
|
return nil, fmt.Errorf("数据为空")
|
||||||
|
}
|
||||||
|
unpadding := int(data[length-1])
|
||||||
|
if unpadding > length {
|
||||||
|
return nil, fmt.Errorf("无效的填充")
|
||||||
|
}
|
||||||
|
return data[:length-unpadding], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetErrorByCode 根据错误码获取错误
|
||||||
|
func GetErrorByCode(code int) error {
|
||||||
|
// 对于有多个错误对应同一错误码的情况,返回第一个
|
||||||
|
switch code {
|
||||||
|
case 1000:
|
||||||
|
return ErrQueryEmpty
|
||||||
|
case 1001:
|
||||||
|
return ErrSystem
|
||||||
|
case 1002:
|
||||||
|
return ErrDecryptFail
|
||||||
|
case 1003:
|
||||||
|
return ErrRequestParam
|
||||||
|
case 1004:
|
||||||
|
return ErrInvalidIP
|
||||||
|
case 1005:
|
||||||
|
return ErrMissingAccessId
|
||||||
|
case 1006:
|
||||||
|
return ErrInvalidAccessId
|
||||||
|
case 1007:
|
||||||
|
return ErrFrozenAccount
|
||||||
|
case 1008:
|
||||||
|
return ErrProductNotFound
|
||||||
|
case 2001:
|
||||||
|
return ErrBusiness
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("未知错误码: %d", code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCodeByError 根据错误获取错误码
|
||||||
|
func GetCodeByError(err error) int {
|
||||||
|
if code, exists := ErrorCodeMap[err]; exists {
|
||||||
|
return code
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
package svc
|
package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
"tyc-server/app/main/api/internal/config"
|
"tyc-server/app/main/api/internal/config"
|
||||||
"tyc-server/app/main/api/internal/middleware"
|
"tyc-server/app/main/api/internal/middleware"
|
||||||
"tyc-server/app/main/api/internal/service"
|
"tyc-server/app/main/api/internal/service"
|
||||||
|
tianyuanapi "tyc-server/app/main/api/internal/service/tianyuanapi_sdk"
|
||||||
"tyc-server/app/main/model"
|
"tyc-server/app/main/model"
|
||||||
|
|
||||||
"github.com/hibiken/asynq"
|
"github.com/hibiken/asynq"
|
||||||
@@ -26,6 +28,7 @@ type ServiceContext struct {
|
|||||||
WestDexService *service.WestDexService
|
WestDexService *service.WestDexService
|
||||||
YushanService *service.YushanService
|
YushanService *service.YushanService
|
||||||
TianjuService *service.TianjuService
|
TianjuService *service.TianjuService
|
||||||
|
TianyuanapiService *tianyuanapi.Client
|
||||||
ApiRequestService *service.ApiRequestService
|
ApiRequestService *service.ApiRequestService
|
||||||
AsynqServer *asynq.Server
|
AsynqServer *asynq.Server
|
||||||
AsynqService *service.AsynqService
|
AsynqService *service.AsynqService
|
||||||
@@ -139,6 +142,15 @@ func initBusinessServices(c config.Config, models *BaseModels, adminModels *Admi
|
|||||||
westDexService := service.NewWestDexService(c)
|
westDexService := service.NewWestDexService(c)
|
||||||
yushanService := service.NewYushanService(c)
|
yushanService := service.NewYushanService(c)
|
||||||
tianjuService := service.NewTianjuService(c)
|
tianjuService := service.NewTianjuService(c)
|
||||||
|
tianyuanapiService, err := tianyuanapi.NewClient(tianyuanapi.Config{
|
||||||
|
AccessID: c.Tianyuanapi.AccessID,
|
||||||
|
Key: c.Tianyuanapi.Key,
|
||||||
|
BaseURL: c.Tianyuanapi.BaseURL,
|
||||||
|
Timeout: time.Duration(c.Tianyuanapi.Timeout) * time.Second,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("初始化天远API失败: %+v", err)
|
||||||
|
}
|
||||||
asynqService := service.NewAsynqService(c)
|
asynqService := service.NewAsynqService(c)
|
||||||
|
|
||||||
// 初始化API请求服务
|
// 初始化API请求服务
|
||||||
@@ -147,6 +159,7 @@ func initBusinessServices(c config.Config, models *BaseModels, adminModels *Admi
|
|||||||
westDexService,
|
westDexService,
|
||||||
yushanService,
|
yushanService,
|
||||||
tianjuService,
|
tianjuService,
|
||||||
|
tianyuanapiService,
|
||||||
models.FeatureModel,
|
models.FeatureModel,
|
||||||
models.ProductFeatureModel,
|
models.ProductFeatureModel,
|
||||||
)
|
)
|
||||||
@@ -163,6 +176,7 @@ func initBusinessServices(c config.Config, models *BaseModels, adminModels *Admi
|
|||||||
WestDexService: westDexService,
|
WestDexService: westDexService,
|
||||||
YushanService: yushanService,
|
YushanService: yushanService,
|
||||||
TianjuService: tianjuService,
|
TianjuService: tianjuService,
|
||||||
|
TianyuanapiService: tianyuanapiService,
|
||||||
ApiRequestService: apiRequestService,
|
ApiRequestService: apiRequestService,
|
||||||
VerificationService: service.NewVerificationService(c, westDexService, apiRequestService),
|
VerificationService: service.NewVerificationService(c, westDexService, apiRequestService),
|
||||||
DictService: service.NewDictService(adminModels.AdminDictTypeModel, adminModels.AdminDictDataModel),
|
DictService: service.NewDictService(adminModels.AdminDictTypeModel, adminModels.AdminDictDataModel),
|
||||||
@@ -198,6 +212,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
WestDexService: businessServices.WestDexService,
|
WestDexService: businessServices.WestDexService,
|
||||||
YushanService: businessServices.YushanService,
|
YushanService: businessServices.YushanService,
|
||||||
TianjuService: businessServices.TianjuService,
|
TianjuService: businessServices.TianjuService,
|
||||||
|
TianyuanapiService: businessServices.TianyuanapiService,
|
||||||
ApiRequestService: businessServices.ApiRequestService,
|
ApiRequestService: businessServices.ApiRequestService,
|
||||||
AsynqService: businessServices.AsynqService,
|
AsynqService: businessServices.AsynqService,
|
||||||
VerificationService: businessServices.VerificationService,
|
VerificationService: businessServices.VerificationService,
|
||||||
@@ -277,6 +292,7 @@ type BusinessServices struct {
|
|||||||
WestDexService *service.WestDexService
|
WestDexService *service.WestDexService
|
||||||
YushanService *service.YushanService
|
YushanService *service.YushanService
|
||||||
TianjuService *service.TianjuService
|
TianjuService *service.TianjuService
|
||||||
|
TianyuanapiService *tianyuanapi.Client
|
||||||
ApiRequestService *service.ApiRequestService
|
ApiRequestService *service.ApiRequestService
|
||||||
AsynqService *service.AsynqService
|
AsynqService *service.AsynqService
|
||||||
VerificationService *service.VerificationService
|
VerificationService *service.VerificationService
|
||||||
|
|||||||
Reference in New Issue
Block a user