1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
request.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale\Delivery\Pecom;
4
5class Request
6{
11 const API_BASE_URL = 'https://kabinet.pecom.ru/api/v1/';
12
17 protected $apiLogin = '';
18
23 protected $apiKey = '';
24
29 protected $apiUrl = '';
30
31 public function __construct($apiLogin, $apiKey, $apiUrl = '')
32 {
33 $this->apiLogin = $apiLogin;
34 $this->apiKey = $apiKey;
35 $this->apiUrl = ($apiUrl === '') ? self::API_BASE_URL : $apiUrl;
36 }
37
47 public function send($controller, $action, $data, $assoc = true)
48 {
49 global $APPLICATION;
50 $http = new \Bitrix\Main\Web\HttpClient(array(
51 "version" => "1.1",
52 "socketTimeout" => 30,
53 "streamTimeout" => 30,
54 "redirect" => true,
55 "redirectMax" => 5,
56 "disableSslVerification" => true
57 ));
58
59 $http->setHeader("Content-Type", "application/json; charset=utf-8");
60 $http->setHeader("Authorization", "Basic ".base64_encode($this->apiLogin.":".$this->apiKey));
61
62 $jsonData = json_encode($data);
63 $result = $http->post($this->constructApiUrl($controller, $action), $jsonData);
64 $errors = $http->getError();
65
66 if (!$result && !empty($errors))
67 {
68 $strError = "";
69
70 foreach($errors as $errorCode => $errMes)
71 $strError .= $errorCode.": ".$errMes;
72
73 throw new \Exception($strError);
74 }
75 else
76 {
77 $status = $http->getStatus();
78
79 if ($status != 200)
80 {
81 throw new \Exception(sprintf('HTTP error code: %d', $status));
82 }
83
84 $resData = $http->getResult();
85
86 $decodedResult = json_decode($resData, $assoc);
87 }
88
89 return $decodedResult;
90 }
91
98 protected function constructApiUrl($controller, $action)
99 {
100 return sprintf('%s%s/%s/', $this->apiUrl, $controller, $action);
101 }
102}
global $APPLICATION
Определения include.php:80
send($controller, $action, $data, $assoc=true)
Определения request.php:47
__construct($apiLogin, $apiKey, $apiUrl='')
Определения request.php:31
const API_BASE_URL
Определения request.php:11
constructApiUrl($controller, $action)
Определения request.php:98
$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
$result
Определения get_property_values.php:14
$errors
Определения iblock_catalog_edit.php:74
$strError
Определения options_user_settings.php:4
$status
Определения session.php:10
$action
Определения file_dialog.php:21