This commit is contained in:
2024-10-12 20:41:55 +08:00
parent 8c09120db6
commit 597e4f1b89
75 changed files with 5009 additions and 823 deletions

View File

@@ -0,0 +1,41 @@
package service
import (
"context"
"encoding/json"
"github.com/zeromicro/go-queue/kq"
"tianyuan-api/pkg/models"
"time"
)
type ApiRequestMqsService struct {
KqPusherClient *kq.Pusher
}
// NewApiRequestMqsService
func NewApiRequestMqsService(KqPusherClient *kq.Pusher) *ApiRequestMqsService {
return &ApiRequestMqsService{
KqPusherClient: KqPusherClient,
}
}
func (s *ApiRequestMqsService) SendApiRequestMessage(ctx context.Context, transactionID string, userId int64, productCode string, status string, charges bool, remark string) error {
message := models.ApiRequestMessage{
TransactionID: transactionID,
UserId: userId,
ProductCode: productCode,
Status: status,
Charges: charges,
Remark: remark,
Timestamp: time.Now(),
}
msgBytes, marshalErr := json.Marshal(message)
if marshalErr != nil {
return marshalErr
}
if pushErr := s.KqPusherClient.Push(ctx, string(msgBytes)); pushErr != nil {
return pushErr
}
return nil
}

View File

@@ -44,11 +44,7 @@ func (w *WestDexService) CallAPI(code string, reqData map[string]interface{}) (r
// 构造请求URL
reqUrl := fmt.Sprintf("%s/%s/%s?timestamp=%s", w.config.Url, w.config.SecretId, code, timestamp)
// 将请求参数编码为JSON格式
data := map[string]interface{}{
"data": reqData,
}
jsonData, err := json.Marshal(data)
jsonData, err := json.Marshal(reqData)
if err != nil {
logx.Errorf("【西部数据请求】JSON编码错误: %v", err)
return
@@ -94,7 +90,7 @@ func (w *WestDexService) CallAPI(code string, reqData map[string]interface{}) (r
logx.Errorf("【西部数据请求】JSON反序列化错误: %v", UnmarshalErr)
return nil, UnmarshalErr
}
logx.Infof("西部流水号: %s", westDexResp.ID)
// 到这层是西部系统
if westDexResp.Code != "00000" {
logx.Errorf("【西部数据请求】响应数据业务异常: %s %s", westDexResp.Message, westDexResp.Reason)