-
Notifications
You must be signed in to change notification settings - Fork 0
/
officialaccount.go
48 lines (42 loc) · 1.47 KB
/
officialaccount.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
package officialaccount
import (
"github.com/fideism/golang-wechat/credential"
"github.com/fideism/golang-wechat/officialaccount"
offConfig "github.com/fideism/golang-wechat/officialaccount/config"
opContext "github.com/fideism/golang-wechat/openplatform/context"
)
//OfficialAccount 代公众号实现业务
type OfficialAccount struct {
//授权的公众号的appID
appID string
*officialaccount.OfficialAccount
}
//NewOfficialAccount 实例化
//appID :为授权方公众号 APPID,非开放平台第三方平台 APPID
func NewOfficialAccount(opCtx *opContext.Context, appID string) *OfficialAccount {
officialAccount := officialaccount.NewOfficialAccount(&offConfig.Config{
AppID: opCtx.AppID,
EncodingAESKey: opCtx.EncodingAESKey,
Token: opCtx.Token,
Cache: opCtx.Cache,
})
//设置获取access_token的函数
officialAccount.SetAccessTokenHandle(NewDefaultAuthrAccessToken(opCtx, appID))
return &OfficialAccount{appID: appID, OfficialAccount: officialAccount}
}
//DefaultAuthrAccessToken 默认获取授权ak的方法
type DefaultAuthrAccessToken struct {
opCtx *opContext.Context
appID string
}
//NewDefaultAuthrAccessToken New
func NewDefaultAuthrAccessToken(opCtx *opContext.Context, appID string) credential.AccessTokenHandle {
return &DefaultAuthrAccessToken{
opCtx: opCtx,
appID: appID,
}
}
//GetAccessToken 获取ak
func (ak *DefaultAuthrAccessToken) GetAccessToken() (string, error) {
return ak.opCtx.GetAuthrAccessToken(ak.appID)
}