1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
transport.php
См. документацию.
1
<?php
2
namespace
Bitrix\Rest\Marketplace;
3
4
use Bitrix\Main\ArgumentException;
5
use Bitrix\Main\Context;
6
use Bitrix\Main\Loader;
7
use Bitrix\Main\ModuleManager;
8
use Bitrix\Main\Config\Option;
9
use Bitrix\Main\Web\HttpClient;
10
use Bitrix\Main\Web\Json;
11
use Bitrix\Main\Web\Uri;
12
13
if
(!defined(
'REST_MARKETPLACE_URL'
))
14
{
15
define(
'REST_MARKETPLACE_URL'
,
''
);
16
}
17
18
class
Transport
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
{
129
$query
= $this->
prepareQuery
(
$method
,
$fields
);
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
190
if
(
Client::isSubscriptionAccess
())
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
$type
Определения
options.php:106
$request
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения
catalog_reindex.php:36
Bitrix\Main\ArgumentException
Определения
ArgumentException.php:9
Bitrix\Main\ModuleManager\isModuleInstalled
static isModuleInstalled($moduleName)
Определения
modulemanager.php:125
Bitrix\Main\Web\HttpClient
Определения
httpclient.php:24
Bitrix\Main\Web\Uri
Определения
uri.php:17
Bitrix\Rest\Marketplace\Client\isSubscriptionAccess
static isSubscriptionAccess()
Определения
client.php:650
Bitrix\Rest\Marketplace\Transport
Определения
transport.php:19
Bitrix\Rest\Marketplace\Transport\METHOD_GET_BUY
const METHOD_GET_BUY
Определения
transport.php:55
Bitrix\Rest\Marketplace\Transport\prepareQuery
prepareQuery($method, $fields)
Определения
transport.php:180
Bitrix\Rest\Marketplace\Transport\__construct
__construct()
Определения
transport.php:98
Bitrix\Rest\Marketplace\Transport\instance
static instance()
Определения
transport.php:87
Bitrix\Rest\Marketplace\Transport\METHOD_GET_INSTALL
const METHOD_GET_INSTALL
Определения
transport.php:67
Bitrix\Rest\Marketplace\Transport\METHOD_GET_IMMUNE
const METHOD_GET_IMMUNE
Определения
transport.php:61
Bitrix\Rest\Marketplace\Transport\METHOD_GET_LAST
const METHOD_GET_LAST
Определения
transport.php:51
Bitrix\Rest\Marketplace\Transport\METHOD_GET_DEV
const METHOD_GET_DEV
Определения
transport.php:52
Bitrix\Rest\Marketplace\Transport\DICTIONARY_IMMUNE_LIST
const DICTIONARY_IMMUNE_LIST
Определения
transport.php:74
Bitrix\Rest\Marketplace\Transport\METHOD_SEARCH_APP
const METHOD_SEARCH_APP
Определения
transport.php:69
Bitrix\Rest\Marketplace\Transport\METHOD_GET_APP
const METHOD_GET_APP
Определения
transport.php:65
Bitrix\Rest\Marketplace\Transport\METHOD_GET_SITE_LIST
const METHOD_GET_SITE_LIST
Определения
transport.php:71
Bitrix\Rest\Marketplace\Transport\STREAM_TIMEOUT
const STREAM_TIMEOUT
Определения
transport.php:49
Bitrix\Rest\Marketplace\Transport\getDictionary
getDictionary(string $dictionary)
Определения
transport.php:141
Bitrix\Rest\Marketplace\Transport\METHOD_SET_INSTALL
const METHOD_SET_INSTALL
Определения
transport.php:68
Bitrix\Rest\Marketplace\Transport\prepareAnswer
prepareAnswer($response)
Определения
transport.php:213
Bitrix\Rest\Marketplace\Transport\METHOD_GET_BEST
const METHOD_GET_BEST
Определения
transport.php:53
Bitrix\Rest\Marketplace\Transport\METHOD_GET_SALE_OUT
const METHOD_GET_SALE_OUT
Определения
transport.php:54
Bitrix\Rest\Marketplace\Transport\METHOD_FILTER_APP
const METHOD_FILTER_APP
Определения
transport.php:70
Bitrix\Rest\Marketplace\Transport\METHOD_GET_CATEGORY
const METHOD_GET_CATEGORY
Определения
transport.php:63
Bitrix\Rest\Marketplace\Transport\SERVICE_TYPE_APP
const SERVICE_TYPE_APP
Определения
transport.php:41
Bitrix\Rest\Marketplace\Transport\METHOD_GET_APP_PUBLIC
const METHOD_GET_APP_PUBLIC
Определения
transport.php:66
Bitrix\Rest\Marketplace\Transport\METHOD_GET_UPDATES
const METHOD_GET_UPDATES
Определения
transport.php:56
Bitrix\Rest\Marketplace\Transport\SERVICE_TYPE_COUPON
const SERVICE_TYPE_COUPON
Определения
transport.php:42
Bitrix\Rest\Marketplace\Transport\SOCKET_TIMEOUT
const SOCKET_TIMEOUT
Определения
transport.php:48
Bitrix\Rest\Marketplace\Transport\METHOD_GET_SITE_ITEM
const METHOD_GET_SITE_ITEM
Определения
transport.php:72
Bitrix\Rest\Marketplace\Transport\SERVICE_URL
const SERVICE_URL
Определения
transport.php:21
Bitrix\Rest\Marketplace\Transport\METHOD_GET_TAG
const METHOD_GET_TAG
Определения
transport.php:64
Bitrix\Rest\Marketplace\Transport\call
call($method, $fields=array())
Определения
transport.php:127
Bitrix\Rest\Marketplace\Transport\batch
batch($actions)
Определения
transport.php:159
Bitrix\Rest\Marketplace\Transport\$serviceDomain
string $serviceDomain
Определения
transport.php:25
Bitrix\Rest\Marketplace\Transport\getServiceUrl
getServiceUrl(string $type=self::SERVICE_TYPE_APP)
Определения
transport.php:117
Bitrix\Rest\Marketplace\Transport\$instance
static $instance
Определения
transport.php:80
Bitrix\Rest\Marketplace\Transport\METHOD_GET_CATEGORIES
const METHOD_GET_CATEGORIES
Определения
transport.php:62
Bitrix\Rest\Marketplace\Transport\VERSION
const VERSION
Определения
transport.php:22
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$query
$query
Определения
get_search.php:11
$region
$region
Определения
.description.php:13
$_SERVER
$_SERVER["DOCUMENT_ROOT"]
Определения
cron_frame.php:9
$uri
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения
urlrewrite.php:61
false
return false
Определения
prolog_main_admin.php:185
$key
if(empty($signedUserToken)) $key
Определения
quickway.php:257
$response
$response
Определения
result.php:21
$method
$method
Определения
index.php:27
$fields
$fields
Определения
yandex_run.php:501
bitrix
modules
rest
lib
marketplace
transport.php
Создано системой
1.14.0