public function getJsApiTicket($force = false)
{
$time = time();
// 为了更精确控制.取当前时间计算
if ($this->_jsApiTicket === null || $this->_jsApiTicket['expire'] < $time || $force) {
$result = $this->_jsApiTicket === null && !$force ? $this->getCache('js_api_ticket', false) : false;
if ($result === false) {
if (!($result = $this->requestJsApiTicket())) {
throw new HttpException(500, 'Fail to get jsapi_ticket from wechat server.');
}
$result['expire'] = $time + $result['expires_in'];
$this->trigger(self::EVENT_AFTER_JS_API_TICKET_UPDATE, new Event(['data' => $result]));
$this->setCache('js_api_ticket', $result, $result['expires_in']);
}
$this->setJsApiTicket($result);
}
return $this->_jsApiTicket['ticket'];
}