1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
baseapiobject.php
См. документацию.
1<?
2
3namespace Bitrix\Sender\Integration\Yandex\Toloka;
4
5use Bitrix\Main\Web\HttpClient;
6use Bitrix\Sender\Integration\Yandex\Toloka\Exception\AccessDeniedException;
7use Bitrix\Seo\Analytics\Service;
8use Bitrix\Seo\Engine\YandexJson;
9use COption;
10
11if(!defined("BITRIX_CLOUD_ADV_URL"))
12{
13 $domain = 'bitrix.info';
14 if (
15 class_exists('\Bitrix\Main\License\UrlProvider')
16 && method_exists('\Bitrix\Main\License\UrlProvider',
17 'getTechDomain'
18 )
19 && \Bitrix\Sender\Integration\Bitrix24\Service::isRegionRussian(true)
20 )
21 {
22 $domain = (new \Bitrix\Main\License\UrlProvider())->getTechDomain();
23 }
24
25 $cloudAdvUrl = 'https://cloud-adv.' . $domain;
26
27 define("BITRIX_CLOUD_ADV_URL", $cloudAdvUrl);
28}
29
30if(!defined("SEO_BITRIX_API_URL"))
31{
32 define("SEO_BITRIX_API_URL", BITRIX_CLOUD_ADV_URL."/rest/");
33}
34
35abstract class BaseApiObject
36{
37 private const API_URL = SEO_BITRIX_API_URL;
38 protected $result;
39 protected $accessToken;
40 protected $clientId;
41 protected $clientSecret;
42
43 private function checkResult(): void
44 {
45 $errorCode = $this->result['error'] ?? $this->result['code']?? false;
46
47 if(!$errorCode)
48 {
49 return;
50 }
51
52 switch ($errorCode)
53 {
54 case 'verification_needed':
55 case 'ACCESS_DENIED':
56 COption::RemoveOption('sender', ApiRequest::ACCESS_CODE);
57 throw new AccessDeniedException();
58 break;
59 }
60 }
61
65 public function getAccessToken()
66 {
67 return $this->accessToken;
68 }
69
76 {
77 $this->accessToken = $accessToken;
78
79 return $this;
80 }
81
85 public function getClientId()
86 {
87 return $this->clientId;
88 }
89
95 public function setClientId($clientId)
96 {
97 $this->clientId = $clientId;
98
99 return $this;
100 }
101
105 public function getClientSecret()
106 {
107 return $this->clientSecret;
108 }
109
116 {
117 $this->clientSecret = $clientSecret;
118
119 return $this;
120 }
121
122 protected function sendRequest($data = [])
123 {
124 $scope = static::getScope().$data['methodName']??'';
125
126 $httpResult = $this
127 ->query($scope, $data['parameters']??[])
128 ->getResult();
129
130 $httpResult = $httpResult ?
131 YandexJson::decode($httpResult) : [];
132
133 $this->result = isset($httpResult['result']) ?
134 YandexJson::decode($httpResult['result']) :
135 $httpResult
136 ;
137
138 $this->checkResult();
139 }
140 protected function registerOnCloudAdv()
141 {
142 $authAdapter = Service::getInstance()->getAuthAdapter(Service::TYPE_YANDEX);
143
144 $http = new HttpClient();
145 $http->setRedirect(false);
146 $http->get($authAdapter->getAuthUrl());
147 }
148
149 protected function query($scope, $param = NULL)
150 {
151 if ($param === NULL)
152 {
153 $param = array();
154 }
155
156 $http = new HttpClient();
157 $http->setRedirect(false);
158
160 "access_code" => $this->accessToken,
161 "client_id" => $this->clientId,
162 "client_secret" => $this->clientSecret,
163 "data" => json_encode($param, JSON_UNESCAPED_UNICODE)
164 );
165
166 if (!empty($param))
167 {
168 $postData = array_merge($postData, $param);
169 }
170
171 $http->post(self::API_URL.$scope, $postData, false);
172
173 return $http;
174 }
175
176 abstract function getScope():string;
177}
static getInstance()
Определения application.php:98
static decode($data)
Определения json.php:50
$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
$postData
Определения index.php:29