|
|
@@ -268,6 +268,30 @@ func (self *BaseController) GetCurrentWxUser(useCache bool) *user_model.WxUser {
|
|
|
return u
|
|
|
}
|
|
|
|
|
|
+//根据token解析userId
|
|
|
+func (self *BaseController) GetCurrentUserIdByToken() int64 {
|
|
|
+ return getCurrentUserIdByToken(self.Ctx)
|
|
|
+}
|
|
|
+
|
|
|
+//TODO校验是否微信客户端
|
|
|
+func getCurrentUserIdByToken(ctx *context.Context) int64 {
|
|
|
+ inputToken := ""
|
|
|
+ wxUserId := int64(0)
|
|
|
+ requestAuthordata := ctx.Request.Header.Get("Authorization")
|
|
|
+ if len(requestAuthordata) > 0 {
|
|
|
+ authorizationData := strings.SplitN(ctx.Request.Header.Get("Authorization"), " ", 2)
|
|
|
+ inputToken = authorizationData[1]
|
|
|
+ }
|
|
|
+ token_user, err := token_model.ValidateToken(inputToken)
|
|
|
+ if err == nil {
|
|
|
+ wxUser := user_model.GetWxUserById(token_user.Id, true)
|
|
|
+ if wxUser != nil {
|
|
|
+ wxUserId = wxUser.Id
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return wxUserId
|
|
|
+}
|
|
|
+
|
|
|
//sceneId, 关注场景id
|
|
|
func (self *BaseController) CheckWxUserSubscribe(sceneId int64) {
|
|
|
beego.BeeLogger.Info("check wx_user subscribe")
|