- 修复多小程序支持的BUG,从referer中得到小程序ID信息

This commit is contained in:
gazebo
2019-08-12 14:42:55 +08:00
parent 9ab43f291e
commit 342be58814
2 changed files with 25 additions and 6 deletions

View File

@@ -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
}