mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
use context when getting access token (#815)
* use context Signed-off-by: mqf20 <mingqingfoo@gmail.com> * added docs Signed-off-by: mqf20 <mingqingfoo@gmail.com> * improved docs Signed-off-by: mqf20 <mingqingfoo@gmail.com> * added SetAccessTokenContextHandle Signed-off-by: mqf20 <mingqingfoo@gmail.com> --------- Signed-off-by: mqf20 <mingqingfoo@gmail.com>
This commit is contained in:
@@ -42,15 +42,22 @@ func NewMiniProgram(cfg *config.Config) *MiniProgram {
|
||||
defaultAkHandle = credential.NewDefaultAccessToken(cfg.AppID, cfg.AppSecret, cacheKeyPrefix, cfg.Cache)
|
||||
}
|
||||
ctx := &context.Context{
|
||||
Config: cfg,
|
||||
AccessTokenHandle: defaultAkHandle,
|
||||
Config: cfg,
|
||||
AccessTokenContextHandle: defaultAkHandle,
|
||||
}
|
||||
return &MiniProgram{ctx}
|
||||
}
|
||||
|
||||
// SetAccessTokenHandle 自定义 access_token 获取方式
|
||||
func (miniProgram *MiniProgram) SetAccessTokenHandle(accessTokenHandle credential.AccessTokenHandle) {
|
||||
miniProgram.ctx.AccessTokenHandle = accessTokenHandle
|
||||
miniProgram.ctx.AccessTokenContextHandle = credential.AccessTokenCompatibleHandle{
|
||||
AccessTokenHandle: accessTokenHandle,
|
||||
}
|
||||
}
|
||||
|
||||
// SetAccessTokenContextHandle 自定义 access_token 获取方式
|
||||
func (miniProgram *MiniProgram) SetAccessTokenContextHandle(accessTokenContextHandle credential.AccessTokenContextHandle) {
|
||||
miniProgram.ctx.AccessTokenContextHandle = accessTokenContextHandle
|
||||
}
|
||||
|
||||
// GetContext get Context
|
||||
|
||||
Reference in New Issue
Block a user