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.
24 lines
589 B
24 lines
589 B
package wechatunion
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
func (c *Client) GetAccessToken(ctx context.Context) string {
|
|
if c.config.RedisClient.Db == nil {
|
|
return c.config.AccessToken
|
|
}
|
|
newCache := c.config.RedisClient.NewSimpleStringCache(c.config.RedisClient.NewStringOperation(), time.Second*7000)
|
|
newCache.DBGetter = func() string {
|
|
token := c.CgiBinToken(ctx)
|
|
return token.Result.AccessToken
|
|
}
|
|
return newCache.GetCache(c.getAccessTokenCacheKeyName())
|
|
}
|
|
|
|
func (c *Client) getAccessTokenCacheKeyName() string {
|
|
return fmt.Sprintf("wechat_access_token:%v", c.getAppId())
|
|
}
|