Browse Source

update wechat authorize code url

ls 2 years ago
parent
commit
8467698d5f
1 changed files with 21 additions and 2 deletions
  1. 21 2
      wechat/client.go

+ 21 - 2
wechat/client.go

@@ -116,8 +116,8 @@ func (wc *Client) TokenUseCache(ok bool) {
 	wc.TokenFromCache = ok
 }
 
-// GetCodeURL get code 授权获取 OpenID URL
-// /connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
+// GetCodeURL get code 授权获取 OpenID URL(静默授权)
+// /connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect
 // 转向到
 // redirect_uri/?code=CODE&state=STATE
 func (wc Client) GetCodeURL(redirectURL, state string) (uri string) {
@@ -135,6 +135,25 @@ func (wc Client) GetCodeURL(redirectURL, state string) (uri string) {
 	return
 }
 
+// GetUserInfoCodeURL get code 授权获取 OpenID URL
+// /connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect
+// 转向到
+// redirect_uri/?code=CODE&state=STATE
+func (wc Client) GetUserInfoCodeURL(redirectURL, state string) (uri string) {
+	uri = OpenURL + "/connect/oauth2/authorize?"
+	args := url.Values{}
+	args.Add("appid", wc.AppID)
+	args.Add("redirect_uri", redirectURL)
+	args.Add("response_type", "code")
+	args.Add("scope", "snsapi_userinfo")
+	args.Add("state", state)
+
+	uri += args.Encode()
+	uri += "#wechat_redirect"
+
+	return
+}
+
 // GetOpenID 获取 OpenID
 // /sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
 func (wc Client) GetOpenID(code string) (jq *myth.JSONQuery, err error) {