|
@@ -170,16 +170,20 @@ func formatWxUser(wxUser *wx_user.WxUser, platform int) (userInfo UserInfo) {
|
|
|
func WxLogin(wxPlatform int, wxSession auth.ResCode2Session) (token string, userId int, isBind bool, err error) {
|
|
|
openId := wxSession.OpenID
|
|
|
unionId := wxSession.UnionID
|
|
|
+ sessionKey := wxSession.SessionKey
|
|
|
|
|
|
+ needUpdateSessionKey := true //是否更新sessionKey
|
|
|
QUERY_WX_USER:
|
|
|
wxUser, wxUserErr := GetWxUserItemByOpenId(openId)
|
|
|
if wxUserErr == ERR_NO_USER_RECORD { //没有用户openid记录
|
|
|
- _, recordErr := AddUserRecord(openId, unionId, "", "", "", "", "", "", "", wxPlatform, 0, 0)
|
|
|
+ _, recordErr := AddUserRecord(openId, unionId, "", "", "", "", "", "", sessionKey, wxPlatform, 0, 0)
|
|
|
//如果插入失败,那么直接将错误信息返回
|
|
|
if recordErr != nil {
|
|
|
err = recordErr
|
|
|
return
|
|
|
}
|
|
|
+ needUpdateSessionKey = false //因为是新增用户微信信息,所以不需要更新sessionKey的数据了
|
|
|
+
|
|
|
//插入成功后,需要重新查询该用户,并进入下面的逻辑
|
|
|
goto QUERY_WX_USER
|
|
|
} else if wxUserErr == ERR_USER_NOT_BIND {
|
|
@@ -189,6 +193,11 @@ QUERY_WX_USER:
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ //更新微信用户的sessionKey
|
|
|
+ if needUpdateSessionKey {
|
|
|
+ _ = user_record.ModifySessionKeyByOpenid(openId, sessionKey)
|
|
|
+ }
|
|
|
+
|
|
|
//如果已经登录注册绑定的情况下
|
|
|
if wxUserErr == nil {
|
|
|
userId = int(wxUser.UserID)
|