From ebf6158b7c16c895132c4f3aeb72013a1e4f1440 Mon Sep 17 00:00:00 2001 From: aris song Date: Sun, 15 Apr 2018 13:06:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=BC=80=E6=94=BE=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E7=BD=91=E9=A1=B5=E5=BA=94=E7=94=A8=E8=8E=B7=E5=8F=96?= =?UTF-8?q?oauth=E5=9B=9E=E8=B0=83=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oauth/oauth.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/oauth/oauth.go b/oauth/oauth.go index 6b2b710..044b66e 100644 --- a/oauth/oauth.go +++ b/oauth/oauth.go @@ -11,11 +11,12 @@ import ( ) const ( - redirectOauthURL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect" - accessTokenURL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code" - refreshAccessTokenURL = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=%s&grant_type=refresh_token&refresh_token=%s" - userInfoURL = "https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN" - checkAccessTokenURL = "https://api.weixin.qq.com/sns/auth?access_token=%s&openid=%s" + redirectOauthURL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect" + webAppRedirectOauthURL = "https://open.weixin.qq.com/connect/qrconnect?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect" + accessTokenURL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code" + refreshAccessTokenURL = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=%s&grant_type=refresh_token&refresh_token=%s" + userInfoURL = "https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN" + checkAccessTokenURL = "https://api.weixin.qq.com/sns/auth?access_token=%s&openid=%s" ) //Oauth 保存用户授权信息 @@ -37,6 +38,12 @@ func (oauth *Oauth) GetRedirectURL(redirectURI, scope, state string) (string, er return fmt.Sprintf(redirectOauthURL, oauth.AppID, urlStr, scope, state), nil } +//GetWebAppRedirectURL 获取网页应用跳转的url地址 +func (oauth *Oauth) GetWebAppRedirectURL(redirectURI, scope, state string) (string, error) { + urlStr := url.QueryEscape(redirectURI) + return fmt.Sprintf(webAppRedirectOauthURL, oauth.AppID, urlStr, scope, state), nil +} + //Redirect 跳转到网页授权 func (oauth *Oauth) Redirect(writer http.ResponseWriter, req *http.Request, redirectURI, scope, state string) error { location, err := oauth.GetRedirectURL(redirectURI, scope, state)