1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-09 15:12:26 +08:00
Files
wechat/openplatform/officialaccount/officialaccount.go
2020-05-23 12:02:55 +08:00

34 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package officialaccount
import (
"github.com/silenceper/wechat/v2/officialaccount"
offConfig "github.com/silenceper/wechat/v2/officialaccount/config"
offContext "github.com/silenceper/wechat/v2/officialaccount/context"
opContext "github.com/silenceper/wechat/v2/openplatform/context"
)
//OfficialAccount 代公众号实现业务
type OfficialAccount struct {
//授权的公众号的appID
appID string
*officialaccount.OfficialAccount
opContext *opContext.Context
}
//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.GetContext().SetGetAccessTokenFunc(func(offCtx *offContext.Context) (accessToken string, err error) {
// 获取授权方的access_token
return opCtx.GetAuthrAccessToken(appID)
})
return &OfficialAccount{appID: appID, OfficialAccount: officialAccount}
}