1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-13 01:02:27 +08:00

开放平台基本框架

This commit is contained in:
silenceper
2020-01-21 16:36:34 +08:00
parent 15ebd71a04
commit 7e8c94a6c4
11 changed files with 401 additions and 7 deletions

View File

@@ -0,0 +1,32 @@
package officialaccount
import (
"github.com/silenceper/wechat/officialaccount"
offConfig "github.com/silenceper/wechat/officialaccount/config"
offContext "github.com/silenceper/wechat/officialaccount/context"
opContext "github.com/silenceper/wechat/openplatform/context"
)
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}
}