Esempio n. 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;
 }
Esempio n. 2
0
    $aMenu[] = array("parent_menu" => "global_menu_settings", "sort" => 1700, "text" => GetMessage("MAIN_MENU_SHORT_URLS"), "url" => "short_uri_admin.php?lang=" . LANGUAGE_ID, "more_url" => array("short_uri_edit.php"), "title" => GetMessage("MAIN_MENU_SHORT_URLS_ALT"), "icon" => "sys_menu_icon");
}
if ($USER->CanDoOperation('install_updates')) {
    $arMarket = array();
    if (method_exists($adminMenu, "IsSectionActive")) {
        if ($adminMenu->IsSectionActive("menu_marketplace")) {
            $CACHE = 60 * 60 * 24;
            $obCache = new CPHPCache();
            $cache_id = "main_menu_marketplace_" . LANGUAGE_ID;
            if ($obCache->InitCache($CACHE, $cache_id, "/")) {
                $vars = $obCache->GetVars();
                $arMarket = $vars["arMarket"];
            } else {
                $ht = new Bitrix\Main\Web\HttpClient(array("socketTimeout" => 30));
                if ($res = $ht->get("http://marketplace.1c-bitrix.ru/data_export.php")) {
                    if ($ht->getStatus() == "200") {
                        $res = $APPLICATION->ConvertCharset($res, "windows-1251", SITE_CHARSET);
                        require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/xml.php";
                        $objXML = new CDataXML();
                        $objXML->LoadString($res);
                        $arResult = $objXML->GetArray();
                        if (!empty($arResult) && is_array($arResult)) {
                            if (!empty($arResult["categories"]["#"]["category"])) {
                                foreach ($arResult["categories"]["#"]["category"] as $category) {
                                    $arCategory = array();
                                    $arUrls = array();
                                    if (!empty($category["#"]["items"][0]["#"]["item"])) {
                                        foreach ($category["#"]["items"][0]["#"]["item"] as $catIn) {
                                            $url = "update_system_market.php?category=" . $catIn["#"]["id"][0]["#"];
                                            $arCategory[] = array("text" => $catIn["#"]["name"][0]["#"] . " (" . $catIn["#"]["count"][0]["#"] . ")", "title" => GetMessage("MAIN_MENU_MP_CATEGORY") . " " . $catIn["#"]["name"][0]["#"], "url" => $url . "&lang=" . LANGUAGE_ID);
                                            $arUrls[] = $url;
Esempio n. 3
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;
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
 public function call($methodName, $additionalParams = null)
 {
     if (!is_array($additionalParams)) {
         $additionalParams = array();
     }
     $request = $this->prepareRequest($additionalParams);
     $http = new \Bitrix\Main\Web\HttpClient(array('socketTimeout' => $this->httpTimeout));
     $result = $http->post(CBitrix24NetOAuthInterface::NET_URL . self::SERVICE_URL . $methodName, $request);
     try {
         $res = $this->prepareResponse($result);
     } catch (\Bitrix\Main\ArgumentException $e) {
         $res = false;
     }
     if (!$res) {
         AddMessage2Log('Strange answer from Network! ' . $http->getStatus() . ' ' . $result);
     }
     return $res;
 }
Esempio n. 6
0
 public static function DownloadAgent($historyID, $recordUrl, $attachToCrm = true)
 {
     $historyID = intval($historyID);
     if (strlen($recordUrl) <= 0 || $historyID <= 0) {
         return false;
     }
     $http = new \Bitrix\Main\Web\HttpClient();
     $http->query('HEAD', $recordUrl);
     if ($http->getStatus() != 200) {
         CAgent::AddAgent("CVoxImplantHistory::DownloadAgent('{$historyID}','{$recordUrl}','{$attachToCrm}');", 'voximplant', 'N', 30, '', 'Y', ConvertTimeStamp(time() + CTimeZone::GetOffset() + 30, 'FULL'));
         return false;
     }
     $history = VI\StatisticTable::getById($historyID);
     $arHistory = $history->fetch();
     try {
         $recordFile = CFile::MakeFileArray($recordUrl);
         if (is_array($recordFile) && $recordFile['size'] && $recordFile['size'] > 0) {
             $recordFile = array_merge($recordFile, array('MODULE_ID' => 'voximplant'));
             $fileID = CFile::SaveFile($recordFile, 'voximplant');
             if (is_int($fileID) && $fileID > 0) {
                 $elementID = CVoxImplantDiskHelper::SaveFile($arHistory, CFile::GetFileArray($fileID), CSite::GetDefSite());
                 $elementID = intval($elementID);
                 if ($attachToCrm && $elementID > 0) {
                     CVoxImplantCrmHelper::AttachRecordToCall(array('CALL_ID' => $arHistory['CALL_ID'], 'CALL_RECORD_ID' => $fileID, 'CALL_WEBDAV_ID' => $elementID));
                 }
                 VI\StatisticTable::update($historyID, array('CALL_RECORD_ID' => $fileID, 'CALL_WEBDAV_ID' => $elementID));
             }
         }
     } catch (Exception $ex) {
     }
     return false;
 }
 /**
  * Send request to Bitrix (check o receive)
  * @param array $payload
  * @return array|bool
  */
 protected static function sendRequest(array $payload)
 {
     $targetHost = static::getServiceHost();
     // Trusted host *must* have a valid SSL certificate
     $skipSslValidation = !in_array($targetHost, static::$trustedHosts, true);
     $httpClient = new \Bitrix\Main\Web\HttpClient(array('disableSslVerification' => $skipSslValidation, 'streamTimeout' => static::TIMEOUT));
     $response = $httpClient->post(self::buildCheckerUrl($targetHost), $payload);
     if ($response && $httpClient->getStatus() == 200) {
         return self::decodeResponse($response);
     }
     return false;
 }
Esempio n. 8
0
 public function call($methodName, $additionalParams = null)
 {
     if (!is_array($additionalParams)) {
         $additionalParams = array();
     }
     $additionalParams['auth'] = $this->access_token;
     $http = new \Bitrix\Main\Web\HttpClient(array('socketTimeout' => $this->httpTimeout));
     $result = $http->post(CBitrix24NetOAuthInterface::NET_URL . self::SERVICE_URL . $methodName, $additionalParams);
     $res = $this->prepareAnswer($result);
     if (!$res) {
         AddMessage2Log('Strange answer from Network! ' . $http->getStatus() . ' ' . $result);
     }
     return $res;
 }
 /**
  * Send request to Bitrix (check o receive)
  * @param array $payload
  * @return array|bool
  */
 protected static function sendRequest(array $payload)
 {
     $httpClient = new \Bitrix\Main\Web\HttpClient();
     $httpClient->setRedirect(true);
     $httpClient->setStreamTimeout(static::TIMEOUT);
     $response = $httpClient->post(self::getCheckerUrl(), $payload);
     if ($response && $httpClient->getStatus() == 200) {
         return self::decodeResponse($response);
     }
     return false;
 }