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

officeaccount 和 miniprogram 添加UseStableAK 配置项 (#788)

This commit is contained in:
CyJaySong
2024-11-23 18:25:24 +08:00
committed by GitHub
parent 990ba6ede9
commit 3fbe8634d9
4 changed files with 16 additions and 2 deletions

View File

@@ -11,4 +11,5 @@ type Config struct {
Token string `json:"token"` // token
EncodingAESKey string `json:"encoding_aes_key"` // EncodingAESKey
Cache cache.Cache
UseStableAK bool // use the stable access_token
}

View File

@@ -49,7 +49,13 @@ type OfficialAccount struct {
// NewOfficialAccount 实例化公众号API
func NewOfficialAccount(cfg *config.Config) *OfficialAccount {
defaultAkHandle := credential.NewDefaultAccessToken(cfg.AppID, cfg.AppSecret, credential.CacheKeyOfficialAccountPrefix, cfg.Cache)
var defaultAkHandle credential.AccessTokenContextHandle
const cacheKeyPrefix = credential.CacheKeyOfficialAccountPrefix
if cfg.UseStableAK {
defaultAkHandle = credential.NewStableAccessToken(cfg.AppID, cfg.AppSecret, cacheKeyPrefix, cfg.Cache)
} else {
defaultAkHandle = credential.NewDefaultAccessToken(cfg.AppID, cfg.AppSecret, cacheKeyPrefix, cfg.Cache)
}
ctx := &context.Context{
Config: cfg,
AccessTokenHandle: defaultAkHandle,