fix
This commit is contained in:
@@ -58,7 +58,7 @@ func (l *PaymentCheckLogic) PaymentCheck(req *types.PaymentCheckReq) (resp *type
|
|||||||
// 查询失败不影响返回,继续返回当前订单状态
|
// 查询失败不影响返回,继续返回当前订单状态
|
||||||
} else {
|
} else {
|
||||||
// 如果易支付返回订单已支付(status == 1),更新本地订单状态
|
// 如果易支付返回订单已支付(status == 1),更新本地订单状态
|
||||||
if queryResp.Status == 1 {
|
if queryResp.GetStatusInt() == 1 {
|
||||||
logx.Infof("主动查询发现易支付订单已支付,订单号: %s,开始更新订单状态", req.OrderNo)
|
logx.Infof("主动查询发现易支付订单已支付,订单号: %s,开始更新订单状态", req.OrderNo)
|
||||||
|
|
||||||
// 重新查询订单(获取最新版本号)
|
// 重新查询订单(获取最新版本号)
|
||||||
|
|||||||
@@ -35,36 +35,107 @@ func NewEasyPayService(c config.Config) *EasyPayService {
|
|||||||
|
|
||||||
// EasyPayOrderResponse API接口支付响应
|
// EasyPayOrderResponse API接口支付响应
|
||||||
type EasyPayOrderResponse struct {
|
type EasyPayOrderResponse struct {
|
||||||
Code int `json:"code"`
|
Code interface{} `json:"code"` // 可能是 int 或 string
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
TradeNo string `json:"trade_no,omitempty"`
|
TradeNo string `json:"trade_no,omitempty"`
|
||||||
OId string `json:"O_id,omitempty"`
|
OId string `json:"O_id,omitempty"`
|
||||||
PayUrl string `json:"payurl,omitempty"`
|
PayUrl string `json:"payurl,omitempty"`
|
||||||
Qrcode string `json:"qrcode,omitempty"`
|
Qrcode string `json:"qrcode,omitempty"`
|
||||||
Img string `json:"img,omitempty"`
|
Img string `json:"img,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCodeInt 获取 code 的 int 值
|
||||||
|
func (r *EasyPayOrderResponse) GetCodeInt() int {
|
||||||
|
switch v := r.Code.(type) {
|
||||||
|
case int:
|
||||||
|
return v
|
||||||
|
case float64:
|
||||||
|
return int(v)
|
||||||
|
case string:
|
||||||
|
if v == "1" || v == "error" {
|
||||||
|
if v == "1" {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
default:
|
||||||
|
return 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EasyPayQueryResponse 查询订单响应
|
// EasyPayQueryResponse 查询订单响应
|
||||||
type EasyPayQueryResponse struct {
|
type EasyPayQueryResponse struct {
|
||||||
Code int `json:"code"`
|
Code interface{} `json:"code"` // 可能是 int 或 string
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
TradeNo string `json:"trade_no,omitempty"`
|
TradeNo string `json:"trade_no,omitempty"`
|
||||||
OutTradeNo string `json:"out_trade_no,omitempty"`
|
OutTradeNo string `json:"out_trade_no,omitempty"`
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
Pid string `json:"pid,omitempty"`
|
Pid string `json:"pid,omitempty"`
|
||||||
Addtime string `json:"addtime,omitempty"`
|
Addtime string `json:"addtime,omitempty"`
|
||||||
Endtime string `json:"endtime,omitempty"`
|
Endtime string `json:"endtime,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Money string `json:"money,omitempty"`
|
Money string `json:"money,omitempty"`
|
||||||
Status int `json:"status,omitempty"`
|
Status interface{} `json:"status,omitempty"` // 可能是 int 或 string
|
||||||
Param string `json:"param,omitempty"`
|
Param string `json:"param,omitempty"`
|
||||||
Buyer string `json:"buyer,omitempty"`
|
Buyer string `json:"buyer,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCodeInt 获取 code 的 int 值
|
||||||
|
func (r *EasyPayQueryResponse) GetCodeInt() int {
|
||||||
|
switch v := r.Code.(type) {
|
||||||
|
case int:
|
||||||
|
return v
|
||||||
|
case float64:
|
||||||
|
return int(v)
|
||||||
|
case string:
|
||||||
|
if v == "1" {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
default:
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetStatusInt 获取 status 的 int 值
|
||||||
|
func (r *EasyPayQueryResponse) GetStatusInt() int {
|
||||||
|
switch v := r.Status.(type) {
|
||||||
|
case int:
|
||||||
|
return v
|
||||||
|
case float64:
|
||||||
|
return int(v)
|
||||||
|
case string:
|
||||||
|
if v == "1" {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
default:
|
||||||
|
return 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EasyPayRefundResponse 退款响应
|
// EasyPayRefundResponse 退款响应
|
||||||
type EasyPayRefundResponse struct {
|
type EasyPayRefundResponse struct {
|
||||||
Code int `json:"code"`
|
Code interface{} `json:"code"` // 可能是 int 或 string
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCodeInt 获取 code 的 int 值
|
||||||
|
func (r *EasyPayRefundResponse) GetCodeInt() int {
|
||||||
|
switch v := r.Code.(type) {
|
||||||
|
case int:
|
||||||
|
return v
|
||||||
|
case float64:
|
||||||
|
return int(v)
|
||||||
|
case string:
|
||||||
|
if v == "1" {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
default:
|
||||||
|
return 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EasyPayNotification 支付回调通知
|
// EasyPayNotification 支付回调通知
|
||||||
@@ -213,7 +284,7 @@ func (e *EasyPayService) CreateEasyPayAppOrder(ctx context.Context, amount float
|
|||||||
return "", fmt.Errorf("解析响应失败: %v, 响应内容: %s", err, string(body))
|
return "", fmt.Errorf("解析响应失败: %v, 响应内容: %s", err, string(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
if orderResp.Code != 1 {
|
if orderResp.GetCodeInt() != 1 {
|
||||||
return "", fmt.Errorf("创建订单失败: %s", orderResp.Msg)
|
return "", fmt.Errorf("创建订单失败: %s", orderResp.Msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,7 +392,7 @@ func (e *EasyPayService) QueryOrderStatus(ctx context.Context, outTradeNo string
|
|||||||
return nil, fmt.Errorf("解析响应失败: %v, 响应内容: %s", err, string(body))
|
return nil, fmt.Errorf("解析响应失败: %v, 响应内容: %s", err, string(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
if queryResp.Code != 1 {
|
if queryResp.GetCodeInt() != 1 {
|
||||||
return nil, fmt.Errorf("查询订单失败: %s", queryResp.Msg)
|
return nil, fmt.Errorf("查询订单失败: %s", queryResp.Msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,7 +445,7 @@ func (e *EasyPayService) Refund(ctx context.Context, outTradeNo string, refundAm
|
|||||||
return fmt.Errorf("解析响应失败: %v, 响应内容: %s", err, string(body))
|
return fmt.Errorf("解析响应失败: %v, 响应内容: %s", err, string(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
if refundResp.Code != 1 {
|
if refundResp.GetCodeInt() != 1 {
|
||||||
return fmt.Errorf("退款失败: %s", refundResp.Msg)
|
return fmt.Errorf("退款失败: %s", refundResp.Msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user