From 6a3e345c26c6d91eccf8753c933256341f9b63a6 Mon Sep 17 00:00:00 2001 From: danial Date: Sat, 27 Sep 2025 22:17:17 +0800 Subject: [PATCH] =?UTF-8?q?refactor(eggplant):=E9=87=8D=E6=9E=84=E5=8D=A1?= =?UTF-8?q?=E5=AF=86=E5=8F=91=E9=80=81=E9=80=BB=E8=BE=91=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=B5=8B=E8=AF=95=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改通道选择逻辑,根据 forwardUrl 动态判断目标域名- 替换 HTTP 客户端实现,从 beego/httplib 迁移至 resty- 支持多提交地址:djfkm.xyz 和 kmsfkm.xyz - 更新 RSA 加密后数据的请求处理方式- 调整 JSON 解析方式,使用标准库替代框架内置方法 - 同步更新测试文件中的支付类型参数 - 修复 luban 渠道签名算法为大写 MD5 - 添加对特定域名 api.xxsbm.com 的特殊处理逻辑 --- data/pem/eggplant.pem | 2 +- .../third_party/pool/card_sender/eggplant.go | 35 ++++++++++--------- .../pool/card_sender/eggplant_test.go | 2 +- .../third_party/pool/card_sender/luban.go | 7 ++-- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/data/pem/eggplant.pem b/data/pem/eggplant.pem index b3df058..8c2e509 100644 --- a/data/pem/eggplant.pem +++ b/data/pem/eggplant.pem @@ -6,4 +6,4 @@ sbdAxf6Ad/pUm4E0zvzCuFf8wTZq4MBg32bSrMpsa7SibTxf92VGra6tTi3EwJDT QQM/CnE9OK22vMQ2MDMTJPSuFm261Du55ylujQLRei19co+/oDtsytNr/5VYRi5o qxZIamD1De5cJTcaXtioz3dXDELJ9PKuf+0AqqSyHvGCsobxI/8QUxAH9XKrx7RS 3QIDAQAB ------END PUBLIC KEY----- \ No newline at end of file +-----END PUBLIC KEY----- diff --git a/internal/service/supplier/third_party/pool/card_sender/eggplant.go b/internal/service/supplier/third_party/pool/card_sender/eggplant.go index 0537aac..3f93191 100644 --- a/internal/service/supplier/third_party/pool/card_sender/eggplant.go +++ b/internal/service/supplier/third_party/pool/card_sender/eggplant.go @@ -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, "内部数据处理失败" diff --git a/internal/service/supplier/third_party/pool/card_sender/eggplant_test.go b/internal/service/supplier/third_party/pool/card_sender/eggplant_test.go index f46d9f5..04db0d8 100644 --- a/internal/service/supplier/third_party/pool/card_sender/eggplant_test.go +++ b/internal/service/supplier/third_party/pool/card_sender/eggplant_test.go @@ -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") diff --git a/internal/service/supplier/third_party/pool/card_sender/luban.go b/internal/service/supplier/third_party/pool/card_sender/luban.go index fd1c662..f6dbe5a 100644 --- a/internal/service/supplier/third_party/pool/card_sender/luban.go +++ b/internal/service/supplier/third_party/pool/card_sender/luban.go @@ -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 {