service/app/mix/controller/wxpay_callback.go

34 lines
949 B
Go

package controller
import (
"github.com/gin-gonic/gin"
wxpay "github.com/go-pay/gopay/wechat/v3"
vasproto "service/api/proto/vas/proto"
"service/app/mix/service"
"service/bizcommon/util"
"service/library/logger"
"service/library/payclients/wxpaycli"
)
func WxpayCallback(ctx *gin.Context) {
notify, err := wxpaycli.GetDefaultWxpayClient().ParseNotify(ctx.Request)
if err != nil {
logger.Error("ParseNotify fail, req: %v, err: %v", util.ToJson(notify), err)
return
}
if notify == nil {
logger.Error("ParseNotify nil, req: %v, err: %v", util.ToJson(notify), err)
return
}
logger.Info("WxpayCallback, notify: %v", util.ToJson(notify))
if notify.TradeState == wxpay.TradeStateSuccess {
service.DefaultService.PayCallback(ctx, &vasproto.PayCallbackParamIn{
OrderId: notify.OutTradeNo,
OutOrderId: notify.TransactionId,
CallbackPayType: vasproto.CallBackPayTypeWxpay,
})
}
ctx.String(200, "success")
}