1
This commit is contained in:
66
controllers/tictok_callback.go
Normal file
66
controllers/tictok_callback.go
Normal file
@@ -0,0 +1,66 @@
|
||||
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) Msg() {
|
||||
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 {
|
||||
c.Data["json"] = MsgFail()
|
||||
c.ServeJSON()
|
||||
return
|
||||
}
|
||||
err = localjx.OnTTPayCallback(call, refund, payType)
|
||||
if err != nil {
|
||||
c.Data["json"] = MsgFail()
|
||||
c.ServeJSON()
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user