forked from chanxuehong/wechat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
endpoint.go
42 lines (33 loc) · 1.14 KB
/
endpoint.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
package oauth2
import (
"net/url"
"github.com/charsunny/wechat/oauth2"
)
var _ oauth2.Endpoint = (*Endpoint)(nil)
// Endpoint 实现了 github.com/charsunny/wechat/oauth2.Endpoint 接口.
type Endpoint struct {
AppId string
AppSecret string
}
func NewEndpoint(AppId, AppSecret string) *Endpoint {
return &Endpoint{
AppId: AppId,
AppSecret: AppSecret,
}
}
func (p *Endpoint) ExchangeTokenURL(code string) string {
return "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + url.QueryEscape(p.AppId) +
"&secret=" + url.QueryEscape(p.AppSecret) +
"&code=" + url.QueryEscape(code) +
"&grant_type=authorization_code"
}
func (p *Endpoint) RefreshTokenURL(refreshToken string) string {
return "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=" + url.QueryEscape(p.AppId) +
"&grant_type=refresh_token&refresh_token=" + url.QueryEscape(refreshToken)
}
func (p *Endpoint) SessionCodeUrl(code string) string {
return "https://api.weixin.qq.com/sns/jscode2session?appid=" + url.QueryEscape(p.AppId) +
"&secret=" + url.QueryEscape(p.AppSecret) +
"&js_code=" + url.QueryEscape(code) +
"&grant_type=authorization_code"
}