33 lines
958 B
Go
33 lines
958 B
Go
package controllers
|
||
|
||
import (
|
||
"git.rosy.net.cn/jx-callback/business/jxutils/tasks"
|
||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/weimob/wsc"
|
||
"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(msgType string) {
|
||
c.Data["json"] = "ok"
|
||
c.ServeJSON()
|
||
}
|
||
|
||
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)
|
||
}
|
||
}
|
||
}
|