• Модуль: landing
  • Путь к файлу: ~/bitrix/modules/landing/lib/external/site24.php
  • Класс: BitrixLandingExternalSite24
  • Вызов: Site24::Execute
static function Execute($operation, $params = array())
{
	$params['operation'] = $operation;

	$license = Application::getInstance()->getLicense();
	$params['key'] = $license->getPublicHashKey();
	$params['keysign'] = $license->getHashLicenseKey();
	$params['host']= BitrixMainConfigOption::get('intranet', 'portal_url', null);

	if (!$params['host'])
	{
		$params['host']= BitrixMainConfigOption::get(
			'landing',
			'portal_url',
			$_SERVER['HTTP_HOST']
		);
	}

	if (!$params['host'])
	{
		$params['host'] = $_SERVER['HTTP_HOST'];
	}

	$params['host'] = trim($params['host']);

	if (
		mb_strpos($params['host'], 'http://') === 0 ||
		mb_strpos($params['host'], 'https://') === 0
	)
	{
		$parseHost = parse_url($params['host']);
		if (isset($parseHost['host']))
		{
			$params['host'] = $parseHost['host'];
			if (isset($parseHost['port']))
			{
				$params['host'] .= ':' . $parseHost['port'];
			}
		}
	}

	if (!isset($params['lang']) || !$params['lang'])
	{
		unset($params['lang']);
	}

	$httpClient = new BitrixMainWebHttpClient(array(
		'socketTimeout' => 5,
		'streamTimeout' => 30
	));

	$httpClient->setHeader('User-Agent', 'Bitrix24 Sites');
	$answer = $httpClient->post('https://pub.bitrix24.site/pub.php', $params);

	$result = '';
	if ($answer && $httpClient->getStatus() == '200')
	{
		$result = $httpClient->getResult();
	}

	if ($result <> '')
	{
		try
		{
			$result = BitrixMainWebJson::decode($result);
		}
		catch(BitrixMainArgumentException $e)
		{
			throw new SystemException('Bad response');
		}

		if ($result['result'] === 'Bad license')
		{
			throw new SystemException('Bad license');
		}

		return $result['result'];
	}

	throw new SystemException('Bad response');
    }