This commit is contained in:
苏尹岚
2021-04-09 10:15:28 +08:00
parent a160037979
commit 038f60595d

View File

@@ -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的错误