1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
transport.php
См. документацию.
1<?php
2namespace Bitrix\Rest\Marketplace;
3
4use Bitrix\Main\ArgumentException;
5use Bitrix\Main\Context;
6use Bitrix\Main\Loader;
7use Bitrix\Main\ModuleManager;
8use Bitrix\Main\Config\Option;
9use Bitrix\Main\Web\HttpClient;
10use Bitrix\Main\Web\Json;
11use Bitrix\Main\Web\Uri;
12
13if (!defined('REST_MARKETPLACE_URL'))
14{
15 define('REST_MARKETPLACE_URL', '');
16}
17
19{
21 const SERVICE_URL = REST_MARKETPLACE_URL;
22 protected const VERSION = 1;
23 private const API_VERSION = 1;
24
25 protected string $serviceDomain = '';
26 private const DEFAULT_SERVICE_REGION = 'en';
27 private const SERVICE_DOMAIN_LIST = [
28 'en' => 'https://util.bitrixsoft.com/',
29
30 'ru' => 'https://util.1c-bitrix.ru/',
31 'am' => 'https://util.1c-bitrix.ru/',
32 'az' => 'https://util.1c-bitrix.ru/',
33 'ge' => 'https://util.1c-bitrix.ru/',
34
35 'kz' => 'https://util.1c-bitrix.kz/',
36 'kg' => 'https://util.1c-bitrix.kz/',
37 'uz' => 'https://util.1c-bitrix.kz/',
38
39 'by' => 'https://util.1c-bitrix.by/',
40 ];
41 public const SERVICE_TYPE_APP = 'APP';
42 public const SERVICE_TYPE_COUPON = 'COUPON';
43 private const SERVICE_URN_LIST = [
44 self::SERVICE_TYPE_APP => 'b24/apps.php',
45 self::SERVICE_TYPE_COUPON => 'b24/b24_coupon.php',
46 ];
47
48 const SOCKET_TIMEOUT = 10;
49 const STREAM_TIMEOUT = 10;
50
51 const METHOD_GET_LAST = 'get_last';
52 const METHOD_GET_DEV = 'get_dev';
53 const METHOD_GET_BEST = 'get_best';
54 const METHOD_GET_SALE_OUT = 'get_sale_out';
55 const METHOD_GET_BUY = 'get_buy';
56 const METHOD_GET_UPDATES = 'get_updates';
57
61 const METHOD_GET_IMMUNE = 'get_immune';
62 const METHOD_GET_CATEGORIES = 'get_categories';
63 const METHOD_GET_CATEGORY = 'get_category';
64 const METHOD_GET_TAG = 'get_tag';
65 const METHOD_GET_APP = 'get_app';
66 const METHOD_GET_APP_PUBLIC = 'get_app_public';
67 const METHOD_GET_INSTALL = 'get_app_install';
68 const METHOD_SET_INSTALL = 'is_installed';
69 const METHOD_SEARCH_APP = 'search_app';
70 const METHOD_FILTER_APP = 'search_app_adv';
71 const METHOD_GET_SITE_LIST = 'sites_list';
72 const METHOD_GET_SITE_ITEM = 'sites_item';
73
74 public const DICTIONARY_IMMUNE_LIST = 'immune_list';
75
76 private const DICTIONARY_JSON_LIST = [
77 self::DICTIONARY_IMMUNE_LIST => 'market_immune.json',
78 ];
79
80 protected static $instance = null;
81
87 public static function instance()
88 {
89 if(static::$instance == null)
90 {
91 static::$instance = new self();
92 }
93
94 return static::$instance;
95 }
96
97
98 public function __construct()
99 {
100 if (Loader::includeModule('bitrix24'))
101 {
102 $region = \CBitrix24::getLicensePrefix();
103 }
104 else
105 {
106 $region = Option::get('main', '~PARAM_CLIENT_LANG', LANGUAGE_ID);
107 }
108 $this->serviceDomain = self::SERVICE_DOMAIN_LIST[$region] ?? self::SERVICE_DOMAIN_LIST[self::DEFAULT_SERVICE_REGION];
109 }
110
117 public function getServiceUrl(string $type = self::SERVICE_TYPE_APP): string
118 {
119 if ($type === self::SERVICE_TYPE_APP && !empty(self::SERVICE_URL))
120 {
121 return self::SERVICE_URL;
122 }
123
124 return self::SERVICE_URN_LIST[$type] ? $this->serviceDomain . self::SERVICE_URN_LIST[$type] : '';
125 }
126
127 public function call($method, $fields = array())
128 {
130
131 $httpClient = new HttpClient(array(
132 'socketTimeout' => static::SOCKET_TIMEOUT,
133 'streamTimeout' => static::STREAM_TIMEOUT,
134 ));
135
136 $response = $httpClient->post($this->getServiceUrl(), $query);
137
138 return $this->prepareAnswer($response);
139 }
140
141 public function getDictionary(string $dictionary): array|false
142 {
143 $jsonName = static::DICTIONARY_JSON_LIST[$dictionary] ?? null;
144
145 if (!isset($jsonName))
146 {
147 return false;
148 }
149
150 $uri = new Uri($this->serviceDomain);
151 $uri->setPath('/dictionary/' . $jsonName);
152
153 $httpClient = new HttpClient();
154 $response = $httpClient->get($uri);
155
156 return $this->prepareAnswer($response);
157 }
158
159 public function batch($actions)
160 {
161 $query = array();
162
163 foreach($actions as $key => $batch)
164 {
165 if (!isset($batch[1]))
166 {
167 $batch[1] = [];
168 }
169 $query[$key] = $this->prepareQuery($batch[0], $batch[1]);
170 }
171
172 $query = array('batch' => $query);
173
174 $httpClient = new HttpClient();
175 $response = $httpClient->post($this->getServiceUrl(), $query);
176
177 return $this->prepareAnswer($response);
178 }
179
180 protected function prepareQuery($method, $fields)
181 {
182 if(!is_array($fields))
183 {
184 $fields = array();
185 }
186
187 $fields['action'] = $method;
188 $fields['apiVersion'] = self::API_VERSION;
189
191 {
192 $fields['queryVersion'] = static::VERSION;
193 }
194 $fields['lang'] = LANGUAGE_ID;
195 $fields['bsm'] = ModuleManager::isModuleInstalled('intranet') ? '0' : '1';
196
197 if(Loader::includeModule('bitrix24') && defined('BX24_HOST_NAME'))
198 {
199 $fields['tariff'] = \CBitrix24::getLicensePrefix();
200 $fields['host_name'] = BX24_HOST_NAME;
201 }
202 else
203 {
204 $request = Context::getCurrent()->getRequest();
205 $fields['host_name'] = $request->getHttpHost();
206 @include($_SERVER['DOCUMENT_ROOT'] . '/bitrix/license_key.php');
207 $fields['license_key'] = ($LICENSE_KEY == 'DEMO') ? 'DEMO' : md5('BITRIX' . $LICENSE_KEY . 'LICENCE');
208 }
209
210 return $fields;
211 }
212
213 protected function prepareAnswer($response)
214 {
215 $responseData = false;
216 if($response && $response <> '')
217 {
218 try
219 {
220 $responseData = Json::decode($response);
221 }
222 catch(ArgumentException $e)
223 {
224 $responseData = false;
225 }
226 }
227 return is_array($responseData) ? $responseData : false;
228 }
229}
$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 isModuleInstalled($moduleName)
Определения modulemanager.php:125
Определения uri.php:17
static isSubscriptionAccess()
Определения client.php:650
const METHOD_GET_BUY
Определения transport.php:55
prepareQuery($method, $fields)
Определения transport.php:180
static instance()
Определения transport.php:87
const METHOD_GET_INSTALL
Определения transport.php:67
const METHOD_GET_IMMUNE
Определения transport.php:61
const METHOD_GET_LAST
Определения transport.php:51
const METHOD_GET_DEV
Определения transport.php:52
const DICTIONARY_IMMUNE_LIST
Определения transport.php:74
const METHOD_SEARCH_APP
Определения transport.php:69
const METHOD_GET_APP
Определения transport.php:65
const METHOD_GET_SITE_LIST
Определения transport.php:71
const STREAM_TIMEOUT
Определения transport.php:49
getDictionary(string $dictionary)
Определения transport.php:141
const METHOD_SET_INSTALL
Определения transport.php:68
prepareAnswer($response)
Определения transport.php:213
const METHOD_GET_BEST
Определения transport.php:53
const METHOD_GET_SALE_OUT
Определения transport.php:54
const METHOD_FILTER_APP
Определения transport.php:70
const METHOD_GET_CATEGORY
Определения transport.php:63
const SERVICE_TYPE_APP
Определения transport.php:41
const METHOD_GET_APP_PUBLIC
Определения transport.php:66
const METHOD_GET_UPDATES
Определения transport.php:56
const SERVICE_TYPE_COUPON
Определения transport.php:42
const SOCKET_TIMEOUT
Определения transport.php:48
const METHOD_GET_SITE_ITEM
Определения transport.php:72
const METHOD_GET_TAG
Определения transport.php:64
call($method, $fields=array())
Определения transport.php:127
batch($actions)
Определения transport.php:159
string $serviceDomain
Определения transport.php:25
getServiceUrl(string $type=self::SERVICE_TYPE_APP)
Определения transport.php:117
const METHOD_GET_CATEGORIES
Определения transport.php:62
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$query
Определения get_search.php:11
$region
Определения .description.php:13
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения urlrewrite.php:61
return false
Определения prolog_main_admin.php:185
if(empty($signedUserToken)) $key
Определения quickway.php:257
$response
Определения result.php:21
$method
Определения index.php:27
$fields
Определения yandex_run.php:501