fix
This commit is contained in:
parent
2943bf0320
commit
ef286a2466
@ -1,11 +1,9 @@
|
||||
package COMB
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"tianyuan-api/apps/api/internal/common"
|
||||
@ -182,48 +180,26 @@ func (l *COMB298YLogic) COMB298Y(req *types.Request) (resp string, err *errs.App
|
||||
// 4、发送请求到西部
|
||||
logx.Infof("交易号:%s", transactionID)
|
||||
var respData []byte
|
||||
var err error
|
||||
if req.SourceId == "G05HZ01" {
|
||||
respData, err = l.svcCtx.WestDexService.CallAPISecond(req.SourceId, req.Request, l.svcCtx.Config.WestConfig.SecretSecondId)
|
||||
respData, callAPIErr = l.svcCtx.WestDexService.CallAPISecond(req.SourceId, req.Request, l.svcCtx.Config.WestConfig.SecretSecondId)
|
||||
} else {
|
||||
respData, err = l.svcCtx.WestDexService.CallAPI(req.SourceId, req.Request, l.svcCtx.Config.WestConfig.SecretId)
|
||||
respData, callAPIErr = l.svcCtx.WestDexService.CallAPI(req.SourceId, req.Request, l.svcCtx.Config.WestConfig.SecretId)
|
||||
}
|
||||
if err != nil {
|
||||
// 尝试解析响应数据
|
||||
var respStr string
|
||||
if len(respData) > 0 {
|
||||
// 先尝试解析为 JSON
|
||||
var prettyJSON bytes.Buffer
|
||||
if err := json.Indent(&prettyJSON, respData, "", " "); err == nil {
|
||||
respStr = prettyJSON.String()
|
||||
if callAPIErr != nil {
|
||||
if callAPIErr.Code == errs.ErrDataSource.Code {
|
||||
// 数据源错误(如查询无结果)是业务正常情况,记录为 info
|
||||
logx.Infof("西部请求业务状态:sourceId:%s, resp:%v", req.SourceId, respData)
|
||||
var jsonCheck interface{}
|
||||
if json.Unmarshal(respData, &jsonCheck) != nil {
|
||||
westResp = "{}"
|
||||
} else {
|
||||
// 如果不是 JSON,检查是否是字符串形式的数组
|
||||
strData := string(respData)
|
||||
if strings.HasPrefix(strData, "[") && strings.HasSuffix(strData, "]") {
|
||||
// 尝试解析为数组
|
||||
var arr []int
|
||||
if err := json.Unmarshal(respData, &arr); err == nil {
|
||||
// 如果是数字数组,转换为字符串
|
||||
var sb strings.Builder
|
||||
for _, v := range arr {
|
||||
sb.WriteByte(byte(v))
|
||||
}
|
||||
respStr = sb.String()
|
||||
} else {
|
||||
respStr = strData
|
||||
westResp = string(respData)
|
||||
}
|
||||
} else {
|
||||
respStr = strData
|
||||
// 其他业务错误
|
||||
logx.Errorf("西部请求业务错误:sourceId:%s,err:%v, resp:%v", req.SourceId, callAPIErr, respData)
|
||||
westResp = "{}"
|
||||
}
|
||||
}
|
||||
}
|
||||
logx.Errorf("西部请求失败:sourceId:%s,err:%v, resp:%s", req.SourceId, err, respStr)
|
||||
if appErr, ok := err.(*errs.AppError); ok {
|
||||
callAPIErr = appErr
|
||||
} else {
|
||||
callAPIErr = errs.ErrSystem
|
||||
}
|
||||
westResp = "{}" // 发生错误时返回空对象
|
||||
} else {
|
||||
// 确保返回的是有效的 JSON
|
||||
if len(respData) == 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user