|
@@ -2,10 +2,8 @@ package services
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
- "fmt"
|
|
|
"hongze/hongze_clpt/models"
|
|
|
"hongze/hongze_clpt/utils"
|
|
|
- "strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
@@ -115,7 +113,6 @@ func BindWxUser(mobile, countryCode string) (wxUser *models.WxUserItem, err erro
|
|
|
err = errors.New("手机号或邮箱必填一个")
|
|
|
return
|
|
|
}
|
|
|
- //var bindAccount string
|
|
|
//根据手机号获取用户信息
|
|
|
if mobile != "" {
|
|
|
tmpWxUser, wxUserErr := models.GetWxUserItemByMobile(mobile)
|
|
@@ -124,7 +121,6 @@ func BindWxUser(mobile, countryCode string) (wxUser *models.WxUserItem, err erro
|
|
|
return
|
|
|
}
|
|
|
wxUser = tmpWxUser
|
|
|
- //bindAccount = mobile
|
|
|
}
|
|
|
var userId int
|
|
|
//如果查询出来的用户是nil,那么需要新增用户
|
|
@@ -253,99 +249,6 @@ func BindWxUserMobileAndOpenid(mobile, openid, countryCode string) (wxUser *mode
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//微信登录
|
|
|
-func WxLogin(code, openId, unionId string, wxUserInfo *WxUserInfo) (token string, userId, firstLogin, permission int, err error) {
|
|
|
- if unionId == "" {
|
|
|
- unionId = wxUserInfo.Unionid
|
|
|
- }
|
|
|
- //firstLogin==1,强制绑定手机号或者邮箱
|
|
|
- firstLogin = 1
|
|
|
- //fmt.Println()
|
|
|
- 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.CE_LUE_ID, wxUserInfo.Sex, 0)
|
|
|
- //如果插入失败,那么直接将错误信息返回
|
|
|
- if recordErr != nil {
|
|
|
- err = recordErr
|
|
|
- return
|
|
|
- }
|
|
|
- //插入成功后,需要重新查询该用户,并进入下面的逻辑
|
|
|
- goto QUERY_WX_USER
|
|
|
- } else if wxUserErr == ERR_USER_NOT_BIND {
|
|
|
- //没有用户信息
|
|
|
- //wxUser.FirstLogin = 1
|
|
|
- } else if wxUserErr != nil {
|
|
|
- err = wxUserErr
|
|
|
- return
|
|
|
- }
|
|
|
- fmt.Println("wxUserInfo", wxUserInfo)
|
|
|
- fmt.Println("wxUserInfo.Nickname", wxUserInfo.Nickname)
|
|
|
- fmt.Println("SessionKey", wxUserInfo.SessionKey)
|
|
|
- if wxUserInfo != nil {
|
|
|
- fmt.Println("ModifyUserRecordSessionKey")
|
|
|
- err = models.ModifyUserRecordSessionKey(openId, wxUserInfo.SessionKey)
|
|
|
- fmt.Println("ModifyUserRecordSessionKey Err", err)
|
|
|
- }
|
|
|
- //如果已经登录注册绑定的情况下
|
|
|
- if wxUser != nil && wxUserErr == nil {
|
|
|
- //获取用户权限
|
|
|
- firstLogin = wxUser.FirstLogin
|
|
|
- userId = wxUser.UserId
|
|
|
- {
|
|
|
- codeLog := new(models.WxUserCode)
|
|
|
- codeLog.WxCode = code
|
|
|
- codeLog.UserId = userId
|
|
|
- codeLog.Code = 0
|
|
|
- codeLog.FirstLogin = firstLogin
|
|
|
- codeLog.Authorization = token
|
|
|
- codeLog.UserPermission = permission
|
|
|
- codeLog.CreateTime = time.Now()
|
|
|
- go models.AddWxUserCode(codeLog)
|
|
|
- }
|
|
|
- if wxUser.Mobile == "" && wxUser.Email == "" {
|
|
|
- firstLogin = 1
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //获取登录token
|
|
|
- tokenItem, tokenErr := models.GetTokenByOpenId(openId)
|
|
|
- if tokenErr != nil && tokenErr.Error() != utils.ErrNoRow() {
|
|
|
- err = errors.New("登录失败,获取token失败:" + tokenErr.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- fmt.Println("line 271 ", openId)
|
|
|
- if tokenItem == nil || (tokenErr != nil && tokenErr.Error() == utils.ErrNoRow()) {
|
|
|
- timeUnix := time.Now().Unix()
|
|
|
- timeUnixStr := strconv.FormatInt(timeUnix, 10)
|
|
|
- token = utils.MD5(openId) + utils.MD5(timeUnixStr)
|
|
|
- //新增session
|
|
|
- //{
|
|
|
- // session := new(models.CygxSession)
|
|
|
- // session.OpenId = openId
|
|
|
- // session.UserId = userId
|
|
|
- // session.CreatedTime = time.Now()
|
|
|
- // session.LastUpdatedTime = time.Now()
|
|
|
- // session.ExpireTime = time.Now().AddDate(0, 3, 0)
|
|
|
- // session.AccessToken = token
|
|
|
- // sessionErr := models.AddSession(session)
|
|
|
- // if err != nil {
|
|
|
- // err = errors.New("登录失败,新增用户session信息失败:" + sessionErr.Error())
|
|
|
- // return
|
|
|
- // }
|
|
|
- //}
|
|
|
- } else {
|
|
|
- token = tokenItem.AccessToken
|
|
|
- }
|
|
|
- fmt.Println("line 294 ", token)
|
|
|
-
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
//添加第三方用户(微信)记录
|
|
|
func AddUserRecord(openId, unionId, nickName, realName, province, city, country, headimgurl, sessionKey string, platform, sex, subscribe int) (userRecord *models.UserRecord, err error) {
|
|
|
find, err := models.GetUserRecordByOpenId(openId)
|