@@ -0,0 +1,58 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user