From 342be588140844ed75ca0b73506c706fe036e19c Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 12 Aug 2019 14:42:55 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=E5=A4=9A=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E6=94=AF=E6=8C=81=E7=9A=84BUG=EF=BC=8C?= =?UTF-8?q?=E4=BB=8Ereferer=E4=B8=AD=E5=BE=97=E5=88=B0=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8FID=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth2/authprovider/weixin/weixin_mini.go | 6 ++--- controllers/auth_controller.go | 25 +++++++++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/business/auth2/authprovider/weixin/weixin_mini.go b/business/auth2/authprovider/weixin/weixin_mini.go index ef2571f5c..3f34bf504 100644 --- a/business/auth2/authprovider/weixin/weixin_mini.go +++ b/business/auth2/authprovider/weixin/weixin_mini.go @@ -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 } diff --git a/controllers/auth_controller.go b/controllers/auth_controller.go index 7a9ca90e1..f56a7d40f 100644 --- a/controllers/auth_controller.go +++ b/controllers/auth_controller.go @@ -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 +}