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)