-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
officialaccount.go
61 lines (53 loc) · 1.96 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
49
50
51
52
53
54
55
56
57
58
59
60
61
package officialaccount
import (
"context"
"github.com/donetkit/wechat/credential"
"github.com/donetkit/wechat/officialaccount"
offConfig "github.com/donetkit/wechat/officialaccount/config"
opContext "github.com/donetkit/wechat/openplatform/context"
"github.com/donetkit/wechat/openplatform/officialaccount/js"
"github.com/donetkit/wechat/openplatform/officialaccount/oauth"
)
// 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}
}
// PlatformOauth 平台代发起oauth2网页授权
func (officialAccount *OfficialAccount) PlatformOauth() *oauth.Oauth {
return oauth.NewOauth(officialAccount.GetContext())
}
// PlatformJs 平台代获取js-sdk配置
func (officialAccount *OfficialAccount) PlatformJs() *js.Js {
return js.NewJs(officialAccount.GetContext(), officialAccount.appID)
}
// 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(ctx context.Context) (string, error) {
return ak.opCtx.GetAuthAccessToken(ctx, ak.appID)
}