Files
jx-callback/controllers/wxpay_callback.go
gazebo 596afbd8c5 fk
2019-12-03 12:08:51 +08:00

45 lines
1.4 KiB
Go

package controllers
import (
"fmt"
"net/http"
"git.rosy.net.cn/baseapi/platformapi/wxpay"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/partner/purchase/jx/localjx"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"github.com/astaxie/beego"
)
type WXPayController struct {
beego.Controller
}
func (c *WXPayController) Msg() {
if c.Ctx.Input.Method() == http.MethodPost {
msg, callbackResponse := api.WxpayAPI.GetCallbackMsg(c.Ctx.Request)
globals.SugarLogger.Debugf("wxpay callback msg:%s, callbackResponse:%s, %t", utils.Format4Output(msg, true), utils.Format4Output(callbackResponse, true), callbackResponse == nil)
var err error
if callbackResponse == nil {
globals.SugarLogger.Debugf("wxpay callback1 msg:%s", utils.Format4Output(msg, true))
if msg.MsgType != wxpay.MsgTypeUnkown {
globals.SugarLogger.Debugf("wxpay callback2 msg:%s", utils.Format4Output(msg, true))
err = fmt.Errorf("未知的微信支付回调类型:%d", msg.MsgType)
} else {
globals.SugarLogger.Debugf("wxpay callback3 msg:%s", utils.Format4Output(msg, true))
err = localjx.OnWxPayCallback(msg)
}
}
if callbackResponse == nil {
callbackResponse = wxpay.SuccessResponse
} else if err != nil {
callbackResponse = wxpay.Err2CallbackResponse(err, "")
}
c.Data["xml"] = callbackResponse
c.ServeXML()
} else {
c.Abort("404")
}
}