-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl_builder.go
70 lines (53 loc) · 1.4 KB
/
url_builder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package qq_miniprogram
import "net/url"
const (
// BaseURL 基础URL
baseURL = "https://api.q.qq.com"
codeAPI = "/sns/jscode2session"
tokenAPI = "/api/getToken"
sendCustomMessage = "/api/json/template/send"
)
func CodeToURL(appId, appSecret, code string) (s string, err error) {
if appId == "" || appSecret == "" || code == "" {
return s, ErrNotAllowEmptyParam
}
u, err := url.Parse(baseURL + codeAPI)
if err != nil {
return s, err
}
query := u.Query()
query.Set("appid", appId)
query.Set("secret", appSecret)
query.Set("js_code", code)
query.Set("grant_type", "authorization_code")
u.RawQuery = query.Encode()
return u.String(), nil
}
func TokenURL(appId, appSecret string) (s string, err error) {
if appId == "" || appSecret == "" {
return s, ErrNotAllowEmptyParam
}
u, err := url.Parse(baseURL + tokenAPI)
if err != nil {
return s, err
}
query := u.Query()
query.Set("appid", appId)
query.Set("secret", appSecret)
query.Set("grant_type", "client_credential")
u.RawQuery = query.Encode()
return u.String(), nil
}
func SendCustomMessageURL(accessToken string) (s string, err error) {
if accessToken == "" {
return s, ErrNotAllowEmptyParam
}
u, err := url.Parse(baseURL + sendCustomMessage)
if err != nil {
return s, err
}
query := u.Query()
query.Set("access_token", accessToken)
u.RawQuery = query.Encode()
return u.String(), nil
}