- 修复多小程序支持的BUG,从referer中得到小程序ID信息
This commit is contained in:
@@ -60,15 +60,13 @@ func (a *MiniAuther) DecryptData(authInfo *auth2.AuthInfo, encryptedData, iv str
|
||||
func ProxySNSCode2Session(jsCode string) (sessionInfo *weixinapi.SessionInfo, err error) {
|
||||
miniApi := api.WeixinMiniAPI
|
||||
list := strings.Split(jsCode, ",")
|
||||
if len(list) >= 2 {
|
||||
if len(list) >= 2 && len(list[0]) == len("wx4b5930c13f8b1170") {
|
||||
if list[0] == api.WeixinMiniAppID2 {
|
||||
miniApi = api.WeixinMiniAPI2
|
||||
}
|
||||
jsCode = strings.Join(list[1:], ",")
|
||||
}
|
||||
sessionInfo, err = miniApi.SNSCode2Session(jsCode)
|
||||
if err != nil && api.WeixinMiniAPI2 != nil {
|
||||
sessionInfo, err = miniApi.SNSCode2Session(jsCode)
|
||||
}
|
||||
return sessionInfo, err
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||
@@ -75,6 +76,9 @@ func (c *AuthController) GetWeiXinUserInfo() {
|
||||
// @router /Login [post]
|
||||
func (c *AuthController) Login() {
|
||||
c.callLogin(func(params *tAuthLoginParams) (retVal interface{}, errCode string, err error) {
|
||||
if params.Type == weixin.LoginTypeMiniProgram {
|
||||
params.Secret = c.GetComposedCode((params.Secret))
|
||||
}
|
||||
retVal, err = auth.Login(params.Id, params.Type, params.Secret)
|
||||
if err == auth.ErrUserNotExist {
|
||||
return retVal, model.ErrCodeUserNotExist, err
|
||||
@@ -172,7 +176,7 @@ func (c *AuthController) BindMobile2() {
|
||||
// @router /MiniBindWeiXin [post]
|
||||
func (c *AuthController) MiniBindWeiXin() {
|
||||
c.callMiniBindWeiXin(func(params *tAuthMiniBindWeiXinParams) (retVal interface{}, errCode string, err error) {
|
||||
err = weixin.AutherMini.BindWeiXin(params.Ctx, params.Code, params.Nickname)
|
||||
err = weixin.AutherMini.BindWeiXin(params.Ctx, c.GetComposedCode(params.Code), params.Nickname)
|
||||
if err == auth.ErrUserNotExist {
|
||||
return retVal, model.ErrCodeUserNotExist, err
|
||||
}
|
||||
@@ -189,7 +193,7 @@ func (c *AuthController) MiniBindWeiXin() {
|
||||
// @router /BindMiniProgram [post]
|
||||
func (c *AuthController) BindMiniProgram() {
|
||||
c.callBindMiniProgram(func(params *tAuthBindMiniProgramParams) (retVal interface{}, errCode string, err error) {
|
||||
err = weixin.AutherMini.BindMiniProgram(params.Ctx, params.Code)
|
||||
err = weixin.AutherMini.BindMiniProgram(params.Ctx, c.GetComposedCode(params.Code))
|
||||
if err == auth.ErrUserNotExist {
|
||||
return retVal, model.ErrCodeUserNotExist, err
|
||||
}
|
||||
@@ -211,3 +215,20 @@ func (c *AuthController) MiniDecryptData() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
func (c *AuthController) GetComposedCode(code string) (composedCode string) {
|
||||
composedCode = code
|
||||
referer := c.Ctx.Request.Referer()
|
||||
globals.SugarLogger.Debugf("GetComposedCode referer:%s", referer)
|
||||
index := strings.Index(referer, "//")
|
||||
if index > 0 {
|
||||
list := strings.Split(referer[index+2:], "/")
|
||||
if len(list) >= 2 {
|
||||
composedCode = strings.Join([]string{
|
||||
list[1],
|
||||
code,
|
||||
}, ",")
|
||||
}
|
||||
}
|
||||
return composedCode
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user