• Модуль: socialservices
  • Путь к файлу: ~/bitrix/modules/socialservices/lib/properties/client.php
  • Класс: BitrixSocialservicesPropertiesClient
  • Вызов: Client::call
protected function call($methodName, $additionalParams = null, $licenseCheck = false, $clearAccessSettings = false)
{
	$this->errorCollection->clear();

	if($clearAccessSettings)
		$this->clearAccessSettings();

	if(is_null($this->accessSettings))
		$this->accessSettings = $this->getAccessSettings();

	if($this->accessSettings === false)
		return false;

	if(!is_array($additionalParams))
	{
		$additionalParams = array();
	}
	else
	{
		$additionalParams = Encoding::convertEncodingArray($additionalParams, LANG_CHARSET, "utf-8");
	}

	$additionalParams['client_id'] = $this->accessSettings['client_id'];
	$additionalParams['client_secret'] = $this->accessSettings['client_secret'];
	if($licenseCheck)
		$additionalParams['key'] = static::getLicenseHash();

	$http = new HttpClient(array('socketTimeout' => $this->httpTimeout));
	$result = $http->post(
			static::SERVICE_HOST.static::REST_URI.$methodName,
			$additionalParams
	);

	if($result === false)
	{
		$httpErrors = $http->getError();
		foreach ($httpErrors as $errorCode => $errorText)
		{
			$this->errorCollection->add(array(new Error($errorText, $errorCode)));
		}
		return false;
	}

	$answer = $this->prepareAnswer($result);

	if(!is_array($answer) || count($answer) == 0)
	{
		$this->errorCollection->add(array(new Error('Malformed answer from service: '.$http->getStatus().' '.$result, static::ERROR_SERVICE_UNAVAILABLE)));
		return false;
	}

	if(array_key_exists('error', $answer))
	{
		if($answer['error'] === 'verification_needed' && !$licenseCheck)
		{
			return $this->call($methodName, $additionalParams, true);
		}
		else if(($answer['error'] === 'ACCESS_DENIED' || $answer['error'] === 'Invalid client')
				&& !$clearAccessSettings)
		{
			return $this->call($methodName, $additionalParams, true, true);
		}

		$this->errorCollection->add(array(new Error($answer['error_description'], $answer['error'])));
		return false;
	}

	if($answer['result'] == false)
	{
		$this->errorCollection->add(array(new Error(Loc::getMessage('SALE_PROPERTIES_ERROR_NOTHING_FOUND'), static::ERROR_NOTHING_FOUND)));
	}

	return $answer['result'];
}