fix: BepUsdt签名改用fmt.Sprint格式化amount(与官方一致),添加调试日志
This commit is contained in:
@@ -78,9 +78,11 @@ func (h *PaymentHandler) CreatePayment(c *gin.Context) {
|
|||||||
redirectURL := fmt.Sprintf("%s/orders/%d", baseURL, order.ID)
|
redirectURL := fmt.Sprintf("%s/orders/%d", baseURL, order.ID)
|
||||||
timestamp := time.Now().Unix()
|
timestamp := time.Now().Unix()
|
||||||
|
|
||||||
|
amountStr := fmt.Sprint(order.TotalAmount)
|
||||||
|
|
||||||
params := map[string]string{
|
params := map[string]string{
|
||||||
"order_id": strconv.Itoa(int(order.ID)),
|
"order_id": strconv.Itoa(int(order.ID)),
|
||||||
"amount": strconv.FormatFloat(order.TotalAmount, 'f', -1, 64),
|
"amount": amountStr,
|
||||||
"notify_url": notifyURL,
|
"notify_url": notifyURL,
|
||||||
"redirect_url": redirectURL,
|
"redirect_url": redirectURL,
|
||||||
"timestamp": strconv.FormatInt(timestamp, 10),
|
"timestamp": strconv.FormatInt(timestamp, 10),
|
||||||
@@ -91,6 +93,9 @@ func (h *PaymentHandler) CreatePayment(c *gin.Context) {
|
|||||||
|
|
||||||
signature := signBepUsdt(params, apiToken)
|
signature := signBepUsdt(params, apiToken)
|
||||||
|
|
||||||
|
fmt.Printf("[BepUsdt] signature params: %v\n", params)
|
||||||
|
fmt.Printf("[BepUsdt] signature: %s, token: %s\n", signature, apiToken)
|
||||||
|
|
||||||
reqBody := BepUsdtCreateRequest{
|
reqBody := BepUsdtCreateRequest{
|
||||||
TradeType: tradeType,
|
TradeType: tradeType,
|
||||||
OrderID: strconv.Itoa(int(order.ID)),
|
OrderID: strconv.Itoa(int(order.ID)),
|
||||||
@@ -102,6 +107,7 @@ func (h *PaymentHandler) CreatePayment(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body, _ := json.Marshal(reqBody)
|
body, _ := json.Marshal(reqBody)
|
||||||
|
fmt.Printf("[BepUsdt] request body: %s\n", string(body))
|
||||||
resp, err := http.Post(apiURL+"/api/v1/order/create-transaction", "application/json", strings.NewReader(string(body)))
|
resp, err := http.Post(apiURL+"/api/v1/order/create-transaction", "application/json", strings.NewReader(string(body)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to connect payment gateway"})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to connect payment gateway"})
|
||||||
@@ -111,6 +117,8 @@ func (h *PaymentHandler) CreatePayment(c *gin.Context) {
|
|||||||
|
|
||||||
respBody, _ := io.ReadAll(resp.Body)
|
respBody, _ := io.ReadAll(resp.Body)
|
||||||
|
|
||||||
|
fmt.Printf("[BepUsdt] response: %s\n", string(respBody))
|
||||||
|
|
||||||
var result map[string]interface{}
|
var result map[string]interface{}
|
||||||
json.Unmarshal(respBody, &result)
|
json.Unmarshal(respBody, &result)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user