- Модуль: socialservices
- Путь к файлу: ~/bitrix/modules/socialservices/classes/general/zoom.php
- Класс: CZoomInterface
- Вызов: CZoomInterface::getNewAccessToken
public function getNewAccessToken($refreshToken = false, $userId = 0, $save = false): bool
{
if (!$this->appID || !$this->appSecret)
{
return false;
}
if (!$refreshToken)
{
$refreshToken = $this->refresh_token;
}
$httpClient = new HttpClient(array(
'socketTimeout' => $this->httpTimeout,
'streamTimeout' => $this->httpTimeout,
));
$httpClient->setAuthorization($this->appID, $this->appSecret);
$queryPrams = http_build_query([
'refresh_token' => $refreshToken,
'grant_type' => 'refresh_token',
]);
$url = static::TOKEN_URL.'?'.$queryPrams;
$result = $httpClient->post($url);
try
{
$arResult = Json::decode($result);
}
catch (BitrixMainArgumentException $e)
{
$arResult = array();
}
if (!empty($arResult['access_token']))
{
$this->access_token = $arResult['access_token'];
$this->accessTokenExpires = $arResult['expires_in'] + time();
$this->refresh_token = $arResult['refresh_token'];
if ($save && (int)$userId > 0)
{
$dbSocservUser = BitrixSocialservicesUserTable::getList(array(
'filter' => array(
'=EXTERNAL_AUTH_ID' => static::SERVICE_ID,
'=USER_ID' => $userId,
),
'select' => array('ID')
));
if ($arOauth = $dbSocservUser->fetch())
{
BitrixSocialservicesUserTable::update($arOauth['ID'], array(
'OATOKEN' => $this->access_token,
'REFRESH_TOKEN' => $this->refresh_token,
'OATOKEN_EXPIRES' => $this->accessTokenExpires,
)
);
}
}
return true;
}
return false;
}