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

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