private function QueryOrderData($arFilter, $arOptions = null) { if (!is_array($arOptions)) { $arOptions = array(); } $requestMethod = isset($arOptions["REQUEST_METHOD"]) && is_string($arOptions["REQUEST_METHOD"]) ? strtoupper($arOptions["REQUEST_METHOD"]) : ""; if ($requestMethod === "") { $requestMethod = "GET"; } $siteUrl = !empty($_SERVER["HTTP_HOST"]) ? ($GLOBALS["APPLICATION"]->IsHTTPS() ? "https" : "http") . "://" . $_SERVER["HTTP_HOST"] : ""; if ($requestMethod === "GET") { if ($siteUrl !== "") { $arFilter["CRM_SITE_URL"] = $siteUrl; } $request = array("METHOD" => "GET", "PATH" => CHTTP::urlAddParams($this->path, $arFilter), "HEADERS" => array()); } else { $request = array("METHOD" => "POST", "PATH" => $this->path, "HEADERS" => array(), "BODY" => array()); foreach ($arFilter as $key => $val) { $request["BODY"][$key] = $val; } if ($siteUrl !== "") { $request["BODY"]["CRM_SITE_URL"] = $siteUrl; } } $response = $this->proxy->Send($request); if (is_array($response) && isset($response["BODY"])) { return $response["BODY"]; } $errors = array(); foreach ($this->proxy->GetErrors() as $error) { $errors[] = sprintf("[%s] %s", $error[0], $error[1]); } $status = implode(" ", $errors); $this->AddError("GD1", $status); CCrmExternalSale::Update($this->externalSaleId, array("LAST_STATUS" => $status)); return null; }
$arFields = array("IMPORT_PERIOD" => $importPeriod, "IMPORT_PROBABILITY" => $_REQUEST["IMPORT_PROBABILITY"], "IMPORT_RESPONSIBLE" => $_REQUEST["IMPORT_RESPONSIBLE"], "IMPORT_PUBLIC" => $_REQUEST["IMPORT_PUBLIC"]); if (empty($errorMessage)) { $res = CCrmExternalSale::Update($id, $arFields); if (!$res) { if ($ex = $GLOBALS["APPLICATION"]->GetException()) { $errorMessage .= $ex->GetString() . ".<br>"; } else { $errorMessage .= "Unknown error." . "<br>"; } } } } if ($currentStep == 6 && $processActions && empty($errorMessage)) { $arFields = array("IMPORT_PROBABILITY" => $_REQUEST["IMPORT_PROBABILITY"], "IMPORT_RESPONSIBLE" => $_REQUEST["IMPORT_RESPONSIBLE"], "IMPORT_PUBLIC" => $_REQUEST["IMPORT_PUBLIC"], "IMPORT_GROUP_ID" => $_REQUEST["IMPORT_GROUP_ID"]); if (empty($errorMessage)) { $res = CCrmExternalSale::Update($id, $arFields); if (!$res) { if ($ex = $GLOBALS["APPLICATION"]->GetException()) { $errorMessage .= $ex->GetString() . ".<br>"; } else { $errorMessage .= "Unknown error." . "<br>"; } } } if (empty($errorMessage)) { $dataSyncPeriod = intval($_REQUEST["DATA_SYNC_PERIOD"]); $dbAgents = CAgent::GetList(array(), array("NAME" => "CCrmExternalSaleImport::DataSync(" . $id . ");", "MODULE_ID" => "crm")); if ($arAgent = $dbAgents->Fetch()) { if ($dataSyncPeriod > 0) { if ($arAgent["ACTIVE"] != "Y" || intval($arAgent["AGENT_INTERVAL"] / 60) != $dataSyncPeriod) { CAgent::Update($arAgent["ID"], array("ACTIVE" => "Y", "AGENT_INTERVAL" => 60 * $dataSyncPeriod));
$crmUrlScheme = 'http'; } $crmUrlPort = $arCrmUrl["port"] ? intval($arCrmUrl["port"]) : intval($_POST["PORT"]); if ($crmUrlPort <= 0) { $crmUrlPort = $crmUrlScheme == 'https' ? 443 : 80; } $arFields["SCHEME"] = $crmUrlScheme; $arFields["SERVER"] = $crmUrlHost; $arFields["PORT"] = $crmUrlPort; } if ($arParams["ID"] > 0) { //$arFields["MODIFICATION_LABEL"] = $_POST["MODIFICATION_LABEL"]; if (strlen($_POST["PASSWORD"]) > 0) { $arFields["PASSWORD"] = $_POST["PASSWORD"]; } $res = CCrmExternalSale::Update($arParams["ID"], $arFields); } else { $arFields["PASSWORD"] = $_POST["PASSWORD"]; $res = CCrmExternalSale::Add($arFields); } if (!$res) { if ($ex = $GLOBALS["APPLICATION"]->GetException()) { $errorMessage .= $ex->GetString() . ".<br>"; } else { $errorMessage .= "Unknown error." . "<br>"; } } } if (strlen($errorMessage) <= 0) { $dbAgents = CAgent::GetList(array(), array("NAME" => "CCrmExternalSaleImport::DataSync(" . intval($res) . ");", "MODULE_ID" => "crm")); if ($arAgent = $dbAgents->Fetch()) {
public function Send(array $request) { $method = isset($request['METHOD']) ? strtoupper($request['METHOD']) : ''; if ($method !== \Bitrix\Main\Web\HttpClient::HTTP_GET && $method !== \Bitrix\Main\Web\HttpClient::HTTP_POST) { throw new Bitrix\Main\ArgumentException("Could not find 'METHOD'.", 'request'); } $path = isset($request['PATH']) && is_string($request['PATH']) ? $request['PATH'] : ''; if ($path === '') { throw new Bitrix\Main\ArgumentException("Could not find 'PATH'.", 'request'); } $postData = $method === \Bitrix\Main\Web\HttpClient::HTTP_POST && isset($request['BODY']) ? $request['BODY'] : null; if (!$this->client) { $this->client = new \Bitrix\Main\Web\HttpClient(); } $this->client->setRedirect(false); if ($method === \Bitrix\Main\Web\HttpClient::HTTP_POST && is_array($postData)) { //Force UTF encoding $this->client->setCharset('UTF-8'); if ((!isset($request['UTF']) || !$request['UTF']) && !defined('BX_UTF')) { $postData = \Bitrix\Main\Text\Encoding::convertEncodingArray($postData, SITE_CHARSET, 'UTF-8'); } } $headers = isset($request['HEADERS']) ? $request['HEADERS'] : null; if (is_array($headers)) { foreach ($headers as $k => $v) { $this->client->setHeader($k, $v, true); } } if (!empty($this->cookies)) { $this->client->setCookies($this->cookies); } if ($this->enableProxy) { $this->client->setProxy($this->proxyServer, $this->proxyPort, $this->proxyUserName, $this->proxyUserPassword); } if ($this->userName !== '') { $this->client->setAuthorization($this->userName, $this->userPassword); } $this->client->setHeader('User-Agent', $this->userAgent, true); $absolutePath = $this->GetUrl() . $path; if (!$this->client->query($method, $absolutePath, $postData)) { $this->responseData = null; $this->errors = $this->client->getError(); } else { /**@var \Bitrix\Main\Web\HttpHeaders*/ $responseHeaders = $this->client->getHeaders(); //STATUS.VERSION & STATUS.PHRASE are delcared for backward compatibility only. $this->responseData = array('STATUS' => array('VERSION' => '', 'CODE' => $this->client->getStatus(), 'PHRASE' => ''), 'CONTENT' => array('TYPE' => $this->client->getContentType(), 'ENCODING' => $this->client->getCharset()), 'HEADERS' => $responseHeaders, 'BODY' => $this->client->getResult()); if ($responseHeaders->get('Set-Cookie', false) !== null) { $this->cookies = array_merge($this->cookies, $this->client->getCookies()->toArray()); CCrmExternalSale::Update($this->externalSaleId, array('COOKIE' => serialize($this->cookies))); } $this->errors = array(); } return $this->responseData; }