PaymentCenter/app/http/controllers/front/payment_controller.go

55 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package front
import (
"github.com/gin-gonic/gin"
"github.com/go-pay/gopay/alipay"
"github.com/go-pay/xlog"
"github.com/qit-team/snow-core/log/logger"
"net/http"
)
// WxCallback 微信支付回调
//func WxCallback(c *gin.Context) {
// notifyReq, err := wechat.V3ParseNotify(c.Request)
// if err != nil {
// xlog.Error(err)
// return
// }
//
// paymentService.WxPayCallBack(notifyReq)
//
// // ====↓↓↓====异步通知应答====↓↓↓====
// // 退款通知http应答码为200且返回状态码为SUCCESS才会当做商户接收成功否则会重试。
// // 注意:重试过多会导致微信支付端积压过多通知而堵塞,影响其他正常通知。
//
// // 此写法是 gin 框架返回微信的写法
// c.JSON(http.StatusOK, &wechat.V3NotifyRsp{Code: gopay.SUCCESS, Message: "成功"})
//}
// AliCallback 支付宝支付回调
func AliCallback(c *gin.Context) {
notifyReq, err := alipay.ParseNotifyToBodyMap(c.Request) // c.Request 是 gin 框架的写法
logger.Info(c, "AliCallback-回调数据", c.Request)
if err != nil {
xlog.Error(err)
return
}
appId := notifyReq.Get("app_id")
if appId == "" {
c.String(http.StatusBadRequest, "%s", "fail")
}
// todo 查询支付宝公钥证书信息,进行验证签名
alipayPublicCert := ""
ok, err := alipay.VerifySignWithCert([]byte(alipayPublicCert), notifyReq)
if !ok {
logger.Error(c, "AliCallback-回调数据,验签失败")
c.String(http.StatusBadRequest, "%s", "fail")
}
// todo 拼装数据触发下游回调,数据待定
c.String(http.StatusOK, "%s", "success")
}