refactor(eggplant):重构卡密发送逻辑并更新测试配置

- 修改通道选择逻辑,根据 forwardUrl 动态判断目标域名- 替换 HTTP 客户端实现,从 beego/httplib 迁移至 resty- 支持多提交地址:djfkm.xyz 和 kmsfkm.xyz
- 更新 RSA 加密后数据的请求处理方式- 调整 JSON 解析方式,使用标准库替代框架内置方法
- 同步更新测试文件中的支付类型参数
- 修复 luban 渠道签名算法为大写 MD5
- 添加对特定域名 api.xxsbm.com 的特殊处理逻辑
This commit is contained in:
danial
2025-09-27 22:17:17 +08:00
parent 566e7386c0
commit 6a3e345c26
4 changed files with 26 additions and 20 deletions

View File

@@ -6,4 +6,4 @@ sbdAxf6Ad/pUm4E0zvzCuFf8wTZq4MBg32bSrMpsa7SibTxf92VGra6tTi3EwJDT
QQM/CnE9OK22vMQ2MDMTJPSuFm261Du55ylujQLRei19co+/oDtsytNr/5VYRi5o
qxZIamD1De5cJTcaXtioz3dXDELJ9PKuf+0AqqSyHvGCsobxI/8QUxAH9XKrx7RS
3QIDAQAB
-----END PUBLIC KEY-----
-----END PUBLIC KEY-----

View File

@@ -158,10 +158,12 @@ type eggplantProductCode struct {
func (c *eggplantProductCode) SendData(ctx context.Context, orderId string, forwardUrl *url.URL) (bool, string) {
// 通道1
channelOneCodeArray := []string{"8055"}
if slices.Contains(channelOneCodeArray, strutil.Trim(c.ProductCode)) {
if slices.ContainsFunc([]string{"kmsfkm.xyz", "djfkm.xyz"}, func(s string) bool {
return strings.Contains(forwardUrl.String(), s)
}) {
return c.channelOne(ctx, forwardUrl)
}
// 通道2
channelTwoCodeArray := []string{""}
if slices.Contains(channelTwoCodeArray, strutil.Trim(c.ProductCode)) {
@@ -192,17 +194,6 @@ func (c *eggplantProductCode) SendData(ctx context.Context, orderId string, forw
// 第一个通道
func (c *eggplantProductCode) channelOne(ctx context.Context, forwardUrl *url.URL) (bool, string) {
req := httplib.NewBeegoRequestWithCtx(ctx, "https://api.djfkm.xyz/api/order/shopSubCard", "POST").
SetTransport(otelhttp.NewTransport(http.DefaultTransport)).
SetTimeout(time.Second*5, time.Second*5).Retries(3).
SetProxy(func(req *http.Request) (*url.URL, error) {
proxy, err := utils.GetProxy(ctx, utils.GenerateId(), "eggplant_channel_one")
if err != nil || proxy == "" {
return nil, nil
}
return url.Parse(proxy)
})
jsonBody := struct {
OrderId string `json:"orderId"`
CardNo string `json:"cardNo"`
@@ -221,7 +212,19 @@ func (c *eggplantProductCode) channelOne(ctx context.Context, forwardUrl *url.UR
encrypted := cryptor.RsaEncrypt(jsonBo, "./data/pem/eggplant.pem")
jsonBody.Pass = base64.StdEncoding.EncodeToString(encrypted)
req, err = req.JSONBody(jsonBody)
webClient := resty.New().SetTimeout(time.Second * 5).SetRetryCount(3).OnBeforeRequest(func(c *resty.Client, request *resty.Request) error {
proxy, _ := utils.GetProxy(ctx, utils.GenerateId(), string(SendCardTaskTypeEnumEggplant+"channel_one"))
if proxy != "" {
c.SetProxy(proxy)
}
return nil
})
otelresty.TraceClient(webClient)
submitUrl := "https://api.djfkm.xyz/api/order/shopSubCard"
if strings.Contains(forwardUrl.String(), "kmsfkm.xyz") {
submitUrl = "https://admin.kmsfkm.xyz/api/order/shopSubCard"
}
response, err := webClient.R().SetBody(jsonBody).Post(submitUrl)
if err != nil {
otelTrace.Logger.WithContext(ctx).Error("json序列化失败", zap.Error(err))
return false, "内部数据处理失败"
@@ -231,8 +234,8 @@ func (c *eggplantProductCode) channelOne(ctx context.Context, forwardUrl *url.UR
Code int `json:"code"`
Msg string `json:"msg"`
}
err = req.ToJSON(&respData)
otelTrace.Logger.WithContext(ctx).Info("提交卡密接口", zap.Any("解析结果", respData), zap.Any("jsonBody", jsonBody))
otelTrace.Logger.WithContext(ctx).Info("提交卡密接口", zap.Any("解析结果", response.String()), zap.Any("jsonBody", jsonBody))
err = json.Unmarshal(response.Body(), &respData)
if err != nil {
otelTrace.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err))
return false, "内部数据处理失败"

View File

@@ -19,7 +19,7 @@ func TestSendCardTaskTypeEggplant_CreateOrder(t *testing.T) {
"order_no": utils.GenerateId(),
"client_ip": utils.GenerateIpv4(),
"amount": "10",
"pay_type": "8069",
"pay_type": "8055",
"notify_url": "https://baidu.com",
}
params["sign"] = eggService.sign(ctx, params, "2c5131ef1cbc3ba8d5b9267ab607d53b2c5131ef1cbc3ba8")

View File

@@ -155,7 +155,10 @@ func (s *SendCardTaskTypeLuban) HandleSendCardTask(ctx context.Context, orderIte
attribute.String("orderId", orderItem.OrderID),
))
defer span.End()
if strings.Contains(orderItem.PayURL, "api.xxsbm.com") {
err2 := (&SendCardTaskTypeFatSix{}).HandleSendCardTask(ctx, orderItem, task)
return err2
}
return s.channelOne(ctx, orderItem, task)
}
@@ -170,7 +173,7 @@ func (s *SendCardTaskTypeLuban) sign(ctx context.Context, params map[string]any,
signD += subKey + "=" + convertor.ToString(params[subKey]) + "&"
}
signD += "key=" + key
return strings.ToLower(utils.EncodeMd5Str(signD))
return strings.ToUpper(utils.EncodeMd5Str(signD))
}
func (s *SendCardTaskTypeLuban) QueryOrder(ctx context.Context, orderItem OrderPoolItem, task SendCardTask) error {