mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
将小程序获取ak的方式也抽象出来
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
package miniprogram
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/silenceper/wechat/v2/credential"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/analysis"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/auth"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/basic"
|
||||
@@ -19,16 +18,19 @@ type MiniProgram struct {
|
||||
|
||||
//NewMiniProgram 实例化小程序API
|
||||
func NewMiniProgram(cfg *config.Config) *MiniProgram {
|
||||
if cfg.Cache == nil {
|
||||
panic("cache未设置")
|
||||
}
|
||||
defaultAkHandle := credential.NewDefaultAccessToken(cfg.AppID, cfg.AppSecret, credential.CacheKeyMiniProgramPrefix, cfg.Cache)
|
||||
ctx := &context.Context{
|
||||
Config: cfg,
|
||||
Config: cfg,
|
||||
AccessTokenHandle: defaultAkHandle,
|
||||
}
|
||||
ctx.SetAccessTokenLock(new(sync.RWMutex))
|
||||
return &MiniProgram{ctx}
|
||||
}
|
||||
|
||||
//SetAccessTokenHandle 自定义access_token获取方式
|
||||
func (miniProgram *MiniProgram) SetAccessTokenHandle(accessTokenHandle credential.AccessTokenHandle) {
|
||||
miniProgram.ctx.AccessTokenHandle = accessTokenHandle
|
||||
}
|
||||
|
||||
// GetContext get Context
|
||||
func (miniProgram *MiniProgram) GetContext() *context.Context {
|
||||
return miniProgram.ctx
|
||||
|
||||
Reference in New Issue
Block a user