70 lines
2.0 KiB
Go
70 lines
2.0 KiB
Go
package front
|
||
|
||
import (
|
||
"PaymentCenter/app/third/paymentService"
|
||
"github.com/gin-gonic/gin"
|
||
"github.com/go-pay/gopay"
|
||
"github.com/go-pay/gopay/alipay"
|
||
"github.com/go-pay/gopay/wechat/v3"
|
||
"github.com/go-pay/xlog"
|
||
"github.com/qit-team/snow-core/log/logger"
|
||
|
||
"net/http"
|
||
)
|
||
|
||
// WxCallback 微信支付回调
|
||
func WxCallback(c *gin.Context) {
|
||
appId := c.Param("appId")
|
||
logger.Info(c, "WxCallback-回调数据APPID", appId)
|
||
if appId == "" {
|
||
c.String(http.StatusBadRequest, "%s", "fail")
|
||
}
|
||
|
||
// todo 查询应用下的支付配置
|
||
|
||
var wxConfig paymentService.WxPay
|
||
|
||
logger.Info(c, "WxCallback-回调数据", c.Request)
|
||
notifyReq, err := wechat.V3ParseNotify(c.Request)
|
||
if err != nil {
|
||
logger.Error(c, "WxCallback-回调数据验签失败", err.Error())
|
||
return
|
||
}
|
||
|
||
err = paymentService.WxPayCallBack(notifyReq, wxConfig)
|
||
if err != nil {
|
||
logger.Error(c, "WxCallback-回调执行失败,失败原因:", err.Error())
|
||
return
|
||
}
|
||
|
||
// ====↓↓↓====异步通知应答====↓↓↓====
|
||
// 退款通知http应答码为200且返回状态码为SUCCESS才会当做商户接收成功,否则会重试。
|
||
// 注意:重试过多会导致微信支付端积压过多通知而堵塞,影响其他正常通知。
|
||
c.JSON(http.StatusOK, &wechat.V3NotifyRsp{Code: gopay.SUCCESS, Message: "成功"})
|
||
}
|
||
|
||
// AliCallback 支付宝支付回调
|
||
func AliCallback(c *gin.Context) {
|
||
appId := c.Param("appId")
|
||
logger.Info(c, "AliCallback-回调数据APPID", appId)
|
||
if appId == "" {
|
||
c.String(http.StatusBadRequest, "%s", "fail")
|
||
}
|
||
// todo 查询应用下的支付配置
|
||
|
||
notifyReq, err := alipay.ParseNotifyToBodyMap(c.Request) // c.Request 是 gin 框架的写法
|
||
logger.Info(c, "AliCallback-回调数据", c.Request)
|
||
if err != nil {
|
||
xlog.Error(err)
|
||
return
|
||
}
|
||
var aliConfig paymentService.AliPay
|
||
err = paymentService.ALiCallBack(notifyReq, aliConfig)
|
||
if err != nil {
|
||
logger.Error(c, "AliCallback-回调执行失败,失败原因:", err.Error())
|
||
return
|
||
}
|
||
|
||
c.String(http.StatusOK, "%s", "success")
|
||
}
|