Пример #1
0
 /**
  * Calls API
  * @param string $controller Group name
  * @param string $action Method name
  * @param mixed $data Input data
  * @param bool $assoc Result format. true - array, false - object
  * @return mixed Result
  * @throws \Exception Case error during requesting
  */
 public function send($controller, $action, $data, $assoc = true)
 {
     global $APPLICATION;
     $http = new \Bitrix\Main\Web\HttpClient(array("version" => "1.1", "socketTimeout" => 30, "streamTimeout" => 30, "redirect" => true, "redirectMax" => 5));
     $http->setHeader("Content-Type", "application/json; charset=utf-8");
     $http->setHeader("Authorization", "Basic " . base64_encode($this->apiLogin . ":" . $this->apiKey));
     if (strtolower(SITE_CHARSET) != 'utf-8') {
         $data = $APPLICATION->ConvertCharsetArray($data, SITE_CHARSET, 'utf-8');
     }
     $jsonData = json_encode($data);
     $result = $http->post($this->constructApiUrl($controller, $action), $jsonData);
     $errors = $http->getError();
     if (!$result && !empty($errors)) {
         $strError = "";
         foreach ($errors as $errorCode => $errMes) {
             $strError .= $errorCode . ": " . $errMes;
         }
         throw new \Exception($strError);
     } else {
         $status = $http->getStatus();
         if ($status != 200) {
             throw new \Exception(sprintf('HTTP error code: %d', $status));
         }
         $resData = $http->getResult();
         $decodedResult = json_decode($resData, $assoc);
         if (strtolower(SITE_CHARSET) != 'utf-8') {
             $decodedResult = $APPLICATION->ConvertCharsetArray($decodedResult, 'utf-8', SITE_CHARSET);
         }
     }
     return $decodedResult;
 }
Пример #2
0
 function Request($server, $page, $port, $params, $uri = false)
 {
     if ($uri && strlen($uri) > 0) {
         $strURI = $uri;
     } else {
         $strURI = "http://" . $server . (strlen($port) > 0 && intval($port) > 0 ? ":" . intval($port) : "") . (strlen($page) ? $page : "/") . (strlen($params) > 0 ? "?" . $params : "");
     }
     $http = new \Bitrix\Main\Web\HttpClient(array("version" => "1.0", "socketTimeout" => 30, "streamTimeout" => 30, "redirect" => true, "redirectMax" => 5));
     $strData = $http->get($strURI);
     $errors = $http->getError();
     $arRSSResult = array();
     if (!$strData && !empty($errors)) {
         $strError = "";
         foreach ($errors as $errorCode => $errMes) {
             $strError .= $errorCode . ": " . $errMes;
         }
         \CEventLog::Add(array("SEVERITY" => "ERROR", "AUDIT_TYPE_ID" => "XDIMPORT_HTTP", "MODULE_ID" => "xdimport", "ITEM_ID" => "RSS_REQUEST", "DESCRIPTION" => $strError));
     }
     if ($strData) {
         $rss_charset = "windows-1251";
         if (preg_match("/<" . "\\?XML[^>]{1,}encoding=[\"']([^>\"']{1,})[\"'][^>]{0,}\\?" . ">/i", $strData, $matches)) {
             $rss_charset = Trim($matches[1]);
         }
         $strData = preg_replace("/<" . "\\?XML.*?\\?" . ">/i", "", $strData);
         $strData = $GLOBALS["APPLICATION"]->ConvertCharset($strData, $rss_charset, SITE_CHARSET);
     }
     if (strlen($strData) > 0) {
         require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/xml.php";
         $objXML = new CDataXML();
         $res = $objXML->LoadString($strData);
         if ($res !== false) {
             $ar = $objXML->GetArray();
             if (is_array($ar) && isset($ar["rss"]) && is_array($ar["rss"]) && isset($ar["rss"]["#"]) && is_array($ar["rss"]["#"]) && isset($ar["rss"]["#"]["channel"]) && is_array($ar["rss"]["#"]["channel"]) && isset($ar["rss"]["#"]["channel"][0]) && is_array($ar["rss"]["#"]["channel"][0]) && isset($ar["rss"]["#"]["channel"][0]["#"])) {
                 $arRSSResult = $ar["rss"]["#"]["channel"][0]["#"];
             } else {
                 $arRSSResult = array();
             }
             $arRSSResult["rss_charset"] = strtolower(SITE_CHARSET);
         }
     }
     if (is_array($arRSSResult) && !empty($arRSSResult)) {
         $arRSSResult = CXDILFSchemeRSS::FormatArray($arRSSResult);
         if (!empty($arRSSResult) && array_key_exists("item", $arRSSResult) && is_array($arRSSResult["item"]) && !empty($arRSSResult["item"])) {
             $arRSSResult["item"] = array_reverse($arRSSResult["item"]);
         }
     }
     return $arRSSResult;
 }
Пример #3
0
 public static function getAllPecomCities($cleanCache = false)
 {
     global $APPLICATION;
     $ttl = 2592000;
     $data = array();
     $cacheId = "SaleDeliveryPecomCities";
     $cacheManager = \Bitrix\Main\Application::getInstance()->getManagedCache();
     if ($cleanCache) {
         $cacheManager->clean($cacheId);
     }
     if ($cacheManager->read($ttl, $cacheId)) {
         $data = $cacheManager->get($cacheId);
     }
     if (empty($data)) {
         $http = new \Bitrix\Main\Web\HttpClient(array("version" => "1.1", "socketTimeout" => 30, "streamTimeout" => 30, "redirect" => true, "redirectMax" => 5));
         $jsnData = $http->get("http://www.pecom.ru/ru/calc/towns.php");
         $errors = $http->getError();
         if (!$jsnData && !empty($errors)) {
             $strError = "";
             foreach ($errors as $errorCode => $errMes) {
                 $strError .= $errorCode . ": " . $errMes;
             }
             \CEventLog::Add(array("SEVERITY" => "ERROR", "AUDIT_TYPE_ID" => "SALE_DELIVERY", "MODULE_ID" => "sale", "ITEM_ID" => "PECOM_GET_TOWNS", "DESCRIPTION" => $strError));
         }
         $data = json_decode($jsnData, true);
         if (strtolower(SITE_CHARSET) != 'utf-8') {
             $data = $APPLICATION->ConvertCharsetArray($data, 'utf-8', SITE_CHARSET);
             if (is_array($data)) {
                 foreach ($data as $key => $value) {
                     $newKey = $APPLICATION->ConvertCharset($key, 'utf-8', SITE_CHARSET);
                     $data[$newKey] = $value;
                     unset($data[$key]);
                 }
             }
         }
         if (!is_array($data)) {
             $data = array();
         }
         $cacheManager->set($cacheId, $data);
     }
     return $data;
 }
Пример #4
0
 protected static function send($strParams)
 {
     $http = new \Bitrix\Main\Web\HttpClient(array("version" => "1.1", "socketTimeout" => 30, "streamTimeout" => 30, "redirect" => true, "redirectMax" => 5));
     $jsnData = $http->post("http://www.pecom.ru/bitrix/components/pecom/calc/ajax.php", $strParams);
     $errors = $http->getError();
     if (!$jsnData && !empty($errors)) {
         $strError = "";
         foreach ($errors as $errorCode => $errMes) {
             $strError .= $errorCode . ": " . $errMes;
         }
         \CEventLog::Add(array("SEVERITY" => "ERROR", "AUDIT_TYPE_ID" => "SALE_DELIVERY", "MODULE_ID" => "sale", "ITEM_ID" => "PECOM_CALCULATOR_SEND", "DESCRIPTION" => $strError));
     }
     return $jsnData;
 }
Пример #5
0
	public static function GetVideoOembed($url = '')
	{
		// Get oembed url
		$oembed = self::GetOembedUrlInfo($url);
		$output = array('result' => false, 'error' => "");
		$http = new \Bitrix\Main\Web\HttpClient();
		$resp = $http->get($oembed['url']);
		if ($resp === false)
		{
			$error = $http->getError();
			foreach($error as $errorCode => $errorMessage)
			{
				$output['error'] .=  '['.$errorCode.'] '.$errorMessage.";\n";
			}
		}
		else
		{
			$resParams = json_decode($resp, true);
			if ($resParams && is_array($resParams))
			{
				if (!defined('BX_UTF') || BX_UTF !== true)
				{
					$resParams['title'] = CharsetConverter::ConvertCharset($resParams['title'], 'UTF-8', SITE_CHARSET);
					$resParams['html'] = CharsetConverter::ConvertCharset($resParams['html'], 'UTF-8', SITE_CHARSET);
					$resParams['provider_name'] = CharsetConverter::ConvertCharset($resParams['provider_name'], 'UTF-8', SITE_CHARSET);

				}

				$resParams['html'] = preg_replace("/https?:\/\//is", '//', $resParams['html']);
				$output['result'] = true;
				$output['data'] = array(
					'html' => $resParams['html'],
					'title' => $resParams['title'],
					'width' => intval($resParams['width']),
					'height' => intval($resParams['height']),
					'provider' => $resParams['provider_name']
				);
			}
			else
			{
				$output['error'] .=  '[FVID404] '.GetMessage('HTMLED_VIDEO_NOT_FOUND').";\n";
			}
		}

		return $output;
	}
Пример #6
0
 public function sendStatus($orderId, $status, $substatus = false)
 {
     global $APPLICATION;
     if (strlen($this->yandexApiUrl) <= 0 || strlen($this->campaignId) <= 0 || intval($orderId) <= 0 || strlen($status) <= 0 || strlen($this->oAuthToken) <= 0 || strlen($this->oAuthClientId) <= 0 || strlen($this->oAuthLogin) <= 0) {
         return false;
     }
     $format = $this->communicationFormat == self::JSON ? 'json' : 'xml';
     $url = $this->yandexApiUrl . "campaigns/" . $this->campaignId . "/orders/" . $orderId . "/status." . $format;
     $http = new \Bitrix\Main\Web\HttpClient(array("version" => "1.1", "socketTimeout" => 30, "streamTimeout" => 30, "redirect" => true, "redirectMax" => 5));
     $arQuery = array("order" => array("status" => $status));
     if ($substatus) {
         $arQuery["order"]["substatus"] = $substatus;
     }
     if (strtolower(SITE_CHARSET) != 'utf-8') {
         $arQuery = $APPLICATION->ConvertCharsetArray($arQuery, SITE_CHARSET, 'utf-8');
     }
     $postData = '';
     if ($this->communicationFormat == self::JSON) {
         $postData = json_encode($arQuery);
     }
     $http->setHeader("Content-Type", "application/" . $format);
     $http->setHeader("Authorization", 'OAuth oauth_token="' . $this->oAuthToken . '", oauth_client_id="' . $this->oAuthClientId . '", oauth_login="******"', false);
     $result = $http->query("PUT", $url, $postData);
     $errors = $http->getError();
     if (!$result && !empty($errors)) {
         $bResult = false;
         $message = "HTTP ERROR: ";
         foreach ($errors as $errorCode => $errMes) {
             $message .= $errorCode . ": " . $errMes;
         }
     } else {
         $headerStatus = $http->getStatus();
         if ($headerStatus == 200) {
             $message = GetMessage("SALE_YMH_STATUS") . ": " . $status;
             $bResult = true;
         } else {
             $res = $http->getResult();
             $message = "HTTP error code: " . $headerStatus . "(" . $res . ")";
             if ($headerStatus == 403) {
                 $this->notifyAdmin("SEND_STATUS_ERROR_403");
             }
             if ($headerStatus == 500) {
                 $intervalSeconds = 3600;
                 $timeToStart = ConvertTimeStamp(strtotime(date('Y-m-d H:i:s', time() + $intervalSeconds)), 'FULL');
                 \CAgent::AddAgent('\\CSaleYMHandler::sendStatusAgent("' . $orderId . '","' . $status . '", "' . $substatus . '", "' . $this->siteId . '");', 'sale', "N", $intervalSeconds, $timeToStart, "Y", $timeToStart);
             }
             $bResult = false;
         }
     }
     $this->log($bResult ? self::LOG_LEVEL_INFO : self::LOG_LEVEL_ERROR, "YMARKET_STATUS_CHANGE", $orderId, $message);
     return $bResult;
 }
Пример #7
0
 public static function GetVideoOembed($url = '')
 {
     // Get oembed url
     $oembed = self::GetOembedUrlInfo($url);
     $output = array('result' => false, 'error' => "");
     $http = new \Bitrix\Main\Web\HttpClient();
     $resp = $http->get($oembed['url']);
     if ($resp === false) {
         $io = CBXVirtualIo::GetInstance();
         $path = $url;
         $serverPath = self::GetServerPath();
         if (strpos($path, $serverPath) !== false) {
             $path = str_replace($serverPath, '', $path);
         }
         if ($io->FileExists($io->RelativeToAbsolutePath($path))) {
             $output['data'] = array('local' => true, 'path' => $path);
             $output['result'] = true;
         } else {
             $path = $url;
             $http = new \Bitrix\Main\Web\HttpClient();
             $resp1 = $http->get($path);
             if ($resp1 !== false) {
                 $output['data'] = array('local' => true, 'path' => $url);
             }
             $output['result'] = true;
         }
         if (!$output['result']) {
             $error = $http->getError();
             foreach ($error as $errorCode => $errorMessage) {
                 $output['error'] .= '[' . $errorCode . '] ' . $errorMessage . ";\n";
             }
         }
     } else {
         $resParams = json_decode($resp, true);
         if ($resParams && is_array($resParams)) {
             if (!defined('BX_UTF') || BX_UTF !== true) {
                 $resParams['title'] = CharsetConverter::ConvertCharset($resParams['title'], 'UTF-8', SITE_CHARSET);
                 $resParams['html'] = CharsetConverter::ConvertCharset($resParams['html'], 'UTF-8', SITE_CHARSET);
                 $resParams['provider_name'] = CharsetConverter::ConvertCharset($resParams['provider_name'], 'UTF-8', SITE_CHARSET);
             }
             $resParams['html'] = preg_replace("/https?:\\/\\//is", '//', $resParams['html']);
             $output['result'] = true;
             $output['data'] = array('html' => $resParams['html'], 'title' => $resParams['title'], 'width' => intval($resParams['width']), 'height' => intval($resParams['height']), 'provider' => $resParams['provider_name']);
         } else {
             $output['error'] .= '[FVID404] ' . GetMessage('HTMLED_VIDEO_NOT_FOUND') . ";\n";
         }
     }
     return $output;
 }
Пример #8
0
 /**
  * @param $data
  * @return \Bitrix\Main\Entity\Result
  */
 protected static function sendRequestData($data, $method)
 {
     $result = new \Bitrix\Main\Entity\Result();
     $url = "http://" . DELIVERY_RUSSIANPOST_SERVER . DELIVERY_RUSSIANPOST_SERVER_PAGE;
     $reqResult = false;
     $httpClient = new \Bitrix\Main\Web\HttpClient(array("version" => "1.1", "socketTimeout" => 30, "streamTimeout" => 30, "redirect" => true, "redirectMax" => 5));
     $method = DELIVERY_RUSSIANPOST_SERVER_METHOD == $method ? \Bitrix\Main\Web\HttpClient::HTTP_GET : \Bitrix\Main\Web\HttpClient::HTTP_POST;
     if ($httpClient->query($method, $url, $data)) {
         $reqResult = $httpClient->getResult();
     }
     $errors = $httpClient->getError();
     if (!$reqResult && !empty($errors)) {
         foreach ($errors as $errorCode => $errMes) {
             $result->addError(new \Bitrix\Main\Entity\EntityError($errorCode . ": " . $errMes));
         }
     } else {
         $status = $httpClient->getStatus();
         if ($status != 200) {
             $result->addError(new \Bitrix\Main\Entity\EntityError('HTTP error code: %d', $status));
         } else {
             $result->setData(array("DATA" => $reqResult));
         }
     }
     return $result;
 }