public static function getJsApiTicket($type = 'jsapi')
{
$cacheKey = parent::getApi()->getAppId() . $type . 'jsapi_ticket';
$ticket = Cache::get($cacheKey);
if ($ticket !== false) {
return $ticket;
}
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type={$type}&access_token=ACCESS_TOKEN";
$data = parent::request($url);
$ticket = $data['ticket'];
//jsapi_ticket的有效期为7200秒
Cache::set($cacheKey, $ticket, $data['expires_in'] - 200);
return $ticket;
}