• Модуль: socialservices
  • Путь к файлу: ~/bitrix/modules/socialservices/lib/integration/zoom/downloadagent.php
  • Класс: BitrixSocialservicesIntegrationZoomDownloadAgent
  • Вызов: DownloadAgent::download
static function download(string $recordingUrl, string $downloadToken, string $fileName): Result
{
	$result = new Result();

	$tempPath = CFile::GetTempName('', $fileName);
	IODirectory::createDirectory(IOPath::getDirectory($tempPath));
	if(IODirectory::isDirectoryExists(IOPath::getDirectory($tempPath)) === false)
	{
		return $result->addError(new Error("Error creating temporary directory {$tempPath}"));
	}
	$tempFile = new IOFile($tempPath);
	$handler = $tempFile->open("w+");
	if($handler === false)
	{
		return $result->addError(new Error("Error opening temporary file {$tempPath}"));
	}

	$http = new HttpClient();
	$http->setHeader("Authorization",  "Bearer {$downloadToken}");
	$http->query("GET", $recordingUrl);
	$statusCode = $http->getStatus();
	if($statusCode !== 200)
	{
		return $result->addError(new Error("Service response status code is {$statusCode}"));
	}

	$http->setOutputStream($handler);
	$http->getResult();
	$tempFile->close();

	return $result->setData([
		'file' => $tempPath
	]);
}