Files
2026-10-27 16:44:55 +08:00

59 lines
1.6 KiB
Go

package payCenter
import (
"context"
"errors"
"fmt"
"videoweb/pub/common/httputil"
"videoweb/pub/common/log"
)
type RechargeQueryResp struct {
Code int `json:"code"`
Msg QueryOrderInfo `json:"msg"`
}
type QueryOrderInfo struct {
MercID string `json:"mercID"`
TradeNo string `json:"tradeNo"`
Money float32 `json:"money"`
PayMoney float32 `json:"payMoney"`
PayTime string `json:"payTime"`
PayStatus string `json:"payStatus"`
NotifyStatus string `json:"notifyStatus"`
}
func (in *Recharge) GetQueryURL() string {
return payCenterConf.ApiUrl + "/api/shark/order/queryOrder"
}
func (in *Recharge) QueryOrder(ctx context.Context) (QueryOrderInfo, error) {
if in == nil {
return QueryOrderInfo{}, errors.New("query pay center order: nil recharge")
}
if err := validateConfig(false); err != nil {
return QueryOrderInfo{}, err
}
if in.TradeNo == "" {
return QueryOrderInfo{}, errors.New("新支付中心查单缺少订单号")
}
var response RechargeQueryResp
body := map[string]string{
"mercId": in.GetMercID(),
"tradeNo": in.TradeNo,
}
code, err := httputil.NewCtx(ctx).GetWithJResp(&response, in.GetQueryURL(), nil, body)
if err != nil {
log.Error("【新支付中心 /api/shark/order/queryOrder】查单失败", log.Any("tradeNo", in.TradeNo), log.E(err))
return QueryOrderInfo{}, fmt.Errorf("query pay center order: %w", err)
}
if code != 200 {
return QueryOrderInfo{}, fmt.Errorf("query pay center order: HTTP status %d", code)
}
if response.Code != 200 {
return QueryOrderInfo{}, fmt.Errorf("query pay center order: provider code %d", response.Code)
}
return response.Msg, nil
}