-
Notifications
You must be signed in to change notification settings - Fork 174
/
accessToken.go
46 lines (38 loc) · 1.15 KB
/
accessToken.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
package auth
// #reference: https://developer.work.weixin.qq.com/document/path/91039
import (
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel"
)
type AccessToken struct {
*kernel.AccessToken
}
// https://developer.work.weixin.qq.com/document/path/91039
func NewAccessToken(app kernel.ApplicationInterface) (*AccessToken, error) {
kernelToken, err := kernel.NewAccessToken(&app)
if err != nil {
return nil, err
}
token := &AccessToken{
kernelToken,
}
// Override fields and functions
token.EndpointToGetToken = "cgi-bin/gettoken"
token.OverrideGetCredentials()
return token, nil
}
// Override GetCredentials
func (accessToken *AccessToken) OverrideGetCredentials() {
config := (*accessToken.App).GetConfig()
accessToken.GetCredentials = func() *object.StringMap {
return &object.StringMap{
// this is for the cached key encoded
"appid": config.GetString("corp_id", ""),
"secret": config.GetString("secret", ""),
"neededText": "",
// this is for the real credentials
"corpid": config.GetString("corp_id", ""),
"corpsecret": config.GetString("secret", ""),
}
}
}