83 lines
2.6 KiB
Go
83 lines
2.6 KiB
Go
package thirdpay
|
|
|
|
import (
|
|
"PaymentCenter/app/constants/common"
|
|
"PaymentCenter/app/constants/errorcode"
|
|
"PaymentCenter/app/http/entities/backend"
|
|
"PaymentCenter/app/models/ordersmodel"
|
|
"PaymentCenter/app/services/thirdpay/thirdpay_notify"
|
|
"PaymentCenter/app/third/paymentService"
|
|
"PaymentCenter/app/third/paymentService/payCommon"
|
|
"PaymentCenter/app/utils"
|
|
"context"
|
|
"fmt"
|
|
"github.com/goccy/go-json"
|
|
)
|
|
|
|
// 发起查询上游支付,并回调下游
|
|
func OrderQueryAndNotify(ctx context.Context, orderInfo *ordersmodel.OrdersLeftPayChannelList) {
|
|
|
|
query := paymentService.PayOrderQueryRequest{
|
|
OrderId: orderInfo.Id,
|
|
}
|
|
switch utils.PayType(orderInfo.ChannelType) {
|
|
case common.PAY_CHANNLE_TYPE_WECHAT:
|
|
wx := backend.WechatPayChannel{}
|
|
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &wx)
|
|
query.PayChannel = payCommon.PAY_CHANNLE_TYPE_WECHAT
|
|
query.Wx = paymentService.WxPay{
|
|
AppId: orderInfo.AppId,
|
|
MchId: wx.MchId,
|
|
SerialNo: wx.SerialNo,
|
|
ApiV3Key: wx.ApiV3Key,
|
|
PrivateKey: wx.PrivateKey,
|
|
}
|
|
case common.PAY_CHANNLE_TYPE_ZFB:
|
|
ali := backend.AliPayChannel{}
|
|
query.PayChannel = payCommon.PAY_CHANNLE_TYPE_ZFB
|
|
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &ali)
|
|
query.Ali = paymentService.AliPay{
|
|
AppId: orderInfo.AppId,
|
|
PrivateKey: ali.PrivateKey,
|
|
AppPublicCert: ali.AppPublicCert,
|
|
AlipayRootCert: ali.AlipayRootCert,
|
|
AlipayPublicCert: ali.AlipayPublicCert,
|
|
}
|
|
default:
|
|
utils.Log(nil, "查询订单,支付渠道不支持", orderInfo.ChannelType)
|
|
return
|
|
}
|
|
|
|
// 发起查询
|
|
result := paymentService.PayOrderQuery(ctx, query)
|
|
utils.Log(nil, "主动查询订单支付状态,上游返回数据", result)
|
|
// 查询成功,校验状态
|
|
var status int
|
|
if result.Code == payCommon.PAY_SUCCESS_CODE {
|
|
var msg string
|
|
switch result.Result.TradeState {
|
|
case "SUCCESS":
|
|
// 成功
|
|
status = common.ORDER_STATUS_PAYED
|
|
msg = "支付成功"
|
|
case "REFUND":
|
|
// 退款 订单支付完成才能退款,所以支付单的状态是支付完成
|
|
status = common.ORDER_STATUS_PAYED
|
|
msg = "已支付,发生退款"
|
|
case "NOTPAY":
|
|
// 未支付
|
|
return
|
|
case "CLOSED":
|
|
// 关闭
|
|
status = common.ORDER_STATUS_CLOSE
|
|
msg = "订单关闭"
|
|
}
|
|
// 回调通知下游
|
|
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, result.Code, status, int(result.Result.PayerTotal), msg)
|
|
//utils.Log(nil, "主动查询订单支付状态,回调下游", notifyResult)
|
|
if notifyResult.ErrCode != errorcode.Success {
|
|
utils.Log(nil, "主动查询订单支付状态,回调下游失败", fmt.Sprintf("%+v", notifyResult))
|
|
}
|
|
}
|
|
}
|