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...

25 lines
623 B

2 years ago
package wechatoffice
import (
2 years ago
"context"
2 years ago
"fmt"
"time"
)
// GetJsapiTicket 获取api_ticket
2 years ago
func (c *Client) GetJsapiTicket(ctx context.Context) string {
2 years ago
if c.redisClient.Db == nil {
2 years ago
return c.config.JsapiTicket
}
2 years ago
newCache := c.redisClient.NewSimpleStringCache(c.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 {
return fmt.Sprintf("wechat_jsapi_ticket:%v", c.GetAppId())
}