Files
jx-callback/controllers/weimob_callback.go
2019-08-21 17:22:02 +08:00

46 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package controllers
import (
"git.rosy.net.cn/baseapi/platformapi/weimobapi"
"git.rosy.net.cn/jx-callback/business/jxutils/tasks"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"github.com/astaxie/beego"
)
type WeimobController struct {
beego.Controller
}
func (c *WeimobController) onCallbackMsg() {
if true { //c.Ctx.Input.Method() == http.MethodPost {
callbackResponse := weimobapi.SuccessResponse
// msg, callbackResponse := api.WeimobAPI.GetCallbackMsg(c.Ctx.Input.RequestBody)
// if callbackResponse == nil {
// callbackResponse = wsc.OnCallbackMsg(msg)
// }
c.Data["json"] = callbackResponse
c.ServeJSON()
} else {
c.Abort("404")
}
}
func (c *WeimobController) Code() {
globals.SugarLogger.Debugf("WeimobController code, code:%s, state:%s", c.GetString("code"), c.GetString("state"))
state := c.GetString("state")
if state == globals.WeimobStateSecret { // 防止有人故意搞坏添加一个secret
code := c.GetString("code")
token, err := api.WeimobAPI.RefreshTokenByCode(code, globals.WeimobCallbackURL+"/code")
if err == nil {
tasks.SaveWeimobToken(token)
} else {
globals.SugarLogger.Warnf("RefreshTokenByCode failed with error:%v", err)
}
}
}
func (c *WeimobController) Msg() {
c.onCallbackMsg()
}