Exemple #1
0
 /**
  * @param string $hash
  * @param string $act
  * @return string
  */
 public function getUrl($hash, $act = "view")
 {
     return \CHTTP::URN2URI($this->script . (strpos($this->script, "?") === false ? "?" : "&") . \CHTTP::PrepareData(array(self::INFO_NAME => array("CID" => $this->CID, "mode" => $act, "hash" => $hash))));
 }
Exemple #2
0
 public function batch($actions)
 {
     $arBatch = array();
     if (is_array($actions)) {
         foreach ($actions as $query_key => $arCmd) {
             list($cmd, $arParams) = array_values($arCmd);
             $arBatch['cmd'][$query_key] = $cmd . '?' . CHTTP::PrepareData($arParams);
         }
     }
     $arBatch['auth'] = $this->access_token;
     $batch_url = '/rest/batch';
     $httpClient = new \Bitrix\Main\Web\HttpClient();
     $result = $httpClient->post($this->portalURI . $batch_url, $arBatch);
     return $this->prepareAnswer($result);
 }
Exemple #3
0
 private function Query($command, $params = array())
 {
     if (strlen($command) <= 0 || !is_array($params)) {
         return false;
     }
     $params['BX_COMMAND'] = $command;
     $params['BX_LICENCE'] = $this->licenceCode;
     $params['BX_DOMAIN'] = $this->domain;
     $params['BX_TYPE'] = $this->type;
     $params['BX_VERSION'] = $this->version;
     $params["BX_HASH"] = $this->RequestSign($this->type, md5(implode("|", $params)));
     $CHTTP = new CHTTP();
     $arUrl = $CHTTP->ParseURL($this->controllerUrl);
     if ($CHTTP->Query('POST', $arUrl['host'], $arUrl['port'], $arUrl['path_query'], CHTTP::PrepareData($params), $arUrl['proto'])) {
         $result = json_decode($CHTTP->result);
         if (!$result) {
             CVoxImplantHistory::WriteToLog($CHTTP->result, 'ERROR QUERY EXECUTE');
         }
     } else {
         $result = json_decode(json_encode(array('error' => array('code' => 'CONNECT_ERROR', 'msg' => 'Parse error or connect error from server'))));
     }
     return $result;
 }
Exemple #4
0
 public function sendBatch($batch)
 {
     require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/update_client.php";
     $key = CUpdateClient::GetLicenseKey();
     if (strlen($key) > 0 && strlen($batch) > 0) {
         $request = new CHTTP();
         $arPostData = array("Action" => "SendMessage", "MessageBody" => $batch);
         $postdata = CHTTP::PrepareData($arPostData);
         $arUrl = $request->ParseURL(self::$remoteProviderUrl . "?key=" . md5($key), false);
         $request->Query('POST', $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $postdata, $arUrl['proto'], 'N', true);
         return true;
     }
     return false;
 }
	private static function SendCommand($channelId, $message, $method = 'POST', $timeout = 5, $dont_wait_answer = true)
	{
		if (!is_array($channelId))
			$channelId = Array($channelId);

		$channelId = implode('/', array_unique($channelId));

		if (strlen($channelId) <=0 || strlen($message) <= 0)
			return false;

		if (!in_array($method, Array('POST', 'GET')))
			return false;

		$nginx_error = COption::GetOptionString("pull", "nginx_error", "N");
		if ($nginx_error != "N")
		{
			$nginx_error = unserialize($nginx_error);
			if (intval($nginx_error['date'])+120 < time())
			{
				COption::SetOptionString("pull", "nginx_error", "N");
				CAdminNotify::DeleteByTag("PULL_ERROR_SEND");
				$nginx_error = "N";
			}
			else if ($nginx_error['count'] >= 10)
			{
				$ar = Array(
					"MESSAGE" => GetMessage('PULL_ERROR_SEND'),
					"TAG" => "PULL_ERROR_SEND",
					"MODULE_ID" => "pull",
				);
				CAdminNotify::Add($ar);
				return false;
			}
		}

		$postdata = CHTTP::PrepareData($message);

		$CHTTP = new CHTTP();
		$CHTTP->http_timeout = intval($timeout);
		$arUrl = $CHTTP->ParseURL(CPullOptions::GetPublishUrl($channelId), false);
		if ($CHTTP->Query($method, $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $postdata, $arUrl['proto'], 'N', $dont_wait_answer))
		{
			$result = $dont_wait_answer? '{}': $CHTTP->result;
		}
		else
		{
			if ($nginx_error == "N")
			{
				$nginx_error = Array(
					'count' => 1,
					'date' => time(),
					'date_increment' => time(),
				);
			}
			else if (intval($nginx_error['date_increment'])+1 < time())
			{
				$nginx_error['count'] = intval($nginx_error['count'])+1;
				$nginx_error['date_increment'] = time();
			}
			COption::SetOptionString("pull", "nginx_error", serialize($nginx_error));
			$result = false;
		}

		return $result;
	}
Exemple #6
0
 function PrepareData($arPostData, $prefix = '')
 {
     $str = '';
     if (!is_array($arPostData)) {
         $str = $arPostData;
     } else {
         foreach ($arPostData as $key => $value) {
             $name = $prefix == "" ? urlencode($key) : $prefix . "[" . urlencode($key) . "]";
             if (is_array($value)) {
                 $str .= CHTTP::PrepareData($value, $name);
             } else {
                 $str .= '&' . $name . '=' . urlencode($value);
             }
         }
     }
     if ($prefix == '' && substr($str, 0, 1) == '&') {
         $str = substr($str, 1);
     }
     return $str;
 }
Exemple #7
0
 private static function SendCommand($channelId, $message, $options = array())
 {
     if (!is_array($channelId)) {
         $channelId = array($channelId);
     }
     $channelId = implode('/', array_unique($channelId));
     if (strlen($channelId) <= 0 || strlen($message) <= 0) {
         return false;
     }
     $defaultOptions = array("method" => "POST", "timeout" => 5, "dont_wait_answer" => true);
     $options = array_merge($defaultOptions, $options);
     if (!in_array($options["method"], array('POST', 'GET'))) {
         return false;
     }
     $nginx_error = COption::GetOptionString("pull", "nginx_error", "N");
     if ($nginx_error != "N") {
         $nginx_error = unserialize($nginx_error);
         if (intval($nginx_error['date']) + 120 < time()) {
             COption::SetOptionString("pull", "nginx_error", "N");
             CAdminNotify::DeleteByTag("PULL_ERROR_SEND");
             $nginx_error = "N";
         } else {
             if ($nginx_error['count'] >= 10) {
                 $ar = array("MESSAGE" => GetMessage('PULL_ERROR_SEND'), "TAG" => "PULL_ERROR_SEND", "MODULE_ID" => "pull");
                 CAdminNotify::Add($ar);
                 return false;
             }
         }
     }
     $postdata = CHTTP::PrepareData($message);
     $CHTTP = new CHTTP();
     $CHTTP->http_timeout = intval($options["timeout"]);
     if (isset($options["expiry"])) {
         $CHTTP->SetAdditionalHeaders(array("Message-Expiry" => intval($options["expiry"])));
     }
     $arUrl = $CHTTP->ParseURL(CPullOptions::GetPublishUrl($channelId), false);
     try {
         $sendResult = $CHTTP->Query($options["method"], $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $postdata, $arUrl['proto'], 'N', $options["dont_wait_answer"]);
     } catch (Exception $e) {
         $sendResult = false;
     }
     if ($sendResult) {
         $result = $options["dont_wait_answer"] ? '{}' : $CHTTP->result;
     } else {
         if ($nginx_error == "N") {
             $nginx_error = array('count' => 1, 'date' => time(), 'date_increment' => time());
         } else {
             if (intval($nginx_error['date_increment']) + 1 < time()) {
                 $nginx_error['count'] = intval($nginx_error['count']) + 1;
                 $nginx_error['date_increment'] = time();
             }
         }
         COption::SetOptionString("pull", "nginx_error", serialize($nginx_error));
         $result = false;
     }
     return $result;
 }