12 protected const URL =
'https://util.1c-bitrix.ru/analytics.php';
33 public function send(): bool
37 $postData = $this->getCommonData();
38 $postData[
'content'] = $this->data;
39 $postData[
'bx_hash'] = self::signRequest($postData);
40 $postData = Main\Web\Json::encode($postData);
43 $response = $httpClient->post(self::URL, $postData);
44 if (!$response || $httpClient->getStatus() !== 200)
51 $response = Main\Web\Json::decode($response);
52 if ($response[
'result'] !==
'ok')
69 private function getCommonData(): array
71 $isB24 = self::isB24();
73 'type' => $isB24 ?
'b24' :
'self_hosted',
75 'transaction_type' => $this->type,
76 'host_name' => self::getHostName(),
81 $data[
'tariff'] = \CBitrix24::getLicensePrefix();
85 $data[
'license_key'] = Main\Analytics\Counter::getAccountId();
95 private static function signRequest(array $request): string
97 $requestHash = md5(serialize($request));
99 if (Main\Loader::includeModule(
'bitrix24'))
101 return \CBitrix24::RequestSign($requestHash);
104 $privateKey = Main\Analytics\Counter::getPrivateKey();
105 return md5($requestHash.$privateKey);
111 private static function getHostName(): string
115 $hostName = BX24_HOST_NAME;
119 $hostName = Main\Config\Option::get(
'main',
'server_name');
122 $hostName = (defined(
'SITE_SERVER_NAME') && !empty(SITE_SERVER_NAME)) ? SITE_SERVER_NAME :
'';
127 $request = Main\Context::getCurrent()->getRequest();
128 $hostName = $request->getHttpHost();
132 return (
string)$hostName;
138 private static function isB24(): bool
140 return Main\Loader::includeModule(
'bitrix24');