Добавлен LongPoll. Переработка ядра, переработка сборщика, переработка сообщений.

This commit is contained in:
RedHood
2020-09-26 20:28:13 +10:00
parent 48946d9070
commit ce92d44b8b
15 changed files with 1497 additions and 1079 deletions

View File

@@ -6,92 +6,49 @@ namespace VK\Browsers;
use VK\Core;
use Exception;
/**
* Реализация CURL
*
* @method protected static put(string $url, ...$params) Создать
*
* @package Browsers
* @author Arsen Mirzaev
*/
class Curl extends BrowserAbstract
{
/**
* SSL шифрование
* Изменить
*
* @var bool
* Для запросов на изменение (REST)
* Реализация HTTP POST
*
* @param string $url Запрашиваемая ссылка
* @param array $params Передаваемые параметры
*
* @return array Ответ сервера
*/
private static bool $ssl = false;
public static function post($url, $params = [])
public static function post(string $url, array $params = null): array
{
$c = curl_init();
curl_setopt($c, CURLOPT_HTTPHEADER, [
"Content-Type:multipart/form-data"
'Content-Type: multipart/form-data'
]);
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_POSTFIELDS, $params);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, $params);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
$result = json_decode(curl_exec($c), True);
curl_close($c);
if (isset($result['response']))
return $result['response'];
else if (isset($result['error']))
throw new Exception(json_encode($result), $result['error']['error_code']);
else if (!isset($result))
self::post($url, $params);
else
if (isset($result['response'])) {
return $result;
}
public static function getToken($url)
{
if (!self::checkSSL('localhost')) {
$core = Core::init();
$core->logger->notice('Соединение не защищено. Необходимо включить SSL шифрование');
}
if ($curl = curl_init()) {
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_USERAGENT, $_ENV['USERAGENT']);
if (isset($post_values)) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_values);
}
if ($cookie and isset(self::$cookie)) {
$send_cookie = [];
foreach (self::$cookie as $cookie_name => $cookie_val) {
$send_cookie[] = "$cookie_name=$cookie_val";
}
curl_setopt($curl, CURLOPT_COOKIE, join('; ', $send_cookie));
}
curl_setopt(
$curl,
CURLOPT_HEADERFUNCTION,
function ($curl, $header) use (&$headers) {
$len = strlen($header);
$header = explode(':', $header, 2);
if (count($header) < 2) // ignore invalid headers
return $len;
$name = strtolower(trim($header[0]));
if (isset($headers) and !array_key_exists($name, $headers))
$headers[$name] = [trim($header[1])];
else
$headers[$name][] = trim($header[1]);
return $len;
}
);
$out = curl_exec($curl);
curl_close($curl);
//if (isset($headers['set-cookie']))
// $this->parseCookie($headers['set-cookie']);
return ['header' => $headers, 'body' => $out];
} else if (isset($result['error'])) {
throw new Exception(json_encode($result), $result['error']['error_code']);
} else if (!isset($result)) {
self::post($url, $params);
} else {
return ['response' => $result];
}
}