mirror of
https://git.oceanpay.cc/danial/kami_scripts.git
synced 2025-12-18 22:47:10 +00:00
- 更新 .gitignore 文件,添加日志和IDE相关目录 - 修改 config.yaml,更新提交URL和商户配置- 在 interfaces.go 中添加新方法并修改现有方法 - 优化 logger_adapter.go 中的日志记录功能 - 调整 main.go 中的定时任务间隔 - 在 order.go 中实现新的 FindRandomFailedOrders 方法 - 更新 order_service.go,添加 CSV 文件处理逻辑 - 新增 road.go 文件,实现 FindRoadByRoadUid 方法 - 修改 submit_order.go,更新订单提交逻辑
72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"order/internal/interfaces"
|
|
"order/internal/model"
|
|
"order/internal/utils"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/beego/beego/v2/client/httplib"
|
|
)
|
|
|
|
// MockOrderSender 模拟订单发送器
|
|
type MockOrderSender struct {
|
|
logger interfaces.Logger
|
|
}
|
|
|
|
func NewMockOrderSender(logger interfaces.Logger) interfaces.OrderSender {
|
|
return &MockOrderSender{logger: logger}
|
|
}
|
|
|
|
func (s *MockOrderSender) Send(ctx context.Context, order *model.OrderInfo, merchant *model.MerchantInfo, roadInfo *model.RoadInfo, submitURL string) error {
|
|
// 这里实现实际的订单发送逻辑
|
|
s.logger.Info("发送订单",
|
|
"order_no", order.BankOrderID,
|
|
"amount", order.OrderAmount,
|
|
)
|
|
if _, err := submitOrder(ctx, &SubmitOrder{
|
|
OrderPeriod: 1,
|
|
NotifyUrl: "https://www.baidu.com",
|
|
OrderPrice: strconv.FormatFloat(order.OrderAmount, 'f', -1, 64),
|
|
OrderNo: order.BankOrderID,
|
|
ProductCode: roadInfo.ProductCode,
|
|
ExValue: order.ExValue,
|
|
Ip: "127.0.0.1",
|
|
PayKey: merchant.MerchantKey,
|
|
PaySecret: merchant.MerchantSecret,
|
|
}, submitURL); err != nil {
|
|
s.logger.Error("提交订单失败", "error", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func submitOrder(ctx context.Context, input *SubmitOrder, submitURL string) (*SubmitOrderResponse, error) {
|
|
req := httplib.NewBeegoRequestWithCtx(ctx, fmt.Sprintf("%s/gateway/scan", submitURL), "POST").
|
|
SetTimeout(30*time.Second, 30*time.Second).Retries(3).RetryDelay(time.Second * 3)
|
|
|
|
params := input.ToStrMap()
|
|
params["sign"] = utils.GetMD5SignMF(params, input.PaySecret)
|
|
|
|
for k, v := range params {
|
|
req.Param(k, v)
|
|
}
|
|
|
|
response, err := req.String()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
submitOrderResponse := SubmitOrderResponse{}
|
|
err = json.Unmarshal([]byte(response), &submitOrderResponse)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &submitOrderResponse, nil
|
|
}
|