Browse Source

fix(微信登录逻辑):调整微信登录逻辑,如果系统中不存在该第三方用户信息,那么就入库后,再次返回查询

Roc 4 years ago
parent
commit
e573afe73b
1 changed files with 10 additions and 2 deletions
  1. 10 2
      services/user.go

+ 10 - 2
services/user.go

@@ -231,12 +231,20 @@ func WxLogin(code, openId, unionId string, wxUserInfo *WxUserInfo) (token string
 	//firstLogin==1,强制绑定手机号或者邮箱
 	firstLogin = 1
 	fmt.Println("GetWxUserItemByOpenId ", openId)
+
+QUERY_WX_USER:
 	wxUser, wxUserErr := GetWxUserItemByOpenId(openId)
 	fmt.Println("wxUserErr", wxUserErr)
 	if wxUserErr == ERR_NO_USER_RECORD { //没有用户openid记录
+		//先添加第三方信息(openid等信息)
 		_, recordErr := AddUserRecord(openId, unionId, wxUserInfo.Nickname, "", wxUserInfo.Province, wxUserInfo.City, wxUserInfo.Country, wxUserInfo.Headimgurl, wxUserInfo.SessionKey, utils.WxPlatform, wxUserInfo.Sex, 0)
-		err = recordErr
-		return
+		//如果插入失败,那么直接将错误信息返回
+		if recordErr != nil{
+			err = recordErr
+			return
+		}
+		//插入成功后,需要重新查询该用户,并进入下面的逻辑
+		goto QUERY_WX_USER
 	} else if wxUserErr == ERR_USER_NOT_BIND {
 		//没有用户信息
 		//wxUser.FirstLogin = 1