回调 触发下游回调
This commit is contained in:
parent
6ab982e874
commit
ca42c43bd2
|
@ -85,7 +85,7 @@ func (o *OrderNotify) handle() (res *OrderNotifyResp) {
|
||||||
return &OrderNotifyResp{
|
return &OrderNotifyResp{
|
||||||
OrderId: o.OrderId,
|
OrderId: o.OrderId,
|
||||||
Send: true,
|
Send: true,
|
||||||
ErrCode: o.ErrCode,
|
ErrCode: o.code,
|
||||||
Content: o,
|
Content: o,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ func (o *OrderNotify) setBody() *OrderNotifySendContent {
|
||||||
CompleteTime: o.CompleteTime,
|
CompleteTime: o.CompleteTime,
|
||||||
Status: o.order.Status,
|
Status: o.order.Status,
|
||||||
Msg: o.Msg,
|
Msg: o.Msg,
|
||||||
ErrCode: o.ErrCode,
|
ErrCode: o.code,
|
||||||
AppId: o.order.AppId,
|
AppId: o.order.AppId,
|
||||||
ChannelId: o.order.PayChannelId,
|
ChannelId: o.order.PayChannelId,
|
||||||
MerchantId: o.order.MerchantId,
|
MerchantId: o.order.MerchantId,
|
||||||
|
@ -118,7 +118,7 @@ func (o *OrderNotify) setBody() *OrderNotifySendContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OrderNotify) updateOrder() {
|
func (o *OrderNotify) updateOrder() {
|
||||||
if o.ErrCode != errorcode.Success {
|
if o.code != errorcode.Success {
|
||||||
o.order.Status = common.ORDER_STATUS_FAILED
|
o.order.Status = common.ORDER_STATUS_FAILED
|
||||||
} else {
|
} else {
|
||||||
o.order.Status = common.ORDER_STATUS_PAYED
|
o.order.Status = common.ORDER_STATUS_PAYED
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package paymentService
|
package paymentService
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"PaymentCenter/app/constants/common"
|
||||||
|
"PaymentCenter/app/constants/errorcode"
|
||||||
|
"PaymentCenter/app/services/thirdpay/notify"
|
||||||
"PaymentCenter/app/third/paymentService/payCommon"
|
"PaymentCenter/app/third/paymentService/payCommon"
|
||||||
"PaymentCenter/config"
|
"PaymentCenter/config"
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-pay/gopay"
|
"github.com/go-pay/gopay"
|
||||||
|
@ -99,7 +103,43 @@ func ALiCallBack(notifyReq gopay.BodyMap, aliConfig AliPay) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo 拼装数据触发下游回调,数据待定
|
// 拼装数据触发下游回调,触发下游回调
|
||||||
|
orderId, _ := strconv.Atoi(notifyReq.Get("out_trade_no"))
|
||||||
|
payerTotal, _ := strconv.Atoi(notifyReq.Get("buyer_pay_amount"))
|
||||||
|
// 订单状态
|
||||||
|
tradeStatus := notifyReq.Get("trade_status")
|
||||||
|
errCode := 0
|
||||||
|
msg := ""
|
||||||
|
switch tradeStatus {
|
||||||
|
case "TRADE_CLOSED":
|
||||||
|
errCode = errorcode.ParamError
|
||||||
|
msg = "未付款交易超时关闭,或支付完成后全额退款。"
|
||||||
|
case "TRADE_SUCCESS":
|
||||||
|
errCode = errorcode.Success
|
||||||
|
msg = "交易支付成功。"
|
||||||
|
case "TRADE_FINISHED":
|
||||||
|
errCode = errorcode.Success
|
||||||
|
msg = "交易结束,不可退款。"
|
||||||
|
}
|
||||||
|
if errCode == 0 {
|
||||||
|
// 等待买家付款,不走后续回调
|
||||||
|
return errors.New("订单状态异常,无法进行后续回调")
|
||||||
|
}
|
||||||
|
|
||||||
|
res := notify.NewOrderNotifyWithHandle(int64(orderId), errCode, payerTotal, msg)
|
||||||
|
merchantCallback, _ := json.Marshal(res)
|
||||||
|
// 记录日志
|
||||||
|
go func() {
|
||||||
|
payCallback, _ := json.Marshal(notifyReq)
|
||||||
|
payParam := ""
|
||||||
|
saveLog(int64(orderId), common.THIRD_ORDER_TYPE_CALL_BACK, string(payCallback), payParam, string(merchantCallback))
|
||||||
|
}()
|
||||||
|
|
||||||
|
if res.ErrCode != errorcode.Success {
|
||||||
|
logger.Error(context.Background(), "ALiCallBack 发生错误", fmt.Sprintf("回调时,下游处理订单失败,返回数据为:%s", string(merchantCallback)))
|
||||||
|
return errors.New("回调时,下游处理订单失败")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package paymentService
|
package paymentService
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"PaymentCenter/app/constants/common"
|
||||||
|
"PaymentCenter/app/constants/errorcode"
|
||||||
|
"PaymentCenter/app/services/thirdpay/notify"
|
||||||
"PaymentCenter/app/third/paymentService/payCommon"
|
"PaymentCenter/app/third/paymentService/payCommon"
|
||||||
"PaymentCenter/config"
|
"PaymentCenter/config"
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-pay/gopay"
|
"github.com/go-pay/gopay"
|
||||||
|
@ -135,7 +139,40 @@ func WxPayCallBack(notifyReq *wechat.V3NotifyReq, wxConfig WxPay) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// todo 返回触发下游回调的格式
|
|
||||||
|
errCode := 0
|
||||||
|
msg := ""
|
||||||
|
// 订单状态
|
||||||
|
switch CallBackInfo.TradeState {
|
||||||
|
case "SUCCESS":
|
||||||
|
errCode = errorcode.Success
|
||||||
|
msg = "支付成功"
|
||||||
|
case "CLOSED":
|
||||||
|
errCode = errorcode.ParamError
|
||||||
|
msg = "已关闭"
|
||||||
|
case "REVOKED":
|
||||||
|
errCode = errorcode.ParamError
|
||||||
|
msg = "已撤销(付款码支付)"
|
||||||
|
case "PAYERROR":
|
||||||
|
errCode = errorcode.ParamError
|
||||||
|
msg = "支付失败(其他原因,如银行返回失败)"
|
||||||
|
}
|
||||||
|
|
||||||
|
// 触发下游回调的格式
|
||||||
|
orderId, _ := strconv.Atoi(CallBackInfo.OutTradeNo)
|
||||||
|
res := notify.NewOrderNotifyWithHandle(int64(orderId), errCode, int(CallBackInfo.Amount.PayerTotal), msg)
|
||||||
|
merchantCallback, _ := json.Marshal(res)
|
||||||
|
// 记录日志
|
||||||
|
go func() {
|
||||||
|
payCallback, _ := json.Marshal(CallBackInfo)
|
||||||
|
payParam := ""
|
||||||
|
saveLog(int64(orderId), common.THIRD_ORDER_TYPE_CALL_BACK, string(payCallback), payParam, string(merchantCallback))
|
||||||
|
}()
|
||||||
|
|
||||||
|
if res.ErrCode != errorcode.Success {
|
||||||
|
logger.Error(context.Background(), "WxPayCallBack 发生错误", fmt.Sprintf("回调时,下游处理订单失败,返回数据为:%s", string(merchantCallback)))
|
||||||
|
return errors.New("回调时,下游处理订单失败")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue