1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
basesender.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Service\MicroService;
4
5use Bitrix\Main\ArgumentException;
6use Bitrix\Main\Error;
7use Bitrix\Main\Result;
8use Bitrix\Main\Web\HttpClient;
9use Bitrix\Main\Web\Json;
10
14abstract class BaseSender
15{
16 public function __construct()
17 {
18 }
19
25 public function performRequest($action, array $parameters = []): Result
26 {
27 $httpClient = $this->buildHttpClient();
28
29 $url = $this->getServiceUrl() . "/api/?action=".$action;
30
31 $request = [
32 "action" => $action,
33 "serializedParameters" => base64_encode(gzencode(Json::encode($parameters))),
34 ];
35
36 $request["BX_TYPE"] = Client::getPortalType();
37 $request["BX_LICENCE"] = Client::getLicenseCode();
38 $request["SERVER_NAME"] = $this->getClientServerName();
40
41 $result = $httpClient->query(HttpClient::HTTP_POST, $url, $request);
42
43 return $this->buildResult($httpClient, $result);
44 }
45
46 protected function buildHttpClient(): HttpClient
47 {
48 return new HttpClient($this->getHttpClientParameters());
49 }
50
51 protected function buildResult(HttpClient $httpClient, bool $requestResult): Result
52 {
53 return $this->createAnswerForJsonResponse(
54 $requestResult,
55 $httpClient->getResult(),
56 $httpClient->getError(),
57 $httpClient->getStatus()
58 );
59 }
60
61 protected function createAnswerForJsonResponse($queryResult, $response, $errors, $status): Result
62 {
63 $result = new Result();
64
65 if (!$queryResult)
66 {
67 foreach ($errors as $code => $message)
68 {
69 $result->addError(new Error($message, $code));
70 }
71
72 return $result;
73 }
74
75 if ($status != 200)
76 {
77 $result->addError(new Error("Server returned " . $status . " code", "WRONG_SERVER_RESPONSE"));
78 return $result;
79 }
80
81 if ($response == "")
82 {
83 $result->addError(new Error("Empty server response", "EMPTY_SERVER_RESPONSE"));
84 return $result;
85 }
86
87 try
88 {
89 $parsedResponse = Json::decode($response);
90 }
91 catch (\Exception $e)
92 {
93 $result->addError(new Error("Could not parse server response. Raw response: " . $response));
94 return $result;
95 }
96
97 if ($parsedResponse["status"] === "error")
98 {
99 foreach ($parsedResponse["errors"] as $error)
100 {
101 $result->addError(new Error($error["message"], $error["code"], $error["customData"]));
102 }
103 }
104 elseif (is_array($parsedResponse["data"]))
105 {
106 $result->setData($parsedResponse["data"]);
107 }
108
109 return $result;
110 }
111
116 {
117 return [
118 "socketTimeout" => 10,
119 "streamTimeout" => 30,
120 "disableSslVerification" => true
121 ];
122 }
123
127 protected function getClientServerName(): string
128 {
129 return Client::getServerName();
130 }
131
132 abstract protected function getServiceUrl(): string;
133}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
Определения error.php:15
createAnswerForJsonResponse($queryResult, $response, $errors, $status)
Определения basesender.php:61
buildResult(HttpClient $httpClient, bool $requestResult)
Определения basesender.php:51
performRequest($action, array $parameters=[])
Определения basesender.php:25
static getPortalType()
Определения client.php:21
static signRequest(array $parameters, string $suffix="")
Определения client.php:81
static getLicenseCode()
Определения client.php:35
static getServerName()
Определения client.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$errors
Определения iblock_catalog_edit.php:74
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$status
Определения session.php:10
$message
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$response
Определения result.php:21
$error
Определения subscription_card_product.php:20
$action
Определения file_dialog.php:21
$url
Определения iframe.php:7