go接入支付宝异步回调通知

go接入支付宝异步回调通知

1.接入三方支付包

"github.com/go-pay/gopay"

2.demo

//支付宝异步通知
func (s basicService) AliPayNotify(ctx context.Context, req api.PayNotifyRequest) string {
	notifyReq, err := alipay.ParseNotifyToBodyMap(req.Request)
	if err != nil {
		return FAIL
	}
	// 支付宝异步通知验签(公钥模式)
	ok, err := alipay.VerifySign(s.conf.AliPay.PublicKey, notifyReq)
	if !ok {
		mylog.WithContext(ctx).Error(err.Error())
		return FAIL
	}
	mylog.Sugar().Debug(notifyReq)
	errCode := ""
	switch notifyReq.GetString("notify_type") {
	case "trade_status_sync": //扣款通知(交易状态变更通知)
		if notifyReq.GetString("refund_fee") != "" { //退款金额不为空,退款
			errCode = s.aliPayNotifyRefundSuccess(ctx, notifyReq)
		} else { //交易成功
			errCode = s.aliPayTradeNotify(ctx, notifyReq)
		}
	case "dut_user_sign": //签约通知
		errCode = s.aliPaySignNotify(ctx, notifyReq)
	case "dut_user_unsign": //解约通知
		errCode = s.aliPayNotifyCancelSubscription(ctx, notifyReq)
	case "refund_failed": //拒绝退款
		errCode = s.aliPayNotifyRefundFailed(ctx, notifyReq)
	default:
		errCode = FAIL
	}
	return errCode
}
  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值