|
@@ -1,9 +1,12 @@
|
|
|
package permit_controller
|
|
package permit_controller
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "crypto/md5"
|
|
|
|
|
+ "encoding/hex"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
+ "fohow.com/apps/models/token_model"
|
|
|
"fohow.com/libs/lib_redis"
|
|
"fohow.com/libs/lib_redis"
|
|
|
- "strconv"
|
|
|
|
|
|
|
+ "fohow.com/libs/tool"
|
|
|
|
|
|
|
|
// "math/rand"
|
|
// "math/rand"
|
|
|
// "crypto/md5"
|
|
// "crypto/md5"
|
|
@@ -24,14 +27,12 @@ import (
|
|
|
// "fohow.com/apps/models/order_model"
|
|
// "fohow.com/apps/models/order_model"
|
|
|
// "fohow.com/apps/models/product_model"
|
|
// "fohow.com/apps/models/product_model"
|
|
|
// "fohow.com/apps/models/shop_model"
|
|
// "fohow.com/apps/models/shop_model"
|
|
|
- // "fohow.com/apps/models/sms_model"
|
|
|
|
|
|
|
+ "fohow.com/apps/models/sms_model"
|
|
|
"fohow.com/apps/models/user_model"
|
|
"fohow.com/apps/models/user_model"
|
|
|
// "fohow.com/apps/models/wx_gongzhonghao_model"
|
|
// "fohow.com/apps/models/wx_gongzhonghao_model"
|
|
|
"fohow.com/cache"
|
|
"fohow.com/cache"
|
|
|
// "fohow.com/libs/tool"
|
|
// "fohow.com/libs/tool"
|
|
|
"fohow.com/libs/wx_mp"
|
|
"fohow.com/libs/wx_mp"
|
|
|
- // "fohow.com/libs/wx_open"
|
|
|
|
|
- "fohow.com/libs/tool"
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
var (
|
|
@@ -53,11 +54,7 @@ func (self *PermitController) Init(ctx *context.Context, controllerName, actionN
|
|
|
//小程序授权
|
|
//小程序授权
|
|
|
func (self *PermitController) XcxAuthorize() {
|
|
func (self *PermitController) XcxAuthorize() {
|
|
|
params := self.GetString("userinfo")
|
|
params := self.GetString("userinfo")
|
|
|
-
|
|
|
|
|
- channel, _ := self.GetInt64("channel", 0)
|
|
|
|
|
- //beego.BeeLogger.Warn("XcxAuthorize userinfo: %s", params)
|
|
|
|
|
- inviteId, _ := self.GetInt64("invite_id", 0)
|
|
|
|
|
- first := false
|
|
|
|
|
|
|
+ cache, _ := self.GetBool("cache", false)
|
|
|
//beego.BeeLogger.Warn("XcxAuthorize inviteId: %d", inviteId)
|
|
//beego.BeeLogger.Warn("XcxAuthorize inviteId: %d", inviteId)
|
|
|
type UserInfo struct {
|
|
type UserInfo struct {
|
|
|
NickName string `json:"nickName"` // 用户的昵称
|
|
NickName string `json:"nickName"` // 用户的昵称
|
|
@@ -85,58 +82,70 @@ func (self *PermitController) XcxAuthorize() {
|
|
|
beego.BeeLogger.Error("XcxAuthorize err: %s, info:%s", err, info)
|
|
beego.BeeLogger.Error("XcxAuthorize err: %s, info:%s", err, info)
|
|
|
self.ReturnError(403, apps.ParamsError, "", nil)
|
|
self.ReturnError(403, apps.ParamsError, "", nil)
|
|
|
}
|
|
}
|
|
|
- //beego.BeeLogger.Warn("XcxAuthorize code: %s", info.Wxlogincode)
|
|
|
|
|
-
|
|
|
|
|
- sessionKey, _ := self.GetSession(apps.XcxSessionKey).(string)
|
|
|
|
|
- //beego.BeeLogger.Warn("sessionKey:%s", sessionKey)
|
|
|
|
|
- type EncryptedData struct {
|
|
|
|
|
- UnionId string `json:"unionId"`
|
|
|
|
|
- OpenId string `json:"openId"`
|
|
|
|
|
- NickName string `json:"nickName"`
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if sessionKey == "" {
|
|
|
|
|
- self.ReturnError(403, apps.UserNeedLogin, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- encryptedData := &EncryptedData{}
|
|
|
|
|
- encryptedData.OpenId, encryptedData.UnionId = GetXcxLoginInfo(info.Wxlogincode)
|
|
|
|
|
- /*
|
|
|
|
|
- pc := helpers.WxBizDataCrypt{AppID: beego.AppConfig.String("WxFohowXcxAppId"), SessionKey: sessionKey}
|
|
|
|
|
- beego.BeeLogger.Warn("EncryptedData:%s", info.EncryptedData)
|
|
|
|
|
- beego.BeeLogger.Warn("Iv:%s", info.Iv)
|
|
|
|
|
- result, err := pc.Decrypt(info.EncryptedData, info.Iv, true) //第三个参数解释: 需要返回 JSON 数据类型时 使用 true, 需要返回 map 数据类型时 使用 false
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- beego.BeeLogger.Error("xcx XcxAuthorize descrypt failed, err:%s", err)
|
|
|
|
|
- self.ReturnError(403, apps.XcxAuthorizeError, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- beego.BeeLogger.Warn("result:%v", result)
|
|
|
|
|
- encryptedData := &EncryptedData{}
|
|
|
|
|
|
|
+ wxUser := self.GetCurrentWxUser(cache)
|
|
|
|
|
+ user := self.GetCurrentUser(cache)
|
|
|
|
|
+ if wxUser == nil {
|
|
|
|
|
+ self.ReturnError(401, apps.WxUserNotExist, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+ //更新用户信息
|
|
|
|
|
+ wxUser.Nickname = info.UserInfo.NickName
|
|
|
|
|
+ wxUser.Sex = info.UserInfo.Gender
|
|
|
|
|
+ wxUser.City = info.UserInfo.City
|
|
|
|
|
+ wxUser.Province = info.UserInfo.Province
|
|
|
|
|
+ wxUser.Country = info.UserInfo.Country
|
|
|
|
|
+ wxUser.Save()
|
|
|
|
|
+ user.Nickname = wxUser.Nickname
|
|
|
|
|
+ user.Country = wxUser.Country
|
|
|
|
|
+ user.Province = wxUser.Province
|
|
|
|
|
+ user.City = wxUser.City
|
|
|
|
|
+ user.Sex = wxUser.Sex
|
|
|
|
|
+ user.Save()
|
|
|
|
|
|
|
|
- json.Unmarshal([]byte(result.(string)), encryptedData)*/
|
|
|
|
|
|
|
+ beego.BeeLogger.Warn("XcxAuthorize wxUser after save() Nickname:%s, Sex:%s, City:%s, Province:%s, Country:%s ", wxUser.Nickname, wxUser.Sex, wxUser.City, wxUser.Province, wxUser.Country)
|
|
|
|
|
|
|
|
- if encryptedData.UnionId == "" || encryptedData.OpenId == "" {
|
|
|
|
|
- beego.BeeLogger.Error("encryptedData:%v", encryptedData)
|
|
|
|
|
- self.ReturnError(403, apps.UserAuthorizeFailed, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- wxUser := user_model.GetWxUserByUnionid(encryptedData.UnionId, false)
|
|
|
|
|
- ip := self.Ctx.Input.IP()
|
|
|
|
|
- var user *user_model.User
|
|
|
|
|
- if wxUser != nil && wxUser.UserId > 0 {
|
|
|
|
|
- //查找已注册会员
|
|
|
|
|
- user = user_model.GetUserById(wxUser.UserId, false)
|
|
|
|
|
- } else {
|
|
|
|
|
- //注册会员
|
|
|
|
|
- user = user_model.Create("", ip)
|
|
|
|
|
|
|
+ // 如果微信用户已绑定手机,则找出userId,并且赋值给session[userId]
|
|
|
|
|
+ if wxUser != nil {
|
|
|
|
|
+ wxUser.UploadHead(info.UserInfo.AvatarUrl)
|
|
|
|
|
+ user.CopyWxUserHead(wxUser.Head)
|
|
|
}
|
|
}
|
|
|
- if user == nil {
|
|
|
|
|
- self.ReturnError(403, apps.RegisterUserError, "", nil)
|
|
|
|
|
|
|
+ type Ret struct {
|
|
|
|
|
+ Result bool `json:"result"`
|
|
|
|
|
+ WxUser *user_model.WxUser `json:"wx_user"`
|
|
|
}
|
|
}
|
|
|
|
|
+ self.Data["json"] = &Ret{WxUser: wxUser, Result: true}
|
|
|
|
|
+ self.ServeJSON()
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
+//小程序登录
|
|
|
|
|
+func (self *PermitController) XcxLogin() {
|
|
|
|
|
+ code := self.GetString("code")
|
|
|
|
|
+ inviteId, _ := self.GetInt64("invite_id", 0)
|
|
|
|
|
+ //beego.BeeLogger.Warn("XcxLogin code=%s", code)
|
|
|
|
|
+ if code == "" {
|
|
|
|
|
+ self.ReturnError(403, apps.ParamsRequired, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+ appId := beego.AppConfig.String("WxFohowXcxAppId")
|
|
|
|
|
+ appSecret := beego.AppConfig.String("WxFohowXcxAppSecret")
|
|
|
|
|
+ key := wx_mp.GetXcxSessionKey(appId, appSecret, code)
|
|
|
|
|
+ if key == nil {
|
|
|
|
|
+ self.ReturnError(403, apps.XcxGetSessionKeyError, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+ //beego.BeeLogger.Warn("XcxLogin key=%s", key)
|
|
|
|
|
+ wxUser := user_model.GetWxUserByUnionid(key.Unionid, false)
|
|
|
if wxUser != nil {
|
|
if wxUser != nil {
|
|
|
- wxUser.Openid = encryptedData.OpenId
|
|
|
|
|
|
|
+ if len(wxUser.Head) > 0 {
|
|
|
|
|
+ wxUser.FullHead = self.GetFullImgUrl(wxUser.Head)
|
|
|
|
|
+ }
|
|
|
|
|
+ self.SetSession(apps.SessionWxUserKey, wxUser.Id)
|
|
|
|
|
+ self.SetSession(apps.SessionUserKey, wxUser.UserId)
|
|
|
} else {
|
|
} else {
|
|
|
- //首次授权
|
|
|
|
|
- first = true
|
|
|
|
|
|
|
+ //注册会员
|
|
|
|
|
+ ip := self.Ctx.Input.IP()
|
|
|
|
|
+ var user *user_model.User
|
|
|
|
|
+ //注册会员
|
|
|
|
|
+ user = user_model.Create("", ip)
|
|
|
|
|
+
|
|
|
|
|
+ //注册微信会员
|
|
|
introUserId := int64(1)
|
|
introUserId := int64(1)
|
|
|
depart := int64(0)
|
|
depart := int64(0)
|
|
|
if inviteId == int64(0) {
|
|
if inviteId == int64(0) {
|
|
@@ -153,47 +162,34 @@ func (self *PermitController) XcxAuthorize() {
|
|
|
}
|
|
}
|
|
|
depart = inviter.Depart
|
|
depart = inviter.Depart
|
|
|
}
|
|
}
|
|
|
- wxUser = new(user_model.WxUser).QuickCreate(encryptedData.OpenId, encryptedData.UnionId, ip, channel, time.Now().Unix(), user.Id, inviteId, introUserId, depart)
|
|
|
|
|
- }
|
|
|
|
|
- user.Nickname = wxUser.Nickname
|
|
|
|
|
- user.Country = wxUser.Country
|
|
|
|
|
- user.Province = wxUser.Province
|
|
|
|
|
- user.City = wxUser.City
|
|
|
|
|
- user.Sex = wxUser.Sex
|
|
|
|
|
- //参数第一,cookie第二
|
|
|
|
|
- cId, _ := strconv.ParseInt(self.Ctx.GetCookie("sign_up_channel"), 10, 64)
|
|
|
|
|
- user.SignupChannelId = cId
|
|
|
|
|
- user.Save()
|
|
|
|
|
- if user != nil {
|
|
|
|
|
- self.SetSession(apps.SessionUserKey, user.Id)
|
|
|
|
|
- }
|
|
|
|
|
- //wxUser.UserId = user.Id
|
|
|
|
|
- wxUser.Nickname = info.UserInfo.NickName
|
|
|
|
|
- wxUser.Sex = info.UserInfo.Gender
|
|
|
|
|
- wxUser.City = info.UserInfo.City
|
|
|
|
|
- wxUser.Province = info.UserInfo.Province
|
|
|
|
|
- wxUser.Country = info.UserInfo.Country
|
|
|
|
|
- // beego.BeeLogger.Warn("XcxAuthorize wxUser before save() Nickname:%s, Sex:%s, City:%s, Province:%s, Country:%s ", wxUser.Nickname, wxUser.Sex, wxUser.City, wxUser.Province, wxUser.Country)
|
|
|
|
|
- wxUser.Save()
|
|
|
|
|
- beego.BeeLogger.Warn("XcxAuthorize wxUser after save() Nickname:%s, Sex:%s, City:%s, Province:%s, Country:%s ", wxUser.Nickname, wxUser.Sex, wxUser.City, wxUser.Province, wxUser.Country)
|
|
|
|
|
-
|
|
|
|
|
- if wxUser != nil {
|
|
|
|
|
|
|
+ wxUser = new(user_model.WxUser).QuickCreate(key.Openid, key.Unionid, ip, user.Id, inviteId, introUserId, depart)
|
|
|
self.SetSession(apps.SessionWxUserKey, wxUser.Id)
|
|
self.SetSession(apps.SessionWxUserKey, wxUser.Id)
|
|
|
- }
|
|
|
|
|
- //赠送积分
|
|
|
|
|
- if first {
|
|
|
|
|
- //go wxUser.UploadHead(info.UserInfo.AvatarUrl)
|
|
|
|
|
- wxUser.UploadHead(info.UserInfo.AvatarUrl)
|
|
|
|
|
- go user.XcxPermitUploadHead(info.UserInfo.AvatarUrl)
|
|
|
|
|
|
|
+ self.SetSession(apps.SessionUserKey, wxUser.UserId)
|
|
|
|
|
+ //赠送积分
|
|
|
go helpers.SendCent(wxUser.Id, inviteId)
|
|
go helpers.SendCent(wxUser.Id, inviteId)
|
|
|
}
|
|
}
|
|
|
- // 如果微信用户已绑定手机,则找出userId,并且赋值给session[userId]
|
|
|
|
|
- if wxUser != nil && wxUser.UserId > 0 {
|
|
|
|
|
- user := user_model.GetUserById(wxUser.UserId, false)
|
|
|
|
|
- user.CopyWxUserHead(wxUser.Head)
|
|
|
|
|
- self.SetSession(apps.SessionUserKey, wxUser.UserId)
|
|
|
|
|
|
|
+ //self.SetSession(apps.XcxSessionKey, key.SessionKey)
|
|
|
|
|
+ sessionKey := lib_redis.GetKeySessionKey(wxUser.Id)
|
|
|
|
|
+ lib_redis.SetRedisValue(sessionKey, key.SessionKey, time.Hour*10)
|
|
|
|
|
+ beego.BeeLogger.Warn("XcxLogin SessionKey=%s", key.SessionKey)
|
|
|
|
|
+ if self.CruSession == nil {
|
|
|
|
|
+ self.ReturnError(401, apps.NoExist, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+ //更新会员token
|
|
|
|
|
+ var jwtUser token_model.JwtUser
|
|
|
|
|
+ jwtUser.Id = wxUser.Id
|
|
|
|
|
+ token, err := token_model.GenerateToken(&jwtUser, 0)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ self.ReturnError(401, apps.TokenError, "", nil)
|
|
|
}
|
|
}
|
|
|
- self.Data["json"] = encryptedData
|
|
|
|
|
|
|
+
|
|
|
|
|
+ sId := self.CruSession.SessionID()
|
|
|
|
|
+ type Ret struct {
|
|
|
|
|
+ TokenKey string `json:"token"`
|
|
|
|
|
+ SessionKey string `json:"session_key"`
|
|
|
|
|
+ WxUser *user_model.WxUser `json:"wx_user"`
|
|
|
|
|
+ }
|
|
|
|
|
+ self.Data["json"] = &Ret{SessionKey: sId, WxUser: wxUser, TokenKey: token}
|
|
|
self.ServeJSON()
|
|
self.ServeJSON()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -221,124 +217,47 @@ func (self *PermitController) SaveWxuserInfo() {
|
|
|
self.ReturnError(403, apps.ParamsError, "", nil)
|
|
self.ReturnError(403, apps.ParamsError, "", nil)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- wxUId := self.GetCurrentWxUserId()
|
|
|
|
|
- wxUser := user_model.GetWxUserById(wxUId, true)
|
|
|
|
|
|
|
+ //wxUId := self.GetCurrentWxUserId()
|
|
|
|
|
+ wxUId := self.GetCurrentUserIdByToken()
|
|
|
|
|
+
|
|
|
|
|
+ beego.BeeLogger.Info("SaveWxuserInfo wxUId:%d", wxUId)
|
|
|
|
|
|
|
|
|
|
+ wxUser := user_model.GetWxUserById(wxUId, true)
|
|
|
if wxUser == nil {
|
|
if wxUser == nil {
|
|
|
self.ReturnError(403, apps.WxUserInfoError, "", nil)
|
|
self.ReturnError(403, apps.WxUserInfoError, "", nil)
|
|
|
}
|
|
}
|
|
|
- wxUser.UploadHead(info.AvatarUrl)
|
|
|
|
|
|
|
+ headPath := wxUser.UploadHead(info.AvatarUrl)
|
|
|
|
|
+
|
|
|
|
|
+ //更新用户信息
|
|
|
|
|
+ wxUser.Nickname = info.NickName
|
|
|
|
|
+ wxUser.Sex = info.Gender
|
|
|
|
|
+ wxUser.City = info.City
|
|
|
|
|
+ wxUser.Province = info.Province
|
|
|
|
|
+ wxUser.Country = info.Country
|
|
|
|
|
+ wxUser.Save()
|
|
|
|
|
+
|
|
|
|
|
+ user := user_model.GetUserById(wxUser.UserId, true)
|
|
|
|
|
+ if user != nil {
|
|
|
|
|
+ user.Nickname = wxUser.Nickname
|
|
|
|
|
+ user.Country = wxUser.Country
|
|
|
|
|
+ user.Province = wxUser.Province
|
|
|
|
|
+ user.City = wxUser.City
|
|
|
|
|
+ user.Sex = wxUser.Sex
|
|
|
|
|
+ user.Save()
|
|
|
|
|
+ go user.CopyWxUserHead(wxUser.Head)
|
|
|
|
|
+ }
|
|
|
|
|
+ //消除user,wxuser缓存
|
|
|
|
|
+ go wxUser.CleanCache()
|
|
|
|
|
+ headImag := tool.GetCdnFullImgUrl(headPath)
|
|
|
|
|
+ //beego.BeeLogger.Info("save_wx_user_info err: %v ", wxUser)
|
|
|
type Ret struct {
|
|
type Ret struct {
|
|
|
Result bool `json:"result"`
|
|
Result bool `json:"result"`
|
|
|
Head string `json:"head"`
|
|
Head string `json:"head"`
|
|
|
}
|
|
}
|
|
|
- headImag := tool.GetCdnFullImgUrl(wxUser.Head)
|
|
|
|
|
- //beego.BeeLogger.Info("save_wx_user_info err: %v ", wxUser)
|
|
|
|
|
-
|
|
|
|
|
self.Data["json"] = &Ret{Result: true, Head: headImag}
|
|
self.Data["json"] = &Ret{Result: true, Head: headImag}
|
|
|
self.ServeJSON()
|
|
self.ServeJSON()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//小程序登录
|
|
|
|
|
-func (self *PermitController) XcxLogin() {
|
|
|
|
|
- code := self.GetString("code")
|
|
|
|
|
-
|
|
|
|
|
- //beego.BeeLogger.Warn("XcxLogin code=%s", code)
|
|
|
|
|
-
|
|
|
|
|
- if code == "" {
|
|
|
|
|
- self.ReturnError(403, apps.ParamsRequired, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- appId := beego.AppConfig.String("WxFohowXcxAppId")
|
|
|
|
|
- appSecret := beego.AppConfig.String("WxFohowXcxAppSecret")
|
|
|
|
|
- key := wx_mp.GetXcxSessionKey(appId, appSecret, code)
|
|
|
|
|
- if key == nil {
|
|
|
|
|
- self.ReturnError(403, apps.XcxGetSessionKeyError, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- //beego.BeeLogger.Warn("XcxLogin key=%s", key)
|
|
|
|
|
- //beego.BeeLogger.Warn("XcxLogin key=%s, key.Openid=%s", key, key.Openid)
|
|
|
|
|
- //beego.BeeLogger.Warn("XcxLogin key=%s, key.Unionid=%s", key, key.Unionid)
|
|
|
|
|
-
|
|
|
|
|
- wxUser := user_model.GetByOpenid(key.Openid, false)
|
|
|
|
|
- //beego.BeeLogger.Warn("XcxLogin key=[%s], key.Openid=[%s], wxUser= [%s]", key, key.Openid, wxUser)
|
|
|
|
|
-
|
|
|
|
|
- if wxUser != nil {
|
|
|
|
|
- wxUser.FullHead = self.GetFullImgUrl(wxUser.Head)
|
|
|
|
|
- self.SetSession(apps.SessionWxUserKey, wxUser.Id)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 如果微信用户已绑定手机,则找出userId,并且赋值给session[userId]
|
|
|
|
|
- if wxUser != nil && wxUser.UserId > 0 {
|
|
|
|
|
- self.SetSession(apps.SessionUserKey, wxUser.UserId)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- self.SetSession(apps.XcxSessionKey, key.SessionKey)
|
|
|
|
|
- //beego.BeeLogger.Warn("XcxLogin SessionKey=%s", key.SessionKey)
|
|
|
|
|
- if self.CruSession == nil {
|
|
|
|
|
- self.ReturnError(200, apps.NoExist, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- //设置code对应的 redis openId unionId 值
|
|
|
|
|
- openid_key := lib_redis.GetOpenIdRedisKey(code)
|
|
|
|
|
- unionid_key := lib_redis.GetUnionIdRedisKey(code)
|
|
|
|
|
- lib_redis.SetRedisValue(openid_key, key.Openid, time.Duration(30*60)*time.Second)
|
|
|
|
|
- lib_redis.SetRedisValue(unionid_key, key.Unionid, time.Duration(30*60)*time.Second)
|
|
|
|
|
-
|
|
|
|
|
- sId := self.CruSession.SessionID()
|
|
|
|
|
- // beego.BeeLogger.Warn("XcxLogin sId=%s", sId)
|
|
|
|
|
- type Ret struct {
|
|
|
|
|
- SessionKey string `json:"session_key"`
|
|
|
|
|
- WxUser *user_model.WxUser `json:"wx_user"`
|
|
|
|
|
- }
|
|
|
|
|
- self.Data["json"] = &Ret{SessionKey: sId, WxUser: wxUser}
|
|
|
|
|
-
|
|
|
|
|
- self.ServeJSON()
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-//小程序登录
|
|
|
|
|
-func GetXcxLoginInfo(code string) (openId, unionId string) {
|
|
|
|
|
- openid_key := lib_redis.GetOpenIdRedisKey(code)
|
|
|
|
|
- unionid_key := lib_redis.GetUnionIdRedisKey(code)
|
|
|
|
|
-
|
|
|
|
|
- _, openid := lib_redis.GetSimpleValue(openid_key)
|
|
|
|
|
- _, unionid := lib_redis.GetSimpleValue(unionid_key)
|
|
|
|
|
-
|
|
|
|
|
- return openid, unionid
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-//生成订单ID
|
|
|
|
|
-func createUnionId(prefix string) string {
|
|
|
|
|
- n := time.Now().Format("20060102150405")
|
|
|
|
|
- u := uuid.NewV4().String()
|
|
|
|
|
- c := strings.Split(u, "-")
|
|
|
|
|
- oId := strings.ToUpper(fmt.Sprintf("%s%s%s", prefix, n, c[0]))
|
|
|
|
|
- beego.BeeLogger.Info("createUnionId=%s", oId)
|
|
|
|
|
- return oId
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func (self *PermitController) XcxTest() {
|
|
|
|
|
- wxUser := self.GetCurrentWxUser(true)
|
|
|
|
|
- self.Data["json"] = wxUser
|
|
|
|
|
- self.ServeJSON()
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// // 统一登录路径
|
|
|
|
|
-// // 该接口尽量不被前端调用,供服务器开发者使用
|
|
|
|
|
-// func (self *PermitController) Login() {
|
|
|
|
|
-// cb := self.GetString("cb")
|
|
|
|
|
-// url := ""
|
|
|
|
|
-// if self.IsWxClient() {
|
|
|
|
|
-// url = fmt.Sprintf("%s/login/mp?cb=%s", beego.AppConfig.String("ApiHost"), cb)
|
|
|
|
|
-// }
|
|
|
|
|
-// self.Redirect(url, 302)
|
|
|
|
|
-// return
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// // 退出登录
|
|
|
|
|
-// func (self *PermitController) Logout() {
|
|
|
|
|
-// self.DelSession(apps.SessionUserKey)
|
|
|
|
|
-// self.DelSession(apps.SessionWxUserKey)
|
|
|
|
|
-// self.ReturnError(200, apps.HasLogout, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
//公众号静默授权回调
|
|
//公众号静默授权回调
|
|
|
func (self *PermitController) AfterWxMpAuth() {
|
|
func (self *PermitController) AfterWxMpAuth() {
|
|
|
// beego.BeeLogger.Warn("AfterWxMpAuth........")
|
|
// beego.BeeLogger.Warn("AfterWxMpAuth........")
|
|
@@ -386,52 +305,6 @@ func (self *PermitController) AfterWxMpAuth() {
|
|
|
self.ServeJSON()
|
|
self.ServeJSON()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// //公众号静默授权
|
|
|
|
|
-// func (self *PermitController) WxMpAuth() {
|
|
|
|
|
-// // beego.BeeLogger.Warn("WxMpAuth.......")
|
|
|
|
|
-// if !self.IsWxClient() {
|
|
|
|
|
-// self.ReturnError(403, apps.NotWeixinClient, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-// _id := self.Ctx.Input.Param(":id")
|
|
|
|
|
-// cb := self.GetString("cb")
|
|
|
|
|
-// id, _ := strconv.ParseInt(_id, 10, 64)
|
|
|
|
|
-// gzh := wx_gongzhonghao_model.GetGZHById(id, true)
|
|
|
|
|
-// if gzh == nil {
|
|
|
|
|
-// self.ReturnError(403, apps.GongZhongHaoNoExist, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-// appId := gzh.AppId
|
|
|
|
|
-// u := strings.Split(uuid.NewV4().String(), "-")[0]
|
|
|
|
|
-// state := fmt.Sprintf("AuthCb[%s]", u)
|
|
|
|
|
-// cache.Cache.Put(state, cb, 60*time.Second)
|
|
|
|
|
-// redirectURI := fmt.Sprintf("%s/auth/mp/%d/after",
|
|
|
|
|
-// beego.AppConfig.String("ApiHost"), gzh.Id)
|
|
|
|
|
-// scope := "snsapi_base"
|
|
|
|
|
-// url := wx_mp.AuthCodeURL(appId, redirectURI, scope, state)
|
|
|
|
|
-// // beego.BeeLogger.Warn("wx mp auth, redirect url: %s", url)
|
|
|
|
|
-// self.Redirect(url, 302)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// //check是否授权过某个公众号
|
|
|
|
|
-// func (self *PermitController) CheckWxAuth() {
|
|
|
|
|
-// _gId := self.Ctx.Input.Param(":id")
|
|
|
|
|
-// gId, _ := strconv.ParseInt(_gId, 10, 64)
|
|
|
|
|
-// gzh := wx_gongzhonghao_model.GetGZHById(gId, true)
|
|
|
|
|
-// type Ret struct {
|
|
|
|
|
-// IsAuth int64 `json:"is_auth"`
|
|
|
|
|
-// }
|
|
|
|
|
-// var auth int64 = 0
|
|
|
|
|
-// wxUser := self.GetCurrentWxUser(true)
|
|
|
|
|
-// if gzh != nil {
|
|
|
|
|
-// authWxUser := user_model.GetAuthWxUserByMpIdAndUnionId(gzh.WxHao, wxUser.Unionid, false)
|
|
|
|
|
-// if authWxUser != nil {
|
|
|
|
|
-// auth = 1
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// // beego.BeeLogger.Warn("check auth: %v", auth)
|
|
|
|
|
-// self.Data["json"] = &Ret{IsAuth: auth}
|
|
|
|
|
-// self.ServeJSON()
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
// 微信公众号平台登录
|
|
// 微信公众号平台登录
|
|
|
func (self *PermitController) WxMpLogin() {
|
|
func (self *PermitController) WxMpLogin() {
|
|
|
cb := self.GetString("cb")
|
|
cb := self.GetString("cb")
|
|
@@ -710,250 +583,43 @@ func (self *PermitController) Logout() {
|
|
|
self.ReturnError(200, apps.HasLogout, "", nil)
|
|
self.ReturnError(200, apps.HasLogout, "", nil)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// // 微信开放平台登录
|
|
|
|
|
-// func (self *PermitController) WxOpenLogin() {
|
|
|
|
|
-// cb := self.GetString("cb")
|
|
|
|
|
-// u := strings.Split(uuid.NewV4().String(), "-")[0]
|
|
|
|
|
-// state := fmt.Sprintf("loginCb[%s]", u)
|
|
|
|
|
-// cache.Cache.Put(state, cb, 60*time.Second)
|
|
|
|
|
-// appId := beego.AppConfig.String("WxOpenAppId")
|
|
|
|
|
-// redirectURI := fmt.Sprintf("%s/login/open/after",
|
|
|
|
|
-// beego.AppConfig.String("ApiHost"))
|
|
|
|
|
-// url := wx_open.AuthCodeURL(appId, redirectURI, "snsapi_login", state)
|
|
|
|
|
-// self.Redirect(url, 302)
|
|
|
|
|
-// return
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// //微信开放平台登录
|
|
|
|
|
-// func (self *PermitController) AfterWxOpenLogin() {
|
|
|
|
|
-// scope := "snsapi_login"
|
|
|
|
|
-// code := self.GetString("code")
|
|
|
|
|
-// state := self.GetString("state")
|
|
|
|
|
-// a := beego.AppConfig.String("WxOpenAppId")
|
|
|
|
|
-// s := beego.AppConfig.String("WxOpenAppSecret")
|
|
|
|
|
-// redirectURI := fmt.Sprintf("%s/after_wx_open_login",
|
|
|
|
|
-// beego.AppConfig.String("ApiHost"))
|
|
|
|
|
-// token, err := wx_open.AuthExchangeToken(code, a, s, redirectURI, scope)
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// self.ReturnError(403, apps.NetworkBusy, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-// openOpenid := token.OpenId
|
|
|
|
|
-// unionId := token.UnionId
|
|
|
|
|
-// // 这里不能取缓存数据,因为UserId这个字段在外部有可能已被赋值
|
|
|
|
|
-// wxUser := user_model.GetWxUserByUnionid(unionId, false)
|
|
|
|
|
-// if wxUser == nil {
|
|
|
|
|
-// info, err := wx_open.AuthUserInfo(token.AccessToken, redirectURI, scope, openOpenid, a, s)
|
|
|
|
|
-// if err == nil {
|
|
|
|
|
-// ip := self.Ctx.Input.IP()
|
|
|
|
|
-// wxUser = new(user_model.WxUser).Create("", openOpenid, token.UnionId, info.Nickname,
|
|
|
|
|
-// info.City, info.Country, info.Province, ip, int64(info.Sex), 1, time.Now().Unix())
|
|
|
|
|
-// //上传头像至alioss
|
|
|
|
|
-// go wxUser.UploadHead(info.HeadImageURL)
|
|
|
|
|
-// }
|
|
|
|
|
-// } else {
|
|
|
|
|
-// if wxUser.OpenOpenid != openOpenid {
|
|
|
|
|
-// wxUser.OpenOpenid = openOpenid
|
|
|
|
|
-// go wxUser.UpdateField("OpenOpenid")
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// self.SetSession(apps.SessionWxUserKey, wxUser.Id)
|
|
|
|
|
-// // 如果微信用户已绑定手机,则找出userId,并且赋值给session[userId]
|
|
|
|
|
-// if wxUser.UserId > 0 {
|
|
|
|
|
-// self.SetSession(apps.SessionUserKey, wxUser.UserId)
|
|
|
|
|
-// }
|
|
|
|
|
-// if cbUrl, ok := cache.Cache.Get(state).(string); ok {
|
|
|
|
|
-// if cbUrl == "" {
|
|
|
|
|
-// if wxUser.UserId <= 0 {
|
|
|
|
|
-// self.Redirect(fmt.Sprintf("%s/user/binding/state", beego.AppConfig.String("WWWHost")), 302)
|
|
|
|
|
-// return
|
|
|
|
|
-
|
|
|
|
|
-// }
|
|
|
|
|
-// self.Redirect(beego.AppConfig.String("WWWHost"), 302)
|
|
|
|
|
-// return
|
|
|
|
|
-// }
|
|
|
|
|
-// self.Redirect(cbUrl, 302)
|
|
|
|
|
-// return
|
|
|
|
|
-// } else {
|
|
|
|
|
-// self.Redirect(beego.AppConfig.String("WWWHost"), 302)
|
|
|
|
|
-// return
|
|
|
|
|
-// }
|
|
|
|
|
-// self.ReturnError(403, apps.NetworkBusy, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// //PC端手机号码登录
|
|
|
|
|
-// func (self *PermitController) TelLogin() {
|
|
|
|
|
-// //防止用户先登录微信user,未绑定手机,同时又使用tel登录,默认清除wxuser的session
|
|
|
|
|
-// self.DelSession(apps.SessionWxUserKey)
|
|
|
|
|
-
|
|
|
|
|
-// tel := self.GetString("tel")
|
|
|
|
|
-// pwd := self.GetString("pwd")
|
|
|
|
|
-
|
|
|
|
|
-// user := user_model.GetByTel(tel, false)
|
|
|
|
|
-// signUpURL := fmt.Sprintf("%s/v1/signup", beego.AppConfig.String("ApiHost"))
|
|
|
|
|
-// if user == nil {
|
|
|
|
|
-// self.ReturnError(403, apps.UserNotExist, signUpURL, nil)
|
|
|
|
|
-// }
|
|
|
|
|
-// md5Ctx := md5.New()
|
|
|
|
|
-// md5Ctx.Write([]byte(pwd))
|
|
|
|
|
-// cipherStr := md5Ctx.Sum(nil)
|
|
|
|
|
-// md5Pwd := hex.EncodeToString(cipherStr)
|
|
|
|
|
-
|
|
|
|
|
-// if user.Pwd != md5Pwd {
|
|
|
|
|
-// self.ReturnError(403, apps.LoginPasswordError, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-// self.SetSession(apps.SessionUserKey, user.Id)
|
|
|
|
|
-// // 找出微信用户
|
|
|
|
|
-// wxUser := user_model.GetWxUserByUserId(user.Id, false)
|
|
|
|
|
-// if wxUser != nil {
|
|
|
|
|
-// self.SetSession(apps.SessionWxUserKey, wxUser.Id)
|
|
|
|
|
-// }
|
|
|
|
|
-// // self.Data["json"] = "ok"
|
|
|
|
|
-// self.ServeJSON()
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// //使用key登录,key通过GenerateLoginKey生成
|
|
|
|
|
-// func (self *PermitController) KeyLogin() {
|
|
|
|
|
-// //不支持微信端
|
|
|
|
|
-// if self.IsWxClient() {
|
|
|
|
|
-// self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-// key := self.Ctx.Input.Param(":key")
|
|
|
|
|
-// uId, _ := self.GetInt64("user_id")
|
|
|
|
|
-
|
|
|
|
|
-// if key == "" || uId == 0 {
|
|
|
|
|
-// self.ReturnError(403, apps.ParamsRequired, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// k := cache.GetKey(cache.WapAutoLoginKey, uId)
|
|
|
|
|
-// //校验key
|
|
|
|
|
-// if s, ok := cache.Cache.Get(k).(string); ok {
|
|
|
|
|
-// // beego.BeeLogger.Warn("11111111, k:%s, s: %s, key: %s, uId: %d", k, s, key, uId)
|
|
|
|
|
-// if s == key {
|
|
|
|
|
-// // self.DelSession(apps.SessionUserKey)
|
|
|
|
|
-// self.SetSession(apps.SessionUserKey, uId)
|
|
|
|
|
-// //销毁缓存
|
|
|
|
|
-// cache.Cache.Delete(k)
|
|
|
|
|
-// } else {
|
|
|
|
|
-// self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-// } else {
|
|
|
|
|
-// self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// // self.Data["json"] = "ok"
|
|
|
|
|
-// self.ServeJSON()
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// //PC端注册
|
|
|
|
|
-// func (self *PermitController) SignUp() {
|
|
|
|
|
-// code := self.GetString("code")
|
|
|
|
|
-// tel := self.GetString("tel")
|
|
|
|
|
-// k := fmt.Sprintf("%s%s", sms_model.SIGN_UP, tel)
|
|
|
|
|
-// if cacheCode, ok := cache.Cache.Get(k).(string); ok {
|
|
|
|
|
-// if code != cacheCode {
|
|
|
|
|
-// self.ReturnError(403, apps.TelCodesError, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-// } else {
|
|
|
|
|
-// //验证码过期
|
|
|
|
|
-// self.ReturnError(403, apps.TelCodesExpired, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// user := user_model.GetByTel(tel, false)
|
|
|
|
|
-// if user == nil {
|
|
|
|
|
-// loginPwd := tool.Get8Uuid()
|
|
|
|
|
-// md5Ctx := md5.New()
|
|
|
|
|
-// md5Ctx.Write([]byte(loginPwd))
|
|
|
|
|
-// cipherStr := md5Ctx.Sum(nil)
|
|
|
|
|
-// md5Pwd := hex.EncodeToString(cipherStr)
|
|
|
|
|
-// ip := self.Ctx.Input.IP()
|
|
|
|
|
-// user = user_model.Create(tel, md5Pwd, ip)
|
|
|
|
|
-// // 注册渠道处理
|
|
|
|
|
-// cId, _ := strconv.ParseInt(self.Ctx.GetCookie("sign_up_channel"), 10, 64)
|
|
|
|
|
-// channel := user_model.GetSignUpChannelById(cId, true)
|
|
|
|
|
-// if channel != nil {
|
|
|
|
|
-// user.SignupChannelId = cId
|
|
|
|
|
-// user.Save()
|
|
|
|
|
-// // wpsvip注册的用户,因为真功夫项目的,需要通知赠送稻米
|
|
|
|
|
-// if cId == 8 {
|
|
|
|
|
-// key1 := beego.AppConfig.String("CookieWpsVipUId")
|
|
|
|
|
-// key2 := beego.AppConfig.String("CookieWpsVipExtra")
|
|
|
|
|
-// wpsUserId, _ := strconv.ParseInt(self.Ctx.GetCookie(key1), 10, 64)
|
|
|
|
|
-// extra := self.Ctx.GetCookie(key2)
|
|
|
|
|
-// go wps.Reward(wpsUserId, extra, wps.OT_ZGF_ZHUC)
|
|
|
|
|
-// go wps_user_model.CreateWpsUser(wpsUserId, user.Id, 0, extra)
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// sign, template, action := sms_model.GetAliMsgContent(sms_model.LOGIN_PWD)
|
|
|
|
|
-// go sms_model.SendSmsWithAli([]string{tel}, sign, template, action, loginPwd)
|
|
|
|
|
-// } else {
|
|
|
|
|
-// self.ReturnError(403, apps.PhoneExist, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// self.SetSession(apps.SessionUserKey, user.Id)
|
|
|
|
|
-// //如果是体验金专题页面点击过来的,也送
|
|
|
|
|
-// key := beego.AppConfig.String("TYJName")
|
|
|
|
|
-// c := self.Ctx.GetCookie(key)
|
|
|
|
|
-
|
|
|
|
|
-// if c != "" {
|
|
|
|
|
-// id, err := strconv.ParseInt(c, 10, 64)
|
|
|
|
|
-// if err == nil {
|
|
|
|
|
-// trialInfo := trial_coin_model.GetTrialCoinById(id, true)
|
|
|
|
|
-// if trialInfo != nil && trialInfo.Deadline.Unix() >= time.Now().Unix() {
|
|
|
|
|
-// new(trial_coin_model.TrialCoinOrder).Create(user.Id, trialInfo.Id, trialInfo.Amount)
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// self.Data["json"] = user_model.User{Tel: tel}
|
|
|
|
|
-// self.ServeJSON()
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// //忘记密码
|
|
|
|
|
-// func (self *PermitController) ResetPwd() {
|
|
|
|
|
-// code := self.GetString("code")
|
|
|
|
|
-// tel := self.GetString("tel")
|
|
|
|
|
-// pwd := self.GetString("pwd")
|
|
|
|
|
-// confirmedPwd := self.GetString("confirmed_pwd")
|
|
|
|
|
-// if pwd != confirmedPwd {
|
|
|
|
|
-// self.ReturnError(403, apps.PasswordError, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// lengthPwd := len(pwd)
|
|
|
|
|
-// if lengthPwd < 6 || lengthPwd > 20 {
|
|
|
|
|
-// self.ReturnError(403, apps.PasswordLengthError, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// k := fmt.Sprintf("%s%s", sms_model.RESET_PWD, tel)
|
|
|
|
|
-// if cacheCode, ok := cache.Cache.Get(k).(string); ok {
|
|
|
|
|
-// if code != cacheCode {
|
|
|
|
|
-// self.ReturnError(403, apps.TelCodesError, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-// } else {
|
|
|
|
|
-// //验证码过期
|
|
|
|
|
-// self.ReturnError(403, apps.TelCodesExpired, "", nil)
|
|
|
|
|
-// }
|
|
|
|
|
-// md5Ctx := md5.New()
|
|
|
|
|
-// md5Ctx.Write([]byte(pwd))
|
|
|
|
|
-// cipherStr := md5Ctx.Sum(nil)
|
|
|
|
|
-// md5Pwd := hex.EncodeToString(cipherStr)
|
|
|
|
|
-
|
|
|
|
|
-// user := user_model.GetByTel(tel, false)
|
|
|
|
|
-// if user == nil {
|
|
|
|
|
-// self.ReturnError(403, apps.UserNotExist, "", nil)
|
|
|
|
|
-// } else {
|
|
|
|
|
-// user.Pwd = md5Pwd
|
|
|
|
|
-// user.Save()
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// self.Data["json"] = user_model.User{Tel: tel}
|
|
|
|
|
-// self.ServeJSON()
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// func createXkUser(uid, openid string) {
|
|
|
|
|
-// if uid == "" || openid == "" {
|
|
|
|
|
-// return
|
|
|
|
|
-// }
|
|
|
|
|
-// url := fmt.Sprintf("http://api.xikego.com/v1/createwxuser/superd5c/%s/%s", uid, openid)
|
|
|
|
|
-// tool.PostJSON(url, nil)
|
|
|
|
|
-// return
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+//忘记密码
|
|
|
|
|
+func (self *PermitController) ResetPwd() {
|
|
|
|
|
+ code := self.GetString("code")
|
|
|
|
|
+ tel := self.GetString("tel")
|
|
|
|
|
+ pwd := self.GetString("pwd")
|
|
|
|
|
+ confirmedPwd := self.GetString("confirmed_pwd")
|
|
|
|
|
+ if pwd != confirmedPwd {
|
|
|
|
|
+ self.ReturnError(403, apps.PasswordError, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ lengthPwd := len(pwd)
|
|
|
|
|
+ if lengthPwd < 6 || lengthPwd > 20 {
|
|
|
|
|
+ self.ReturnError(403, apps.PasswordLengthError, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ k := fmt.Sprintf("%s%s", sms_model.RESET_PWD, tel)
|
|
|
|
|
+ if cacheCode, ok := cache.Cache.Get(k).(string); ok {
|
|
|
|
|
+ if code != cacheCode {
|
|
|
|
|
+ self.ReturnError(403, apps.TelCodesError, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //验证码过期
|
|
|
|
|
+ self.ReturnError(403, apps.TelCodesExpired, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+ md5Ctx := md5.New()
|
|
|
|
|
+ md5Ctx.Write([]byte(pwd))
|
|
|
|
|
+ cipherStr := md5Ctx.Sum(nil)
|
|
|
|
|
+ md5Pwd := hex.EncodeToString(cipherStr)
|
|
|
|
|
+
|
|
|
|
|
+ user := user_model.GetByTel(tel, false)
|
|
|
|
|
+ if user == nil {
|
|
|
|
|
+ self.ReturnError(403, apps.UserNotExist, "", nil)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ user.Pwd = md5Pwd
|
|
|
|
|
+ user.Save()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ self.Data["json"] = user_model.User{Tel: tel}
|
|
|
|
|
+ self.ServeJSON()
|
|
|
|
|
+}
|