Пример #1
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;
 }
Пример #2
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;
 }
Пример #3
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;
 }