refactor(card_sender): 优化飞鱼卡片提交逻辑并新增测试用例
- 移除无用的依赖库和多余注释代码 - 统一请求头设置,改用 SetHeaders 方便管理 - 删除随机等待时间,改为等待距创建时间满 30 秒后再提交请求 - 新增 HandleSendCardTask 测试用例,涵盖代理池初始化和下单流程 - 更新代理配置,调整默认代理URL及认证信息 - 缩减代理池测试频道列表,简化测试逻辑并加入早期退出机制
This commit is contained in:
@@ -10,8 +10,8 @@ type ProxyInfo struct {
|
||||
|
||||
func GetProxyInfo() ProxyInfo {
|
||||
return ProxyInfo{
|
||||
Url: env.Get("proxyUrl", "https://share.proxy.qg.net/get?key=7ASQH2BI&num=2&area=&isp=0&format=txt&seq=\\n&distinct=false"),
|
||||
AuthKey: env.Get("proxyAuthKey", "7ASQH2BI"),
|
||||
AuthPwd: env.Get("proxyAuthPwd", "34D6652FE7B6"),
|
||||
Url: env.Get("proxyUrl", "https://share.proxy.qg.net/get?key=E4WS5YZV&num=1&area=&isp=0&format=txt&seq=\\n&distinct=true"),
|
||||
AuthKey: env.Get("proxyAuthKey", "E4WS5YZV"),
|
||||
AuthPwd: env.Get("proxyAuthPwd", "C474B2794C4E"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"gateway/internal/otelTrace"
|
||||
"gateway/internal/utils"
|
||||
"gateway/internal/utils/useragent"
|
||||
"github.com/duke-git/lancet/v2/random"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"sort"
|
||||
@@ -101,31 +100,13 @@ func (s *SendCardTaskTypeFlyFishV2) HandleSendCardTask(ctx context.Context, orde
|
||||
return errors.New("解析提交地址失败")
|
||||
}
|
||||
|
||||
//accept-language: zh-CN,zh;q=0.9
|
||||
//priority: u=1, i
|
||||
//sec-fetch-site: same-origin
|
||||
//origin: https://ccfy.cardpay.fyi
|
||||
//:scheme: https
|
||||
//accept-encoding: gzip, deflate, br, zstd
|
||||
//sec-fetch-dest: empty
|
||||
//sec-fetch-mode: cors
|
||||
//:authority: ccfy.cardpay.fyi
|
||||
//content-type: application/x-www-form-urlencoded; charset=UTF-8
|
||||
//accept: application/json, text/javascript, */*; q=0.01
|
||||
//x-requested-with: XMLHttpRequest
|
||||
//:method: POST
|
||||
//cookie: PHPSESSID=68991bd61ddf51fd31150fa9bfb27103
|
||||
//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
|
||||
//sec-ch-ua-mobile: ?0
|
||||
//content-length: 119
|
||||
//dnt: 1
|
||||
//:path: /submitcard
|
||||
//sec-ch-ua-platform: "macOS"
|
||||
//sec-ch-ua: "Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24"
|
||||
|
||||
// 使用 resty 发起请求
|
||||
webClient := resty.New().
|
||||
SetHeader("origin", "https://ccfy.cardpay.fyi").
|
||||
SetHeaders(map[string]string{
|
||||
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
"Accept": "application/json, text/javascript, */*; q=0.01",
|
||||
"user-agent": useragent.GetUserAgentByPlatform(useragent.PlatformPhone),
|
||||
}).
|
||||
SetHeader("user-agent", useragent.GetUserAgentByPlatform(useragent.PlatformPhone)).
|
||||
SetTimeout(time.Second * 30).OnBeforeRequest(func(client *resty.Client, request *resty.Request) error {
|
||||
proxy, err2 := utils.GetProxy(ctx, task.LocalOrderID, "SendCardTaskTypeFlyFishV2_cardTask")
|
||||
@@ -167,8 +148,9 @@ func (s *SendCardTaskTypeFlyFishV2) HandleSendCardTask(ctx context.Context, orde
|
||||
"productCode": productCode,
|
||||
}
|
||||
|
||||
time.Sleep(time.Second * time.Duration(random.RandInt(20, 40)))
|
||||
|
||||
if time.Now().Sub(orderItem.CreateTime) <= time.Second*30 {
|
||||
time.Sleep(time.Second*30 - time.Now().Sub(orderItem.CreateTime))
|
||||
}
|
||||
span.AddEvent("start submit data")
|
||||
resp, err := webClient.R().SetContext(ctx).SetFormData(formData).Post("https://ccfy.cardpay.fyi/submitcard")
|
||||
span.AddEvent("end submit data")
|
||||
|
||||
@@ -2,8 +2,14 @@ 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"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -36,5 +42,48 @@ func TestSendCardTaskTypeFlyFishV2_CreateOrder(t *testing.T) {
|
||||
otelTrace.Logger.WithContext(t.Context()).Info("飞鱼下单返回",
|
||||
zap.Any("respData", respData),
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
func TestSendCardTaskTypeFlyFishV2_HandleSendCardTask(t *testing.T) {
|
||||
// 初始化代理池
|
||||
if err := proxy.InitProxyPool(); err != nil {
|
||||
log.Printf("初始化代理池失败: %v", err)
|
||||
return
|
||||
}
|
||||
cache.Start()
|
||||
utils.StartProxyPool()
|
||||
formData := map[string]string{
|
||||
"orderId": utils.GenerateId(),
|
||||
"productCode": "8002",
|
||||
"amount": strconv.FormatFloat(10.0, 'f', 0, 64),
|
||||
"notify_url": "https://www.baidu.com",
|
||||
"batchno": utils.GenerateId(),
|
||||
"customerId": "8",
|
||||
"timestamp": strconv.FormatInt(time.Now().Unix(), 10),
|
||||
}
|
||||
formData["sign"] = (&SendCardTaskTypeFlyFishV2{}).sign(t.Context(), formData, "4n03qTCEDFO6XPKouoiRbqscfD36Sc")
|
||||
resp, _ := resty.New().SetHeader("Content-Type", "application/x-www-form-urlencoded").
|
||||
SetHeader("Accept", "application/json").R().SetFormData(formData).Post("https://apify.fkpay.online/submitPay.html")
|
||||
var respData struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data struct {
|
||||
Url string `json:"url"`
|
||||
} `json:"data"`
|
||||
}
|
||||
_ = json.Unmarshal(resp.Body(), &respData)
|
||||
otelTrace.Logger.WithContext(t.Context()).Info("飞鱼下单返回",
|
||||
zap.Any("respData", respData),
|
||||
)
|
||||
(&SendCardTaskTypeFlyFishV2{}).HandleSendCardTask(t.Context(), OrderPoolItem{
|
||||
PayURL: respData.Data.Url,
|
||||
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)),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,10 +9,12 @@ import (
|
||||
func TestGetProxy(t *testing.T) {
|
||||
cache.Start()
|
||||
StartProxyPool()
|
||||
channel := []string{"channel_four", "channel_five", "channel_six", "channel_seven", "channel_eight", "channel_nine", "channel_ten", "channel_eleven", "channel_twelve", "channel_thirteen", "channel_fourteen", "channel_fifteen", "channel_sixteen", "channel_seventeen", "channel_eighteen", "channel_nineteen", "channel_twenty"}
|
||||
channel := []string{"channel_four", "channel_five"}
|
||||
//channel := []string{"channel_four", "channel_five", "channel_six", "channel_seven", "channel_eight", "channel_nine", "channel_ten", "channel_eleven", "channel_twelve", "channel_thirteen", "channel_fourteen", "channel_fifteen", "channel_sixteen", "channel_seventeen", "channel_eighteen", "channel_nineteen", "channel_twenty"}
|
||||
for _, c := range channel {
|
||||
proxy, _ := GetProxy(t.Context(), GenerateId(), c)
|
||||
proxy, _ := GetProxy(t.Context(), "12345", "234546")
|
||||
resp, err := resty.New().SetProxy(proxy).R().Get("https://www.qq.com")
|
||||
t.Log(resp.StatusCode(), c, err)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user