Browse Source

fix(用户微信登录):如果已经存在token,且当前openid绑定了联系人,且联系人编号与session里面的联系人编号不一致的时候,需要做session变更

Roc 4 years ago
parent
commit
a0afcc59bb
2 changed files with 9 additions and 6 deletions
  1. 5 5
      controllers/base_auth.go
  2. 4 1
      services/user.go

+ 5 - 5
controllers/base_auth.go

@@ -68,15 +68,15 @@ func (this *BaseAuthController) Prepare() {
 				return
 			}
 			var wxUser *models.WxUserItem
-			if session.UserId > 0{
-				tmpWxUser, tmpErr := services.GetWxUserItemByUserId(session.UserId,utils.WxPcPlatform)
+			if session.OpenId != ""{
+				tmpWxUser, tmpErr := services.GetWxUserItemByOpenId(session.OpenId)
 				wxUser = tmpWxUser
 				err = tmpErr
-			}else if session.OpenId != ""{
-				tmpWxUser, tmpErr := services.GetWxUserItemByOpenId(session.OpenId)
+			}else if session.UserId > 0{
+				tmpWxUser, tmpErr := services.GetWxUserItemByUserId(session.UserId,utils.WxPcPlatform)
 				wxUser = tmpWxUser
 				err = tmpErr
-			}else{
+			}else {
 				this.JSON(models.BaseResponse{Ret: 408, Msg: "数据异常!", ErrMsg: "sesson is empty "}, false, false)
 				this.StopRun()
 				return

+ 4 - 1
services/user.go

@@ -324,7 +324,10 @@ QUERY_WX_USER:
 		}
 	} else {
 		token = tokenItem.AccessToken
-		//_ = models.UpdateSession(tokenItem.SessionId,userId,time.Now().AddDate(0, 1, 0))
+		//如果联系人编号不为空,且联系人编号与session里面的联系人编号不一致的时候,需要做session变更
+		if userId > 0 && tokenItem.UserId != userId{
+			_ = models.UpdateSession(tokenItem.SessionId,userId,time.Now().AddDate(0, 1, 0))
+		}
 	}
 
 	//新增登录日志