- BindMiniProgram
This commit is contained in:
@@ -19,7 +19,7 @@ import (
|
||||
const (
|
||||
LoginType = "weixinsns"
|
||||
LoginTypeMiniProgram = "weixinmini"
|
||||
DefTempPasswordDuration = 5 * time.Minute // 登录时间限制在5分钟内
|
||||
DefTempPasswordDuration = 20 * time.Minute // 登录时间限制在5分钟内
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -38,7 +38,7 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrExceptionalLogin = errors.New("登录异常,无前置微信授权操作")
|
||||
ErrExceptionalLogin = errors.New("登录异常,超时,请重走绑定流程")
|
||||
)
|
||||
|
||||
type Auther struct {
|
||||
@@ -87,7 +87,6 @@ func GetWeiXinUserInfo(code string, state string) (userInfo *UserInfoExt, err er
|
||||
TempPassword: utils.GetUUID(),
|
||||
}
|
||||
globals.SugarLogger.Debugf("GetUserInfo code:%s, pwd:%s", code, userInfo.TempPassword)
|
||||
// api.Cacher.Set(wxUserinfo.OpenID, userInfo.TempPassword, DefTempPasswordDuration)
|
||||
cacheSNSInfo(wxUserinfo, userInfo.TempPassword, DefTempPasswordDuration)
|
||||
user, err2 := dao.GetWeiXinUserByIDs(dao.GetDB(), "", wxUserinfo.UnionID, wxUserinfo.OpenID, "")
|
||||
if err = err2; err == nil {
|
||||
@@ -189,24 +188,27 @@ func (a *AutherMiniProgram) BindWeiXin(ctx *jxcontext.Context, code, nickName st
|
||||
return auth.ConvertErr2NoUser(err, "")
|
||||
}
|
||||
|
||||
// 绑定手机加登录
|
||||
// func (a *AutherMiniProgram) BindMobile2(code, nickName, mobileNum, verifyCode string) (loginInfo *auth.LoginInfo, err error) {
|
||||
// globals.SugarLogger.Debugf("BindMobile2 code:%s, nickName:%s, mobileNum:%s, verifyCode:%s", code, nickName, mobileNum, verifyCode)
|
||||
// err = ErrExceptionalLogin
|
||||
// if mobile.VerifyCode(mobileNum, code) {
|
||||
// sessionInfo, err := api.WeixinMiniAPI.SNSCode2Session(code)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// if err = dao.UpdateWeiXinUser(dao.GetDB(), mobileNum, nickName, sessionInfo.UnionID, "", sessionInfo.OpenID); err == nil {
|
||||
// api.Cacher.Set(composeSessionKeyCacheKey(sessionInfo.OpenID), sessionInfo.SessionKey, auth.DefTokenDuration)
|
||||
// loginInfo = auth.CreateLoginInfo(mobileNum, mobile.LoginType)
|
||||
// }
|
||||
// } else {
|
||||
// err = ErrVerifyCodeIsWrong
|
||||
// }
|
||||
// return loginInfo, err
|
||||
// }
|
||||
// 绑定小程序
|
||||
func (a *AutherMiniProgram) BindMiniProgram(ctx *jxcontext.Context, code string) (err error) {
|
||||
globals.SugarLogger.Debugf("BindMiniProgram code:%s", code)
|
||||
if ctx.GetLoginType() != mobile.LoginType {
|
||||
return errors.New("登录方式应该为手机")
|
||||
}
|
||||
sessionInfo, err := api.WeixinMiniAPI.SNSCode2Session(code)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
db := dao.GetDB()
|
||||
user, err := dao.GetWeiXinUserByIDs(db, ctx.GetLoginID(), "", "", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if user.OpenIDUnion != sessionInfo.UnionID {
|
||||
return errors.New("绑定用户不匹配")
|
||||
}
|
||||
err = auth.ConvertErr2NoUser(dao.UpdateWeiXinUser(db, user.Tel, "", "", "", sessionInfo.OpenID), user.Tel)
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *AutherMiniProgram) Login(mobileNum, code string) (userID, LoginType string, err error) {
|
||||
globals.SugarLogger.Debugf("AutherMiniProgram Login mobileNum:%s, code:%s", mobileNum, code)
|
||||
@@ -225,7 +227,6 @@ func (a *AutherMiniProgram) Login(mobileNum, code string) (userID, LoginType str
|
||||
|
||||
}
|
||||
api.Cacher.Set(composeSessionKeyCacheKey(user.Tel), sessionInfo.SessionKey, auth.DefTokenDuration)
|
||||
err = auth.ConvertErr2NoUser(dao.UpdateWeiXinUser(db, user.Tel, "", sessionInfo.UnionID, "", sessionInfo.OpenID), mobileNum)
|
||||
return user.Tel, mobile.LoginType, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user