70 lines
1.6 KiB
Go
70 lines
1.6 KiB
Go
package controllers
|
|
|
|
import (
|
|
"bytes"
|
|
"git.rosy.net.cn/jx-callback/business/partner/purchase/jx/localjx"
|
|
"io/ioutil"
|
|
"net/http"
|
|
|
|
"git.rosy.net.cn/jx-callback/globals/api"
|
|
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/globals"
|
|
|
|
"github.com/astaxie/beego/server/web"
|
|
"github.com/astaxie/beego/server/web/context"
|
|
)
|
|
|
|
type TicTocController struct {
|
|
web.Controller
|
|
}
|
|
|
|
type TicktockRes struct {
|
|
ErrNo int `json:"err_no"`
|
|
ErrTips string `json:"err_tips"`
|
|
}
|
|
|
|
func MsgSuccess() *TicktockRes {
|
|
return &TicktockRes{
|
|
ErrNo: 0,
|
|
ErrTips: "success",
|
|
}
|
|
}
|
|
|
|
func MsgFail() *TicktockRes {
|
|
return &TicktockRes{
|
|
ErrNo: 400,
|
|
ErrTips: "business fail",
|
|
}
|
|
}
|
|
|
|
func (c *TicTocController) TiktokMsg() {
|
|
globals.SugarLogger.Debugf("============err:%s", "抖音支付/退款回调")
|
|
//if c.Ctx.Input.Method() == http.MethodPost {
|
|
call, refund, payType, err := api.TiktokApi.GetCallbackMsg(getPayInfo(c.Ctx))
|
|
globals.SugarLogger.Debugf("tictok callback callbackResponse:%s", utils.Format4Output(call, true))
|
|
if err != nil || call == nil{
|
|
c.Data["json"] = MsgFail()
|
|
c.ServeJSON()
|
|
globals.SugarLogger.Debugf("============err:%s", err)
|
|
return
|
|
}
|
|
|
|
if err = localjx.OnTTPayCallback(call, refund, payType); err != nil {
|
|
c.Data["json"] = MsgFail()
|
|
c.ServeJSON()
|
|
globals.SugarLogger.Debugf("============err:%s", err)
|
|
return
|
|
}
|
|
c.Data["json"] = MsgSuccess()
|
|
c.ServeJSON()
|
|
//} else {
|
|
// c.Abort("404")
|
|
//}
|
|
}
|
|
|
|
func getPayInfo(ctx *context.Context) *http.Request {
|
|
ctx.Request.Body = ioutil.NopCloser(bytes.NewReader(ctx.Input.RequestBody))
|
|
return ctx.Request
|
|
}
|