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.ticket.getticket.rd...

24 lines
629 B

2 years ago
package wechatoffice
import (
2 years ago
"context"
2 years ago
"time"
)
// GetJsapiTicket 获取api_ticket
2 years ago
func (c *Client) GetJsapiTicket(ctx context.Context) string {
2 years ago
if c.cache.redisClient.Db == nil {
return c.config.jsapiTicket
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.CgiBinTicketGetTicket(ctx, "jsapi")
2 years ago
return token.Result.Ticket
}
2 years ago
return newCache.GetCache(ctx, c.getJsapiTicketCacheKeyName())
2 years ago
}
func (c *Client) getJsapiTicketCacheKeyName() string {
2 years ago
return c.cache.wechatJsapiTicketPrefix + c.GetAppId()
2 years ago
}