- first edition of auth2

This commit is contained in:
gazebo
2019-03-01 17:43:17 +08:00
parent b90313bd49
commit 421240ac54
17 changed files with 1015 additions and 12 deletions

View File

@@ -107,3 +107,11 @@ func ConvertErr2NoUser(err error, mobileNum string) error {
}
return err
}
func (a *LoginInfo) GetAuthID() string {
return a.ID
}
func (a *LoginInfo) GetAuthType() string {
return a.LoginType
}

View File

@@ -179,14 +179,14 @@ func BindMobile2(openid, secret, mobileNum, verifyCode, nickname string) (loginI
func (a *AutherMiniProgram) BindWeiXin(ctx *jxcontext.Context, code, nickName string) (err error) {
globals.SugarLogger.Debugf("AutherMiniProgram BindWeiXin code:%s, nickName:%s", code, nickName)
loginInfo := ctx.GetLoginInfo()
if loginInfo == nil || loginInfo.LoginType != mobile.LoginType {
if loginInfo == nil || loginInfo.GetAuthType() != mobile.LoginType {
return fmt.Errorf("调用AutherMiniProgram BindWeiXin时必须以手机验证方式登录")
}
sessionInfo, err := api.WeixinMiniAPI.SNSCode2Session(code)
if err != nil {
return err
}
err = dao.UpdateWeiXinUser(dao.GetDB(), loginInfo.ID, nickName, sessionInfo.UnionID, "", sessionInfo.OpenID)
err = dao.UpdateWeiXinUser(dao.GetDB(), loginInfo.GetAuthID(), nickName, sessionInfo.UnionID, "", sessionInfo.OpenID)
return auth.ConvertErr2NoUser(err, "")
}
@@ -234,13 +234,13 @@ func (a *AutherMiniProgram) Login(mobileNum, code string) (userID, LoginType str
func (a *AutherMiniProgram) Logout(loginInfo *auth.LoginInfo) error {
globals.SugarLogger.Debugf("AutherMiniProgram Logout openid:%s", utils.Format4Output(loginInfo, false))
return api.Cacher.Del(composeSessionKeyCacheKey(loginInfo.ID))
return api.Cacher.Del(composeSessionKeyCacheKey(loginInfo.GetAuthID()))
}
func (a *AutherMiniProgram) DecryptData(ctx *jxcontext.Context, encryptedData, iv string) (decryptedDataBase64 string, err error) {
globals.SugarLogger.Debugf("AutherMiniProgram DecryptData encryptedData:%s, iv:%s", encryptedData, iv)
var sessionKey string
if err = api.Cacher.GetAs(composeSessionKeyCacheKey(ctx.GetLoginInfo().ID), &sessionKey); err != nil {
if err = api.Cacher.GetAs(composeSessionKeyCacheKey(ctx.GetLoginInfo().GetAuthID()), &sessionKey); err != nil {
return "", err
}
decryptedData, err := api.WeixinMiniAPI.SNSDecodeMiniProgramData(encryptedData, sessionKey, iv)