|
@@ -0,0 +1,37 @@
|
|
1
|
+package mp
|
|
2
|
+
|
|
3
|
+import (
|
|
4
|
+ "net/url"
|
|
5
|
+ "strings"
|
|
6
|
+
|
|
7
|
+ wxerr "gitee.com/yansen_zh/wxcomponent/errors"
|
|
8
|
+)
|
|
9
|
+
|
|
10
|
+// MpWebAccessTokenResult 网页授权, 通过 code 换取 access_token 返回值
|
|
11
|
+type MpWebAccessTokenResult struct {
|
|
12
|
+ wxerr.Error
|
|
13
|
+ // AccessToken 接口调用凭证
|
|
14
|
+ AccessToken string `json:"access_token"`
|
|
15
|
+ // ExpiresIn access_token 接口调用凭证超时时间,单位(秒)
|
|
16
|
+ ExpiresIn int `json:"expires_in"`
|
|
17
|
+ // RefreshToken 用户刷新 access_token
|
|
18
|
+ RefreshToken string `json:"refresh_token"`
|
|
19
|
+ // Openid 授权用户唯一标识
|
|
20
|
+ OpenID string `json:"openid"`
|
|
21
|
+ // Scope 用户授权的作用域,使用逗号(,)分隔
|
|
22
|
+ Scope string `json:"scope"`
|
|
23
|
+}
|
|
24
|
+
|
|
25
|
+// GetAuthorizationCodeLink 代公众号发起网页授权, 构造授权链接
|
|
26
|
+// redirectURI 必须是未经编码的原始网址字符串
|
|
27
|
+func GetAuthorizationCodeLink(componentAppID, appID, redirectURI, state string, scopes ...string) string {
|
|
28
|
+ params := url.Values{}
|
|
29
|
+ params.Set("appid", appID)
|
|
30
|
+ params.Set("redirect_uri", redirectURI)
|
|
31
|
+ params.Set("response_type", "code")
|
|
32
|
+ params.Set("scope", strings.Join(scopes, ","))
|
|
33
|
+ params.Set("state", state)
|
|
34
|
+ params.Set("component_appid", componentAppID)
|
|
35
|
+
|
|
36
|
+ return "https://open.weixin.qq.com/connect/oauth2/authorize?" + params.Encode()
|
|
37
|
+}
|