public function getAccessToken($force = false)
{
if ($this->_accessToken === null || $this->_accessToken['expire'] < YII_BEGIN_TIME || $force) {
$result = !$force && $this->_accessToken === null ? $this->getCache('access_token', false) : false;
if ($result === false) {
if (!($result = $this->requestAccessToken())) {
throw new HttpException(500, 'Fail to get access_token from wechat server.');
}
$this->trigger(self::EVENT_AFTER_ACCESS_TOKEN_UPDATE, new Event(['data' => $result]));
$this->setCache('access_token', $result, $result['expires_in']);
}
$this->setAccessToken($result);
}
return $this->_accessToken['token'];
}