result['error'] ?? $this->result['code']?? false; if(!$errorCode) { return; } switch ($errorCode) { case 'verification_needed': case 'ACCESS_DENIED': COption::RemoveOption('sender', ApiRequest::ACCESS_CODE); throw new AccessDeniedException(); break; } } /** * @return mixed */ public function getAccessToken() { return $this->accessToken; } /** * @param mixed $accessToken * * @return BaseApiObject */ public function setAccessToken($accessToken) { $this->accessToken = $accessToken; return $this; } /** * @return mixed */ public function getClientId() { return $this->clientId; } /** * @param mixed $clientId * * @return BaseApiObject */ public function setClientId($clientId) { $this->clientId = $clientId; return $this; } /** * @return mixed */ public function getClientSecret() { return $this->clientSecret; } /** * @param mixed $clientSecret * * @return BaseApiObject */ public function setClientSecret($clientSecret) { $this->clientSecret = $clientSecret; return $this; } protected function sendRequest($data = []) { $scope = static::getScope().$data['methodName']??''; $httpResult = $this ->query($scope, $data['parameters']??[]) ->getResult(); $httpResult = $httpResult ? YandexJson::decode($httpResult) : []; $this->result = isset($httpResult['result']) ? YandexJson::decode($httpResult['result']) : $httpResult ; $this->checkResult(); } protected function registerOnCloudAdv() { $authAdapter = Service::getInstance()->getAuthAdapter(Service::TYPE_YANDEX); $http = new HttpClient(); $http->setRedirect(false); $http->get($authAdapter->getAuthUrl()); } protected function query($scope, $param = NULL) { if ($param === NULL) { $param = array(); } $http = new HttpClient(); $http->setRedirect(false); $postData = array( "access_code" => $this->accessToken, "client_id" => $this->clientId, "client_secret" => $this->clientSecret, "data" => json_encode($param, JSON_UNESCAPED_UNICODE) ); if (!empty($param)) { $postData = array_merge($postData, $param); } $http->post(self::API_URL.$scope, $postData, false); return $http; } abstract function getScope():string; }