1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
sender.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale\Internals\Analytics;
4
5use Bitrix\Main;
6
11final class Sender
12{
13 protected const URL = '/analytics.php';
14
16 private $type;
17
19 private $data;
20
26 public function __construct(string $type, array $data)
27 {
28 $this->type = $type;
29 $this->data = $data;
30 }
31
35 public function send(): bool
36 {
37 if ($this->data)
38 {
39 $postData = $this->getCommonData();
40 $postData['content'] = $this->data;
41 $postData['bx_hash'] = self::signRequest($postData);
43
44 $httpClient = new Main\Web\HttpClient();
45 $response = $httpClient->post(
46 Main\Application::getInstance()->getLicense()->getDomainStoreLicense() . self::URL,
48 );
49 if (!$response || $httpClient->getStatus() !== 200)
50 {
51 return false;
52 }
53
54 try
55 {
57 if ($response['result'] !== 'ok')
58 {
59 return false;
60 }
61 }
63 {
64 return false;
65 }
66 }
67
68 return true;
69 }
70
74 private function getCommonData(): array
75 {
76 $isB24 = self::isB24();
77 $data = [
78 'type' => $isB24 ? 'b24' : 'self_hosted',
79 'date_time' => (new Main\Type\DateTime())->format('Y-m-d H:i:s'),
80 'transaction_type' => $this->type,
81 'host_name' => self::getHostName(),
82 ];
83
84 if($isB24)
85 {
86 $data['tariff'] = \CBitrix24::getLicensePrefix();
87 }
88 else
89 {
91 }
92
93 return $data;
94 }
95
100 private static function signRequest(array $request): string
101 {
102 $requestHash = md5(serialize($request));
103
104 if (Main\Loader::includeModule('bitrix24'))
105 {
106 return \CBitrix24::RequestSign($requestHash);
107 }
108
109 $privateKey = Main\Analytics\Counter::getPrivateKey();
110 return md5($requestHash.$privateKey);
111 }
112
116 private static function getHostName(): string
117 {
118 if (self::isB24())
119 {
120 $hostName = BX24_HOST_NAME;
121 }
122 else
123 {
124 $hostName = Main\Config\Option::get('main', 'server_name');
125 if (!$hostName)
126 {
127 $hostName = (defined('SITE_SERVER_NAME') && !empty(SITE_SERVER_NAME)) ? SITE_SERVER_NAME : '';
128 }
129
130 if (!$hostName)
131 {
132 $request = Main\Context::getCurrent()->getRequest();
133 $hostName = $request->getHttpHost();
134 }
135 }
136
137 return (string)$hostName;
138 }
139
143 private static function isB24(): bool
144 {
145 return Main\Loader::includeModule('bitrix24');
146 }
147}
$type
Определения options.php:106
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
static getAccountId()
Определения counter.php:62
static decode($data)
Определения json.php:50
static encode($data, $options=null)
Определения json.php:22
__construct(string $type, array $data)
Определения sender.php:26
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$response
Определения result.php:21
$postData
Определения index.php:29