Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/wbs24.exchange1c/lib/ |
Upload File : |
<?php namespace Wbs24\Exchange1c; /** * Класс для работы с CURL */ class Curl { use Exception; public function __construct($objects = []) { $this->wrappers = new Wrappers($objects); } public function request($url, $param = [], $data = false) { $result = false; try { $saveLog = $param['saveLog'] ?? false; $isPost = $param['post'] ?? false; $headers = $param['headers'] ?? false; $getHeaders = $param['getHeaders'] ?? false; $allowRedirect = $param['allowRedirect'] ?? false; $maxRedirect = $param['maxRedirect'] ?? false; if ($saveLog) $this->createReport('api_log.txt', 'request to '.$url.': '.$data); $curl = $this->wrappers->Curl->curl_init($url); if ($headers) $this->wrappers->Curl->curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); if ($getHeaders) $this->wrappers->Curl->curl_setopt($curl, CURLOPT_HEADER, true); if ($isPost) $this->wrappers->Curl->curl_setopt($curl, CURLOPT_POST, true); if ($isPost && $data) $this->wrappers->Curl->curl_setopt($curl, CURLOPT_POSTFIELDS, $data); $this->wrappers->Curl->curl_setopt($curl, CURLOPT_TIMEOUT, 30); $this->wrappers->Curl->curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); if ($allowRedirect) $this->wrappers->Curl->curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); if ($allowRedirect && $maxRedirect) $this->wrappers->Curl->curl_setopt($curl, CURLOPT_MAXREDIRS, $maxRedirect); $response = $this->wrappers->Curl->curl_exec($curl); $error = $this->wrappers->Curl->curl_error($curl); $this->wrappers->Curl->curl_close($curl); if ($error) { $result = [ 'error' => $error, 'responce' => $response, ]; } else { if ($saveLog) $this->createReport('api_log.txt', 'response: '.$response); $result = $response; } } catch (SystemException $exception) { $this->exceptionHandler($exception); } return $result; } }