- 兼容一个新的微信小程序
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
@@ -30,7 +31,7 @@ func init() {
|
||||
func (a *MiniAuther) VerifySecret(dummy, jsCode string) (authBindEx *auth2.AuthBindEx, err error) {
|
||||
globals.SugarLogger.Debugf("weixin mini VerifySecret jsCode:%s", jsCode)
|
||||
|
||||
sessionInfo, err := api.WeixinMiniAPI.SNSCode2Session(jsCode)
|
||||
sessionInfo, err := ProxySNSCode2Session(jsCode)
|
||||
if err == nil {
|
||||
sessionKey := sessionInfo.SessionKey
|
||||
sessionInfo.SessionKey = ""
|
||||
@@ -48,9 +49,25 @@ func (a *MiniAuther) DecryptData(authInfo *auth2.AuthInfo, encryptedData, iv str
|
||||
return "", ErrAuthTypeShouldBeMini
|
||||
}
|
||||
sessionKey := authInfo.AuthBindInfo.UserData.(string)
|
||||
decryptedData, err := api.WeixinMiniAPI.SNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||
decryptedData, err := ProxySNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return base64.StdEncoding.EncodeToString(decryptedData), nil
|
||||
}
|
||||
|
||||
func ProxySNSCode2Session(jsCode string) (sessionInfo *weixinapi.SessionInfo, err error) {
|
||||
sessionInfo, err = api.WeixinMiniAPI.SNSCode2Session(jsCode)
|
||||
if err != nil && api.WeixinMiniAPI2 != nil {
|
||||
sessionInfo, err = api.WeixinMiniAPI2.SNSCode2Session(jsCode)
|
||||
}
|
||||
return sessionInfo, err
|
||||
}
|
||||
|
||||
func ProxySNSDecodeMiniProgramData(encryptedData, sessionKey, iv string) (decryptedData []byte, err error) {
|
||||
decryptedData, err = api.WeixinMiniAPI.SNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||
if err != nil && api.WeixinMiniAPI2 != nil {
|
||||
decryptedData, err = api.WeixinMiniAPI2.SNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||
}
|
||||
return decryptedData, err
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
weixin2 "git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/mobile"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
@@ -185,7 +186,7 @@ func (a *AutherMiniProgram) BindWeiXin(ctx *jxcontext.Context, code, nickName st
|
||||
if loginInfo == nil || loginInfo.GetAuthType() != mobile.LoginType {
|
||||
return fmt.Errorf("调用AutherMiniProgram BindWeiXin时,必须以手机验证方式登录")
|
||||
}
|
||||
sessionInfo, err := api.WeixinMiniAPI.SNSCode2Session(code)
|
||||
sessionInfo, err := weixin2.ProxySNSCode2Session(code)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -199,7 +200,7 @@ func (a *AutherMiniProgram) BindMiniProgram(ctx *jxcontext.Context, code string)
|
||||
if ctx.GetLoginType() != mobile.LoginType {
|
||||
return errors.New("登录方式应该为手机")
|
||||
}
|
||||
sessionInfo, err := api.WeixinMiniAPI.SNSCode2Session(code)
|
||||
sessionInfo, err := weixin2.ProxySNSCode2Session(code)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -217,7 +218,7 @@ func (a *AutherMiniProgram) BindMiniProgram(ctx *jxcontext.Context, code string)
|
||||
|
||||
func (a *AutherMiniProgram) Login(mobileNum, code string) (userID, LoginType string, err error) {
|
||||
globals.SugarLogger.Debugf("AutherMiniProgram Login mobileNum:%s, code:%s", mobileNum, code)
|
||||
sessionInfo, err := api.WeixinMiniAPI.SNSCode2Session(code)
|
||||
sessionInfo, err := weixin2.ProxySNSCode2Session(code)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
@@ -246,7 +247,7 @@ func (a *AutherMiniProgram) DecryptData(ctx *jxcontext.Context, encryptedData, i
|
||||
if err = api.Cacher.GetAs(composeSessionKeyCacheKey(ctx.GetLoginInfo().GetAuthID()), &sessionKey); err != nil {
|
||||
return "", err
|
||||
}
|
||||
decryptedData, err := api.WeixinMiniAPI.SNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||
decryptedData, err := weixin2.ProxySNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user