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; }
protected function isAuthorized($strOfficeLogin, $strPassword, $url) { try { $http = new HttpClient(); $http->setAuthorization($strOfficeLogin, $strPassword); $auth_status = trim($http->get($url)); if ($http->getStatus() != '200') { return false; } return $auth_status == 'ok' || $auth_status == 'ok:' || preg_match('{^ok:(.+)$}', $auth_status); } catch (\Exception $e) { error_log('Office external auth error: ' . $e->getMessage()); } return false; }
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } use Bitrix\Main\Web\HttpClient; use Bitrix\Main\Localization\Loc; use Bitrix\Main\IO\Path; Loc::loadLanguageFile(Path::combine(__DIR__, "statuses.php")); $orderID = strlen(CSalePaySystemAction::GetParamValue("ORDER_ID")) > 0 ? CSalePaySystemAction::GetParamValue("ORDER_ID") : $GLOBALS["SALE_INPUT_PARAMS"]["ORDER"]["ID"]; $login = CSalePaySystemAction::GetParamValue("API_LOGIN"); $password = CSalePaySystemAction::GetParamValue("API_PASSWORD"); $shopId = CSalePaySystemAction::GetParamValue("SHOP_ID"); $changePayStatus = CSalePaySystemAction::GetParamValue("CHANGE_STATUS_PAY") == "Y"; $statusUrl = "https://w.qiwi.com/api/v2/prv/{prv_id}/bills/{bill_id}"; $request = new HttpClient(); $request->setAuthorization($login, $password); $request->setHeader("Accept", "text/json"); $request->setCharset("utf-8"); $response = $request->get(str_replace(array("{prv_id}", "{bill_id}"), array($shopId, $orderID), $statusUrl)); if ($response === false) { return 1; } $response = (array) json_decode($response); if (!$response || !isset($response['response'])) { return 1; } $response = (array) $response['response']; if ((int) $response['result_code']) { CSaleOrder::Update($orderID, array("PS_STATUS" => "N", "PS_STATUS_CODE" => $response['result_code'], "PS_STATUS_MESSAGE" => Loc::getMessage("SALE_QWH_ERROR_CODE_" . $response['result_code']), "PS_STATUS_DESCRIPTION" => isset($response['description']) ? $response['description'] : "", "PS_RESPONSE_DATE" => \Bitrix\Main\Type\DateTime::createFromTimestamp(time()))); } elseif (isset($response['bill'])) { $bill = (array) $response['bill'];