|
|
@@ -0,0 +1,863 @@
|
|
|
+package permit_controller
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "strconv"
|
|
|
+
|
|
|
+ // "math/rand"
|
|
|
+ // "crypto/md5"
|
|
|
+ // "encoding/hex"
|
|
|
+ // "strconv"
|
|
|
+ "encoding/json"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+
|
|
|
+ "github.com/astaxie/beego"
|
|
|
+ "github.com/astaxie/beego/context"
|
|
|
+ "github.com/uuid"
|
|
|
+
|
|
|
+ "fohow.com/apps"
|
|
|
+ "fohow.com/apps/helpers"
|
|
|
+ // "fohow.com/apps/controllers/user_controller"
|
|
|
+ // "fohow.com/apps/models/activity_model"
|
|
|
+ // "fohow.com/apps/models/order_model"
|
|
|
+ // "fohow.com/apps/models/product_model"
|
|
|
+ // "fohow.com/apps/models/shop_model"
|
|
|
+ // "fohow.com/apps/models/sms_model"
|
|
|
+ "fohow.com/apps/models/user_model"
|
|
|
+ // "fohow.com/apps/models/wx_gongzhonghao_model"
|
|
|
+ "fohow.com/cache"
|
|
|
+ // "fohow.com/libs/tool"
|
|
|
+ "fohow.com/libs/wx_mp"
|
|
|
+ // "fohow.com/libs/wx_open"
|
|
|
+)
|
|
|
+
|
|
|
+var (
|
|
|
+ //以下Action无需登录校验,exceptCheckUserLoginAction = []string{"*"} *代表全部不需要
|
|
|
+ exceptCheckUserLoginAction = []string{"*"}
|
|
|
+ exceptCheckWxUserLoginAction = []string{"*"}
|
|
|
+)
|
|
|
+
|
|
|
+type PermitController struct {
|
|
|
+ apps.BaseController
|
|
|
+}
|
|
|
+
|
|
|
+func (self *PermitController) Init(ctx *context.Context, controllerName, actionName string, app interface{}) {
|
|
|
+ self.BaseController.Init(ctx, controllerName, actionName, app)
|
|
|
+ self.ExceptCheckUserLoginAction = exceptCheckUserLoginAction
|
|
|
+ self.ExceptCheckWxUserLoginAction = exceptCheckWxUserLoginAction
|
|
|
+}
|
|
|
+
|
|
|
+//小程序授权
|
|
|
+func (self *PermitController) XcxAuthorize() {
|
|
|
+ params := self.GetString("userinfo")
|
|
|
+ channel, _ := self.GetInt64("channel", 0)
|
|
|
+ // beego.BeeLogger.Warn("XcxAuthorize userinfo: %s", params)
|
|
|
+ inviteId, _ := self.GetInt64("invite_id", 0)
|
|
|
+ beego.BeeLogger.Warn("XcxAuthorize inviteId: %d", inviteId)
|
|
|
+ type UserInfo struct {
|
|
|
+ NickName string `json:"nickName"` // 用户的昵称
|
|
|
+ Gender int64 `json:"gender"` // 用户的性别, 值为1时是男性, 值为2时是女性, 值为0时是未知
|
|
|
+ Language string `json:"language"` // 用户的语言, zh_CN, zh_TW, en
|
|
|
+ City string `json:"city"` // 用户所在城市
|
|
|
+ Province string `json:"province"` // 用户所在省份
|
|
|
+ Country string `json:"country"` // 用户所在国家
|
|
|
+ AvatarUrl string `json:"avatarUrl"` // 头像
|
|
|
+ }
|
|
|
+ type Info struct {
|
|
|
+ ErrMsg string `json:"errMsg"`
|
|
|
+ RawData string `json:"rawData"`
|
|
|
+ Signature string `json:"signature"`
|
|
|
+ Iv string `json:"iv"`
|
|
|
+ EncryptedData string `json:"encryptedData"`
|
|
|
+ UserInfo *UserInfo `json:"userInfo"`
|
|
|
+ }
|
|
|
+ info := new(Info)
|
|
|
+ err := json.Unmarshal([]byte(params), &info)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ beego.BeeLogger.Error("XcxAuthorize err: %s, info:%s", err, info)
|
|
|
+ self.ReturnError(403, apps.ParamsError, "", nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ sessionKey, _ := self.GetSession(apps.XcxSessionKey).(string)
|
|
|
+ // beego.BeeLogger.Warn("sessionKey:%s", sessionKey)
|
|
|
+ type EncryptedData struct {
|
|
|
+ UnionId string `json:"unionId"`
|
|
|
+ OpenId string `json:"openId"`
|
|
|
+ }
|
|
|
+
|
|
|
+ if sessionKey == "" {
|
|
|
+ self.ReturnError(403, apps.UserNeedLogin, "", nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ encryptedData := &EncryptedData{}
|
|
|
+ json.Unmarshal([]byte(result.(string)), encryptedData)
|
|
|
+ if encryptedData.UnionId == "" || encryptedData.OpenId == "" {
|
|
|
+ self.ReturnError(403, apps.UserAuthorizeFailed, "", nil)
|
|
|
+ }
|
|
|
+ wxUser := user_model.GetWxUserByUnionid(encryptedData.UnionId, false)
|
|
|
+ ip := self.Ctx.Input.IP()
|
|
|
+ //注册会员
|
|
|
+ user := user_model.Create("", ip)
|
|
|
+ if user == nil {
|
|
|
+ self.ReturnError(403, apps.RegisterUserError, "", nil)
|
|
|
+ }
|
|
|
+ if wxUser != nil {
|
|
|
+ wxUser.Openid = encryptedData.OpenId
|
|
|
+ } else {
|
|
|
+ introUserId := int64(1)
|
|
|
+ if inviteId == int64(0) {
|
|
|
+ inviteId = int64(1)
|
|
|
+ }
|
|
|
+ beego.BeeLogger.Warn("XcxAuthorize_quickCreate_inviteId:%d", inviteId)
|
|
|
+ inviter := user_model.GetWxUserById(inviteId, false)
|
|
|
+ if inviter != nil {
|
|
|
+ if inviter.ShowInviteMode == 1 && inviteId != int64(1) {
|
|
|
+ introUserId = inviter.Id
|
|
|
+ } else {
|
|
|
+ introUserId = inviter.IntroUserId
|
|
|
+ }
|
|
|
+ }
|
|
|
+ wxUser = new(user_model.WxUser).QuickCreate(encryptedData.OpenId, encryptedData.UnionId, ip, channel, time.Now().Unix(), user.Id, inviteId, introUserId)
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+ wxUser.UploadHead(info.UserInfo.AvatarUrl)
|
|
|
+
|
|
|
+ if wxUser != nil {
|
|
|
+ self.SetSession(apps.SessionWxUserKey, wxUser.Id)
|
|
|
+ }
|
|
|
+ // 如果微信用户已绑定手机,则找出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.Data["json"] = encryptedData
|
|
|
+ self.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+//小程序登录
|
|
|
+func (self *PermitController) XcxLogin() {
|
|
|
+ code := self.GetString("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)
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ 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()
|
|
|
+}
|
|
|
+
|
|
|
+//生成订单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() {
|
|
|
+ // beego.BeeLogger.Warn("AfterWxMpAuth........")
|
|
|
+ code := self.GetString("code")
|
|
|
+ // state := self.GetString("state")
|
|
|
+ // _id := self.Ctx.Input.Param(":id")
|
|
|
+ // id, _ := strconv.ParseInt(_id, 10, 64)
|
|
|
+ // gzh := wx_gongzhonghao_model.GetGZHById(id, true)
|
|
|
+ // if gzh == nil {
|
|
|
+ // self.ReturnError(403, apps.GongZhongHaoNoExist, "", nil)
|
|
|
+ // }
|
|
|
+ a := beego.AppConfig.String("WxMPAppId")
|
|
|
+ s := beego.AppConfig.String("WxMPAppSecret")
|
|
|
+ // mpId := gzh.WxHao
|
|
|
+ token := wx_mp.AuthExchangeToken(code, a, s)
|
|
|
+ if token == nil {
|
|
|
+ beego.BeeLogger.Error("AfterSilenceMpAuth, exchangetoken err")
|
|
|
+ self.ReturnError(403, apps.NetworkBusy, "", nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ // mpOpenid := token.OpenId
|
|
|
+ // unionId := token.UnionId
|
|
|
+ // beego.BeeLogger.Warn("openid: %s", mpOpenid)
|
|
|
+ // beego.BeeLogger.Warn("unionid: %s", unionId)
|
|
|
+ // beego.BeeLogger.Warn("token: %v", token)
|
|
|
+ // wxUser := user_model.GetWxUserByUnionid(unionId, false)
|
|
|
+ // authWxUser := user_model.GetAuthWxUserByMpIdAndUnionId(mpId, unionId, false)
|
|
|
+ // if authWxUser == nil && wxUser != nil {
|
|
|
+ // go new(user_model.AuthWxUser).Create(mpId, mpOpenid, unionId, wxUser.Id)
|
|
|
+ // }
|
|
|
+ // if cbUrl, ok := cache.Cache.Get(state).(string); ok {
|
|
|
+ // if cbUrl == "" {
|
|
|
+ // self.Redirect(beego.AppConfig.String("MHost"), 302)
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // if !strings.HasPrefix(cbUrl, "http://") {
|
|
|
+ // cbUrl = fmt.Sprintf("%s%s", beego.AppConfig.String("MHost"), cbUrl)
|
|
|
+ // }
|
|
|
+ // self.Redirect(cbUrl, 302)
|
|
|
+ // return
|
|
|
+ // } else {
|
|
|
+ // self.Redirect(beego.AppConfig.String("MHost"), 302)
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ 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() {
|
|
|
+ cb := self.GetString("cb")
|
|
|
+ if self.IsWxClient() {
|
|
|
+ _, ok := self.Ctx.Input.Session(apps.SessionWxUserKey).(int64)
|
|
|
+
|
|
|
+ wxUser := self.GetCurrentWxUser(true)
|
|
|
+ // beego.BeeLogger.Warn("wxMpLogin_wxuser_info:%v", wxUser)
|
|
|
+
|
|
|
+ if ok {
|
|
|
+ if wxUser != nil {
|
|
|
+ wxUserGzh := user_model.GetWxUserGzhByWxUIdAndAppId(wxUser.Id, beego.AppConfig.String("WxMPAppId"), false)
|
|
|
+ if wxUserGzh != nil && wxUserGzh.GzhOpenId != "" {
|
|
|
+ self.ReturnError(403, apps.HasLogin, "", nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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("WxMPAppId")
|
|
|
+ redirectURI := fmt.Sprintf("%s/login/mp/after",
|
|
|
+ beego.AppConfig.String("ApiHost"))
|
|
|
+
|
|
|
+ scope := "snsapi_userinfo"
|
|
|
+ url := wx_mp.AuthCodeURL(wx_mp.DefaultAuthCodeRequestUrl, appId, redirectURI, scope, state)
|
|
|
+ self.Redirect(url, 302)
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ self.ReturnError(403, apps.NotWeixinClient, "", nil)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 微信公众号平台登录回调
|
|
|
+func (self *PermitController) AfterWxMpLogin() {
|
|
|
+ code := self.GetString("code")
|
|
|
+ state := self.GetString("state")
|
|
|
+ a := beego.AppConfig.String("WxMPAppId")
|
|
|
+ s := beego.AppConfig.String("WxMPAppSecret")
|
|
|
+ token := wx_mp.AuthExchangeToken(code, a, s)
|
|
|
+ // beego.BeeLogger.Warn("afterWxMpLogin_token: %v", token)
|
|
|
+ if token == nil {
|
|
|
+ beego.BeeLogger.Error("AfterWxAutoLogin, after login, exchangetoken err")
|
|
|
+ self.ReturnError(403, apps.NetworkBusy, "", nil)
|
|
|
+ }
|
|
|
+ mpOpenid := token.OpenId
|
|
|
+ unionId := token.UnionId
|
|
|
+ // beego.BeeLogger.Warn("AfterWxMpLogin_token: %s", unionId)
|
|
|
+ wxUser := user_model.GetWxUserByUnionid(unionId, false)
|
|
|
+ var wxUserGzh *user_model.WxUserGongzhonghao
|
|
|
+ if wxUser != nil {
|
|
|
+ wxUserGzh = user_model.GetWxUserGzhByOpenId(mpOpenid, false)
|
|
|
+ }
|
|
|
+ // beego.BeeLogger.Warn("AfterWxMpLogin_wxUserGzh:%v ", wxUserGzh)
|
|
|
+
|
|
|
+ if wxUser == nil {
|
|
|
+ info := wx_mp.AuthUserInfo(token, mpOpenid, a, s)
|
|
|
+ if info != nil {
|
|
|
+ // beego.BeeLogger.Warn("AfterWxAutoLogin, info=%v", info)
|
|
|
+ ip := self.Ctx.Input.IP()
|
|
|
+ wxUser = new(user_model.WxUser).Create("", unionId, info.Nickname,
|
|
|
+ info.City, info.Country, info.Province, ip, info.Sex, 0, 0, 0)
|
|
|
+
|
|
|
+ beego.BeeLogger.Info("AfterWxAutoLogin, upload WxUserHead with URL: %s", info.HeadImageURL)
|
|
|
+ if wxUser != nil {
|
|
|
+ go wxUser.UploadHead(info.HeadImageURL)
|
|
|
+ }
|
|
|
+ if wxUserGzh == nil {
|
|
|
+ beego.BeeLogger.Info("wxUser: %v, info: %v")
|
|
|
+ wxUserGzh = new(user_model.WxUserGongzhonghao).Create(mpOpenid, a, wxUser.Id, info.Subscribe, info.SubscribeTime)
|
|
|
+ }
|
|
|
+
|
|
|
+ if wxUserGzh != nil && wxUserGzh.WxUserId != wxUser.Id {
|
|
|
+ wxUserGzh.WxUserId = wxUser.Id
|
|
|
+ wxUserGzh.Save()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if wxUser.Head == "" {
|
|
|
+ info := wx_mp.AuthUserInfo(token, mpOpenid, a, s)
|
|
|
+ if info != nil {
|
|
|
+ go wxUser.UploadHead(info.HeadImageURL)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if wxUserGzh == nil {
|
|
|
+ info := wx_mp.AuthUserInfo(token, mpOpenid, a, s)
|
|
|
+ if info != nil {
|
|
|
+ wxUserGzh = new(user_model.WxUserGongzhonghao).Create(mpOpenid, a, wxUser.Id, info.Subscribe, info.SubscribeTime)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if wxUserGzh != nil && wxUserGzh.WxUserId != wxUser.Id {
|
|
|
+ wxUserGzh.WxUserId = wxUser.Id
|
|
|
+ wxUserGzh.Save()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if wxUser != nil && wxUserGzh != nil && wxUserGzh.GzhOpenId != mpOpenid {
|
|
|
+ wxUserGzh.GzhOpenId = mpOpenid
|
|
|
+ go wxUserGzh.UpdateField("GzhOpenId")
|
|
|
+ }
|
|
|
+ if wxUser != nil {
|
|
|
+ self.SetSession(apps.SessionWxUserKey, wxUser.Id)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果微信用户已绑定手机,则找出userId,并且赋值给session[userId]
|
|
|
+ if wxUser != nil && wxUser.UserId > 0 {
|
|
|
+ self.SetSession(apps.SessionUserKey, wxUser.UserId)
|
|
|
+ // beego.BeeLogger.Warn("AfterWxAutoLogin, wxUser.UserId=%d", wxUser.UserId)
|
|
|
+ }
|
|
|
+ if cbUrl, ok := cache.Cache.Get(state).(string); ok {
|
|
|
+ if cbUrl == "" {
|
|
|
+ self.Redirect(beego.AppConfig.String("WxHost"), 302)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !strings.HasPrefix(cbUrl, "http://") && !strings.HasPrefix(cbUrl, "https://") {
|
|
|
+ cbUrl = fmt.Sprintf("%s%s", beego.AppConfig.String("WxHost"), cbUrl)
|
|
|
+ }
|
|
|
+ self.Redirect(cbUrl, 302)
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ self.Redirect(beego.AppConfig.String("WxHost"), 302)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // beego.BeeLogger.Error("AfterWxAutoLogin, after login, something err")
|
|
|
+ self.ReturnError(403, apps.NetworkBusy, "", nil)
|
|
|
+}
|
|
|
+
|
|
|
+// 网站微信登录
|
|
|
+func (self *PermitController) PcWxLogin() {
|
|
|
+ cb := self.GetString("cb")
|
|
|
+ beego.BeeLogger.Warn("PcWxLogin %s", self.Ctx.Input.UserAgent())
|
|
|
+
|
|
|
+ //已经登录了的情况
|
|
|
+ _, ok := self.Ctx.Input.Session(apps.SessionWxUserKey).(int64)
|
|
|
+ wxUser := self.GetCurrentWxUser(true)
|
|
|
+ if ok && wxUser != nil {
|
|
|
+ if cb == "" {
|
|
|
+ self.Redirect(beego.AppConfig.String("PcHost"), 302)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !strings.HasPrefix(cb, "http://") && !strings.HasPrefix(cb, "https://") {
|
|
|
+ cb = fmt.Sprintf("%s%s", beego.AppConfig.String("PcHost"), cb)
|
|
|
+ }
|
|
|
+ self.Redirect(cb, 302)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //内网登录的情况
|
|
|
+ if beego.BConfig.RunMode == beego.DEV {
|
|
|
+ wxUId, _ := self.GetInt64("wxuid")
|
|
|
+ wxUser := user_model.GetWxUserById(wxUId, true)
|
|
|
+ if wxUser != nil {
|
|
|
+ if wxUser.UserId > 0 {
|
|
|
+ self.SetSession(apps.SessionUserKey, wxUser.UserId)
|
|
|
+ }
|
|
|
+ beego.BeeLogger.Warn("beego.AppConfig.String(PcHost) %s", beego.AppConfig.String("PcHost"))
|
|
|
+ if cb == "" {
|
|
|
+ self.Redirect(beego.AppConfig.String("PcHost"), 302)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !strings.HasPrefix(cb, "http://") && !strings.HasPrefix(cb, "https://") {
|
|
|
+ cb = fmt.Sprintf("%s%s", beego.AppConfig.String("PcHost"), cb)
|
|
|
+ }
|
|
|
+ beego.BeeLogger.Warn("beego.AppConfig.String(PcHost) cb= %s", cb)
|
|
|
+ self.Redirect(cb, 302)
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ self.ReturnError(403, apps.UserNotExist, "", nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ u := strings.Split(uuid.NewV4().String(), "-")[0]
|
|
|
+ state := fmt.Sprintf("pcLoginCb[%s]", u)
|
|
|
+ cache.Cache.Put(state, cb, 60*time.Second)
|
|
|
+
|
|
|
+ appId := beego.AppConfig.String("PcWxMPAppId")
|
|
|
+ redirectURI := fmt.Sprintf("%s/pc/login/after", beego.AppConfig.String("ApiHost"))
|
|
|
+ scope := "snsapi_login"
|
|
|
+
|
|
|
+ url := wx_mp.AuthCodeURL(wx_mp.PcAuthCodeRequestUrl, appId, redirectURI, scope, state)
|
|
|
+ self.Redirect(url, 302)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 网站微信登录回调
|
|
|
+func (self *PermitController) AfterPcWxLogin() {
|
|
|
+ code := self.GetString("code")
|
|
|
+ state := self.GetString("state")
|
|
|
+ a := beego.AppConfig.String("PcWxMPAppId")
|
|
|
+ s := beego.AppConfig.String("PcWxMPAppSecret")
|
|
|
+ token := wx_mp.AuthExchangeToken(code, a, s)
|
|
|
+ // beego.BeeLogger.Warn("afterWxMpLogin_token: %v", token)
|
|
|
+ if token == nil {
|
|
|
+ beego.BeeLogger.Error("PcWxMpLogin login, exchangetoken err")
|
|
|
+ self.ReturnError(403, apps.NetworkBusy, "", nil)
|
|
|
+ }
|
|
|
+ mpOpenid := token.OpenId
|
|
|
+ unionId := token.UnionId
|
|
|
+ wxUser := user_model.GetWxUserByUnionid(unionId, false)
|
|
|
+
|
|
|
+ if wxUser == nil {
|
|
|
+ info := wx_mp.AuthUserInfo(token, mpOpenid, a, s)
|
|
|
+ if info != nil {
|
|
|
+ // beego.BeeLogger.Warn("AfterWxAutoLogin, info=%v", info)
|
|
|
+ ip := self.Ctx.Input.IP()
|
|
|
+ wxUser = new(user_model.WxUser).Create("", unionId, info.Nickname,
|
|
|
+ info.City, info.Country, info.Province, ip, info.Sex, 0, 0, 0)
|
|
|
+
|
|
|
+ beego.BeeLogger.Info("PcWxMpLogin, upload WxUserHead with URL: %s", info.HeadImageURL)
|
|
|
+ if wxUser != nil {
|
|
|
+ go wxUser.UploadHead(info.HeadImageURL)
|
|
|
+ }
|
|
|
+ wxUserGzh := user_model.GetWxUserGzhByOpenId(mpOpenid, false)
|
|
|
+ if wxUserGzh == nil {
|
|
|
+ beego.BeeLogger.Info("wxUser: %v, info: %v")
|
|
|
+ wxUserGzh = new(user_model.WxUserGongzhonghao).Create(mpOpenid, a, wxUser.Id, info.Subscribe, info.SubscribeTime)
|
|
|
+ }
|
|
|
+
|
|
|
+ if wxUserGzh != nil && wxUserGzh.WxUserId != wxUser.Id {
|
|
|
+ wxUserGzh.WxUserId = wxUser.Id
|
|
|
+ wxUserGzh.Save()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if wxUser.Head == "" {
|
|
|
+ info := wx_mp.AuthUserInfo(token, mpOpenid, a, s)
|
|
|
+ if info != nil {
|
|
|
+ go wxUser.UploadHead(info.HeadImageURL)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ wxUserGzh := user_model.GetWxUserGzhByOpenId(mpOpenid, false)
|
|
|
+ if wxUserGzh == nil {
|
|
|
+ info := wx_mp.AuthUserInfo(token, mpOpenid, a, s)
|
|
|
+ if info != nil {
|
|
|
+ wxUserGzh = new(user_model.WxUserGongzhonghao).Create(mpOpenid, a, wxUser.Id, info.Subscribe, info.SubscribeTime)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if wxUserGzh != nil && wxUserGzh.WxUserId != wxUser.Id {
|
|
|
+ wxUserGzh.WxUserId = wxUser.Id
|
|
|
+ wxUserGzh.Save()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if wxUser != nil {
|
|
|
+ self.SetSession(apps.SessionWxUserKey, wxUser.Id)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果微信用户已绑定手机,则找出userId,并且赋值给session[userId]
|
|
|
+ if wxUser != nil && wxUser.UserId > 0 {
|
|
|
+ self.SetSession(apps.SessionUserKey, wxUser.UserId)
|
|
|
+ }
|
|
|
+
|
|
|
+ if cbUrl, ok := cache.Cache.Get(state).(string); ok {
|
|
|
+ if cbUrl == "" {
|
|
|
+ self.Redirect(beego.AppConfig.String("PcHost"), 302)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !strings.HasPrefix(cbUrl, "http://") && !strings.HasPrefix(cbUrl, "https://") {
|
|
|
+ cbUrl = fmt.Sprintf("%s%s", beego.AppConfig.String("PcHost"), cbUrl)
|
|
|
+ }
|
|
|
+ self.Redirect(cbUrl, 302)
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ self.Redirect(beego.AppConfig.String("PcHost"), 302)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ self.ReturnError(403, apps.NetworkBusy, "", nil)
|
|
|
+}
|
|
|
+
|
|
|
+// 退出登录
|
|
|
+func (self *PermitController) Logout() {
|
|
|
+ self.DelSession(apps.SessionUserKey)
|
|
|
+ self.DelSession(apps.SessionWxUserKey)
|
|
|
+ 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
|
|
|
+// }
|