File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed
Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ type Options struct {
2020 EncodingAESKey string // 回调消息加解密参数是AES密钥的Base64编码,用于解密回调消息内容对应的密文
2121 Cache cache.Cache // 数据缓存
2222 ExpireTime time.Duration // 令牌过期时间
23+ IsCloseCache bool // 是否关闭自动缓存AccessToken, 默认缓存
2324}
2425
2526// Client 微信客服实例
@@ -33,6 +34,7 @@ type Client struct {
3334 eventQueue sync.Map //事件队列
3435 mutex sync.Mutex
3536 accessToken string // 用户访问凭证
37+ isCloseCache bool // 是否自动缓存AccessToken, 默认缓存
3638}
3739
3840// New 初始化微信客服实例
@@ -54,6 +56,7 @@ func New(options Options) (client *Client, err error) {
5456 cache : options .Cache ,
5557 eventQueue : sync.Map {},
5658 mutex : sync.Mutex {},
59+ isCloseCache : options .IsCloseCache ,
5760 }
5861
5962 if err = client .initAccessToken (); err != nil {
Original file line number Diff line number Diff line change @@ -47,6 +47,14 @@ func (r *Client) RefreshAccessToken() error {
4747}
4848
4949func (r * Client ) initAccessToken () error {
50+ //如果关闭自动缓存则直接刷新AccessToken
51+ if r .isCloseCache {
52+ if err := r .RefreshAccessToken (); err != nil {
53+ return err
54+ }
55+ return nil
56+ }
57+
5058 //判断是否已初始化完成,如果己初始化则直接返回当前实例
5159 token , err := r .getAccessToken ()
5260 if err != nil {
You can’t perform that action at this time.
0 commit comments