股东人企关系精准版Logic修正
This commit is contained in:
parent
5a2b470bf8
commit
6c0dfb2b23
@ -94,7 +94,7 @@ func (l *QYGLB4C0Logic) QYGLB4C0(req *types.Request) (resp string, err *errs.App
|
||||
logx.Infof("交易号:%s", transactionID)
|
||||
apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.QYGLB4C0FieldMapping, "")
|
||||
|
||||
westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G05HZ01", apiRequest, l.svcCtx.Config.WestConfig.SecretSecondId)
|
||||
westResp, callAPIErr := l.svcCtx.WestDexService.CallAPISecond("G05HZ01", apiRequest, l.svcCtx.Config.WestConfig.SecretSecondId)
|
||||
if callAPIErr != nil {
|
||||
if callAPIErr.Code == errs.ErrDataSource.Code {
|
||||
encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key)
|
||||
|
@ -25,6 +25,14 @@ type WestResp struct {
|
||||
ErrorCode *int `json:"error_code"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
type WestSecondResp struct {
|
||||
Message string `json:"message"`
|
||||
Code string `json:"code"`
|
||||
Data json.RawMessage `json:"data"`
|
||||
ID string `json:"id"`
|
||||
ErrorCode *int `json:"error_code"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
type WestDexService struct {
|
||||
config config.WestConfig
|
||||
}
|
||||
@ -130,3 +138,88 @@ func (w *WestDexService) CallAPI(code string, reqData map[string]interface{}, se
|
||||
logx.Errorf("【西部数据请求】请求失败,状态码: %d", httpResp.StatusCode)
|
||||
return nil, errs.ErrSystem
|
||||
}
|
||||
|
||||
// CallAPI 调用西部数据的 API
|
||||
func (w *WestDexService) CallAPISecond(code string, reqData map[string]interface{}, secretId string) (resp []byte, err *errs.AppError) {
|
||||
logx.Infof("西部请求传入%v", reqData)
|
||||
// 生成当前的13位时间戳
|
||||
timestamp := strconv.FormatInt(time.Now().UnixNano()/int64(time.Millisecond), 10)
|
||||
|
||||
// 构造请求URL
|
||||
reqUrl := fmt.Sprintf("%s/%s/%s?timestamp=%s", w.config.Url, secretId, code, timestamp)
|
||||
|
||||
jsonData, marshalErr := json.Marshal(reqData)
|
||||
if marshalErr != nil {
|
||||
logx.Errorf("【西部数据请求】JSON编码错误: %v", marshalErr)
|
||||
return nil, errs.ErrSystem
|
||||
}
|
||||
|
||||
// 创建HTTP POST请求
|
||||
req, newRequestErr := http.NewRequest("POST", reqUrl, bytes.NewBuffer(jsonData))
|
||||
if newRequestErr != nil {
|
||||
logx.Errorf("【西部数据请求】创建请求错误: %v", newRequestErr)
|
||||
return nil, errs.ErrSystem
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// 发送请求
|
||||
client := &http.Client{}
|
||||
httpResp, clientDoErr := client.Do(req)
|
||||
if clientDoErr != nil {
|
||||
logx.Errorf("【西部数据请求】发送请求错误: %v", clientDoErr)
|
||||
return nil, errs.ErrSystem
|
||||
}
|
||||
defer func(Body io.ReadCloser) {
|
||||
closeErr := Body.Close()
|
||||
if closeErr != nil {
|
||||
|
||||
}
|
||||
}(httpResp.Body)
|
||||
|
||||
// 检查请求是否成功
|
||||
if httpResp.StatusCode == 200 {
|
||||
// 读取响应体
|
||||
bodyBytes, ReadErr := io.ReadAll(httpResp.Body)
|
||||
if ReadErr != nil {
|
||||
logx.Errorf("【西部数据请求】读取响应体错误: %v", ReadErr)
|
||||
return nil, errs.ErrSystem
|
||||
}
|
||||
|
||||
// 手动调用 json.Unmarshal 触发自定义的 UnmarshalJSON 方法
|
||||
var westDexResp WestSecondResp
|
||||
UnmarshalErr := json.Unmarshal(bodyBytes, &westDexResp)
|
||||
if UnmarshalErr != nil {
|
||||
logx.Errorf("【西部数据请求】JSON反序列化错误: %v", UnmarshalErr)
|
||||
return nil, errs.ErrSystem
|
||||
}
|
||||
logx.Infof("西部请求响应%+v", westDexResp)
|
||||
|
||||
logx.Infof("西部流水号: %s", westDexResp.ID)
|
||||
|
||||
if westDexResp.Code != "0000" {
|
||||
if westDexResp.Code == "-1" {
|
||||
if westDexResp.Data == nil {
|
||||
logx.Errorf("【西部数据请求】业务失败时响应数据为空: %s %s", westDexResp.Message, westDexResp.Reason)
|
||||
return nil, errs.ErrSystem
|
||||
}
|
||||
logx.Errorf("【西部数据请求】响应数据业务异常: %s %s %s", westDexResp.Message, westDexResp.Reason, string(westDexResp.Data))
|
||||
return westDexResp.Data, errs.ErrDataSource
|
||||
} else {
|
||||
logx.Errorf("【西部数据请求】响应数据异常: %s %s", westDexResp.Message, westDexResp.Reason)
|
||||
return nil, errs.ErrSystem
|
||||
}
|
||||
}
|
||||
if westDexResp.Data == nil {
|
||||
logx.Errorf("【西部数据请求】响应Data字段数据为空")
|
||||
return nil, errs.ErrSystem
|
||||
}
|
||||
|
||||
// 输出解密后的数据
|
||||
return westDexResp.Data, nil
|
||||
}
|
||||
|
||||
logx.Errorf("【西部数据请求】请求失败,状态码: %d", httpResp.StatusCode)
|
||||
return nil, errs.ErrSystem
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user