callmez\wechat\sdk\Wechat::getJsApiTicket PHP Method

getJsApiTicket() public method

获取jsapi_ticket 会自动判断超时时间然后重新获取新的ticket (会智能缓存jsApiTicket)
public getJsApiTicket ( boolean $force = false ) : mixed
$force boolean
return mixed
    public function getJsApiTicket($force = false)
    {
        if ($this->_jsApiTicket === null || $this->_jsApiTicket['expire'] < YII_BEGIN_TIME || $force) {
            $result = !$force && $this->_jsApiTicket === null ? $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.');
                }
                $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'];
    }
Wechat