diff --git a/controllers/auth2.go b/controllers/auth2.go index 1d6089e7f..40e6192eb 100644 --- a/controllers/auth2.go +++ b/controllers/auth2.go @@ -35,6 +35,20 @@ func GetComposedCode(c *web.Controller, code string) (composedCode string) { return composedCode } +func GetComposedCode2(c *web.Controller, code string) (composedCode string) { + composedCode = code + referer := c.Ctx.Request.UserAgent() + 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 = weixin.ComposeJsCode(list[1], code) + } + } + return composedCode +} + type Auth2Controller struct { web.Controller } @@ -92,9 +106,12 @@ func (c *Auth2Controller) Login() { } else if params.AuthType == auth2.AuthTypeEmail { params.AuthIDType = auth2.UserIDEmail } - if params.AuthType == weixin.AuthTypeMini || params.AuthType == weixin.AuthTypeWxApp { + if params.AuthType == weixin.AuthTypeMini { params.AuthSecret = GetComposedCode(&c.Controller, params.AuthSecret) } + if params.AuthType == weixin.AuthTypeWxApp { + params.AuthSecret = GetComposedCode2(&c.Controller, params.AuthSecret) + } ctx := auth2.NewContext(c.Ctx.ResponseWriter, c.Ctx.Request) authInfo, err := auth2.Login(ctx, params.AuthType, params.AuthID, params.AuthIDType, params.AuthSecret) // TODO 兼容没有取到authid2的错误