You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wechatoffice/cgi-bin.token.rdb.go

23 lines
580 B

package wechatoffice
import (
"context"
"time"
)
func (c *Client) GetAccessToken(ctx context.Context) string {
if c.cache.redisClient.Db == nil {
return c.config.accessToken
}
newCache := c.cache.redisClient.NewSimpleStringCache(c.cache.redisClient.NewStringOperation(), time.Second*7000)
newCache.DBGetter = func() string {
token := c.CgiBinToken(ctx)
return token.Result.AccessToken
}
return newCache.GetCache(ctx, c.getAccessTokenCacheKeyName())
}
func (c *Client) getAccessTokenCacheKeyName() string {
return c.cache.wechatAccessTokenPrefix + c.GetAppId()
}