- weimob token

This commit is contained in:
gazebo
2019-01-15 15:56:01 +08:00
parent 1e2d3ae0bb
commit 0873043449
6 changed files with 120 additions and 48 deletions

View File

@@ -1,6 +1,9 @@
package controllers
import (
"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"
)
@@ -14,5 +17,15 @@ func (c *WeimobController) onCallbackMsg(msgType string) {
}
func (c *WeimobController) Code() {
c.onCallbackMsg("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)
}
}
}