fix(card_sender): 优化飞鱼卡密重新下单逻辑及日志输出
- 修改请求提交失败错误信息为“重新下单提交卡密” - 在日志中增加解析后的响应数据打印 - 新增对“请勿重复提交卡号”提示的处理,避免重复提交错误 - 保持“频繁操作”错误时返回重新下单错误提示
This commit is contained in:
@@ -20,6 +20,7 @@ var mustSampled = []string{
|
||||
"HandleSendCardTask",
|
||||
"SubmitOrder",
|
||||
"SubmitPool",
|
||||
"OrderSchedule",
|
||||
}
|
||||
|
||||
// SamplingPriority 强制采样
|
||||
|
||||
@@ -146,14 +146,42 @@ func (s *SendCardTaskTypeLuban) channelTwo(ctx context.Context, orderItem OrderP
|
||||
return errors.New("解析URL失败")
|
||||
}
|
||||
orderUrl := fmt.Sprintf("https://abc.pvcrr.com/baolingqiu/tdeal_order/postCardAndSecret")
|
||||
params := map[string]any{
|
||||
"tradeNo": query.Query().Get("tradeNo"),
|
||||
"sign": query.Query().Get("sign"),
|
||||
"card_no": task.CardInfo.CardNo,
|
||||
"card_pwd": task.CardInfo.Data,
|
||||
time.Sleep(time.Second * 30)
|
||||
|
||||
// 使用有序结构体保证 JSON 序列化的字段顺序
|
||||
params := struct {
|
||||
TradeNo string `json:"tradeNo"`
|
||||
Sign string `json:"sign"`
|
||||
CardNo string `json:"card_no"`
|
||||
CardPwd string `json:"card_pwd"`
|
||||
}{
|
||||
TradeNo: query.Query().Get("tradeNo"),
|
||||
Sign: query.Query().Get("sign"),
|
||||
CardNo: task.CardInfo.CardNo,
|
||||
CardPwd: task.CardInfo.Data,
|
||||
}
|
||||
jsonBody, _ := json.Marshal(params)
|
||||
client := resty.New().SetTimeout(time.Second * 5).SetTimeout(time.Second * 5).OnBeforeRequest(func(client *resty.Client, request *resty.Request) error {
|
||||
|
||||
client := resty.New().SetTimeout(time.Second * 5).SetRetryCount(0).SetHeaders(map[string]string{
|
||||
"Accept": "application/json, text/javascript, */*; q=0.01",
|
||||
"Accept-Language": "zh-CN,zh;q=0.9",
|
||||
"Accept-Encoding": "gzip, deflate, br",
|
||||
"Cache-Control": "no-cache",
|
||||
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
"DNT": "1",
|
||||
"Origin": "https://abc.pvcrr.com",
|
||||
"Pragma": "no-cache",
|
||||
"Referer": orderItem.PayURL,
|
||||
"Sec-Fetch-Dest": "empty",
|
||||
"Sec-Fetch-Mode": "cors",
|
||||
"Sec-Fetch-Site": "same-origin",
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36",
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
"sec-ch-ua": "\"Google Chrome\";v=\"143\", \"Chromium\";v=\"143\", \"Not A(Brand\";v=\"24\"",
|
||||
"sec-ch-ua-mobile": "?0",
|
||||
"sec-ch-ua-platform": "\"macOS\"",
|
||||
"Connection": "keep-alive",
|
||||
}).OnBeforeRequest(func(client *resty.Client, request *resty.Request) error {
|
||||
proxy, _ := utils.GetProxy(ctx, utils.GenerateId(), string(SendCardTaskTypeEnumLuban+"channelTwo"))
|
||||
if proxy != "" {
|
||||
client.SetProxy(proxy)
|
||||
@@ -161,6 +189,10 @@ func (s *SendCardTaskTypeLuban) channelTwo(ctx context.Context, orderItem OrderP
|
||||
return nil
|
||||
})
|
||||
otelresty.TraceClient(client)
|
||||
_, _ = client.R().SetContext(ctx).Get(orderItem.PayURL)
|
||||
|
||||
time.Sleep(time.Second * 30)
|
||||
|
||||
response, err := client.R().SetContext(ctx).SetQueryParams(map[string]string{
|
||||
"json": string(jsonBody),
|
||||
}).Get(orderUrl)
|
||||
@@ -169,7 +201,7 @@ func (s *SendCardTaskTypeLuban) channelTwo(ctx context.Context, orderItem OrderP
|
||||
return errors.New("请求失败")
|
||||
}
|
||||
|
||||
otelTrace.Logger.WithContext(ctx).Info("回调", zap.String("response", response.String()), zap.Any("params", params), zap.String("orderUrl", orderUrl))
|
||||
otelTrace.Logger.WithContext(ctx).Info("回调", zap.String("response", response.String()), zap.Any("params", params))
|
||||
|
||||
submitData := struct {
|
||||
Code int64 `json:"code"`
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
package card_sender
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gateway/internal/cache"
|
||||
"gateway/internal/otelTrace"
|
||||
"gateway/internal/proxy"
|
||||
"gateway/internal/service/supplier"
|
||||
"gateway/internal/utils"
|
||||
"github.com/duke-git/lancet/v2/random"
|
||||
"log"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -13,6 +20,13 @@ import (
|
||||
)
|
||||
|
||||
func TestSendCardTaskTypeLuban_CreateOrder(t *testing.T) {
|
||||
// 初始化代理池
|
||||
if err := proxy.InitProxyPool(); err != nil {
|
||||
log.Printf("初始化代理池失败: %v", err)
|
||||
return
|
||||
}
|
||||
cache.Start()
|
||||
utils.StartProxyPool()
|
||||
webClient := resty.New().SetTimeout(time.Second * 5).SetRetryCount(3)
|
||||
otelresty.TraceClient(webClient)
|
||||
|
||||
@@ -37,4 +51,26 @@ func TestSendCardTaskTypeLuban_CreateOrder(t *testing.T) {
|
||||
}
|
||||
response, _ := webClient.R().SetFormData(paramsStr).Post("http://jiuzpay.xyz:56700/api/pay/create_order")
|
||||
otelTrace.Logger.WithContext(t.Context()).Info("请求结果", zap.String("response", response.String()), zap.Any("params", params))
|
||||
responseStruct := struct {
|
||||
RetCode string `json:"retCode"`
|
||||
PayUrl string `json:"payUrl"`
|
||||
}{}
|
||||
|
||||
if err := json.Unmarshal(response.Body(), &responseStruct); err != nil {
|
||||
otelTrace.Logger.WithContext(t.Context()).Error("转换返回值失败", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
err := (&SendCardTaskTypeLuban{}).HandleSendCardTask(t.Context(), OrderPoolItem{
|
||||
PayURL: responseStruct.PayUrl,
|
||||
OrderID: utils.GenerateId(),
|
||||
CreateTime: time.Now(),
|
||||
}, SendCardTask{
|
||||
LocalOrderID: utils.GenerateId(),
|
||||
CardInfo: supplier.RedeemCardInfo{
|
||||
CardNo: "24032515" + fmt.Sprintf("%08d", random.RandInt(10000000, 99999999)),
|
||||
Data: "23611016" + fmt.Sprintf("%08d", random.RandInt(10000000, 99999999)),
|
||||
},
|
||||
})
|
||||
t.Log(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user