51 protected function call($methodName, $additionalParams =
null, $licenseCheck =
false, $clearAccessSettings =
false)
55 if(!self::isServerAlive() && !defined(
'SALE_SRVS_RESTCLIENT_DISABLE_SRV_ALIVE_CHECK'))
60 self::ERROR_SERVICE_UNAVAILABLE
66 if ($clearAccessSettings)
69 $this->accessSettings =
null;
72 if (is_null($this->accessSettings))
74 $this->accessSettings = $this->getAccessSettings();
77 if (!$this->accessSettings)
83 if (!is_array($additionalParams))
84 $additionalParams = array();
86 $additionalParams = Encoding::convertEncodingArray($additionalParams, LANG_CHARSET,
"utf-8");
89 $additionalParams[
'client_id'] = $this->accessSettings[
'client_id'];
90 $additionalParams[
'client_secret'] = $this->accessSettings[
'client_secret'];
91 $additionalParams[
'lang'] = LANGUAGE_ID;
95 $additionalParams = static::signLicenseRequest($additionalParams, static::getLicense());
100 'socketTimeout' => $this->httpTimeout,
101 'streamTimeout' => $this->streamTimeout,
103 $postResult = @$http->post(
104 $host.static::REST_URI.$methodName,
117 if (!is_array($answer))
119 $result->addError(
new Error(
Loc::getMessage(
'SALE_SRV_BASE_REST_ANSWER_ERROR').
' '.$this->
getServiceHost().
'. (Status: "'.$http->getStatus().
'", Result: "'.$postResult.
'")', static::ERROR_SERVICE_UNAVAILABLE));
124 if(self::getLastUnSuccessCount() > 0)
127 if (array_key_exists(
'error', $answer))
129 if ($answer[
'error'] ===
'verification_needed')
133 $result->addError(
new Error($answer[
'error'].
". ".$answer[
'error_description'], self::ERROR_WRONG_LICENSE));
138 return $this->
call($methodName, $additionalParams,
true);
141 else if (($answer[
'error'] ===
'ACCESS_DENIED' || $answer[
'error'] ===
'Invalid client' || $answer[
'error'] ===
'NO_AUTH_FOUND')
142 && !$clearAccessSettings)
144 return $this->
call($methodName, $additionalParams,
true,
true);
147 $result->addError(
new Error($answer[
'error'].
". ".$answer[
'error_description']));
151 if ($answer[
'result'] ==
false)
152 $result->addError(
new Error(
'Nothing found', static::ERROR_NOTHING_FOUND));
154 if (is_array($answer[
'result']))
155 $result->addData($answer[
'result']);
188 protected function register()
193 $queryParams = array(
194 "scope" => static::SCOPE,
195 "redirect_uri" => static::getRedirectUri(),
198 $queryParams = static::signLicenseRequest($queryParams, static::getLicense());
200 $postResult = $httpClient->post($host.static::REGISTER_URI, $queryParams);
202 if ($postResult ===
false)
204 $result->addError(
new Error(implode(
"\n", $httpClient->getError()), static::ERROR_SERVICE_UNAVAILABLE));
210 $jsonResult = Json::decode($postResult);
214 $result->addError(
new Error($e->getMessage()));
218 if (!empty($jsonResult[
"error"]))
220 $result->addError(
new Error($jsonResult[
"error"], static::ERROR_WRONG_LICENSE));
224 $result->addData($jsonResult);
232 if(Loader::includeModule(
'bitrix24'))
234 $request[
'BX_TYPE'] =
'B24';
235 $request[
'BX_LICENCE'] = BX24_HOST_NAME;
236 $request[
'BX_HASH'] = \CBitrix24::RequestSign(md5(implode(
"|", $request)));
240 $request[
'BX_TYPE'] = ModuleManager::isModuleInstalled(
'intranet') ?
'CP' :
'BSM';
241 $request[
'BX_LICENCE'] = md5(
"BITRIX".$licenseKey.
"LICENCE");
242 $request[
'BX_HASH'] = md5(md5(implode(
"|", $request)).md5($licenseKey));
343 static $alreadySetted =
false;
345 if($alreadySetted && !$reset)
352 $alreadySetted =
true;
353 $last = static::getLastUnSuccessCallInfo();
355 $lastCount = (int)($last[
'COUNT'] ?? 0);
358 'COUNT' => $lastCount > 0 ? $lastCount + 1 : 1,
359 'TIMESTAMP' => time()
363 Option::set(
'sale', static::UNSUCCESSFUL_CALL_OPTION, $data);