Вебхуки: подписки, подпись посылок и доставка очередью

Общий HTTP-клиент с настройкой CA-бандла, на него же переведён драйвер mailer.
Воркер умеет несколько очередей: worker --queue=default,webhooks.
This commit is contained in:
rsgrinko committed 2026-09-13 00:21:59 +03:00
1 parent 3f64f4a49a
commit fce276bb13
17 files changed
+1537 -77

No files matched your search

+5 -49
View File
@@ -6,6 +6,7 @@ namespace Rsgrinko\Proton\Mail\Drivers;
use Rsgrinko\Proton\Mail\Message;
use Rsgrinko\Proton\Support\Config;
use Rsgrinko\Proton\Support\HttpClient;
use Rsgrinko\Proton\Support\ProtonException;
use Rsgrinko\Proton\Support\RequestId;
@@ -84,55 +85,10 @@ final class MailerServiceDriver implements DriverInterface
{
$timeout = max(2, (int) Config::get('mail.service.timeout', 10));
if (function_exists('curl_init')) {
$curl = curl_init($url);
curl_setopt_array($curl, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $body,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => $timeout,
]);
$response = curl_exec($curl);
$status = (int) curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$error = curl_error($curl);
curl_close($curl);
if ($response === false) {
throw new ProtonException('Почтовый сервис недоступен: ' . $error);
}
return ['status' => $status, 'body' => (string) $response];
try {
return (new HttpClient($timeout))->post($url, $body, $headers);
} catch (ProtonException $e) {
throw new ProtonException('Почтовый сервис недоступен: ' . $e->getMessage());
}
$context = stream_context_create([
'http' => [
'method' => 'POST',
'header' => implode("\r\n", $headers),
'content' => $body,
'timeout' => $timeout,
// Нужен ответ, а не исключение: код разбираем сами
'ignore_errors' => true,
],
]);
$response = @file_get_contents($url, false, $context);
if ($response === false) {
throw new ProtonException('Почтовый сервис недоступен: ' . $url);
}
$status = 0;
foreach ($http_response_header ?? [] as $header) {
if (preg_match('#^HTTP/\S+\s+(\d{3})#', $header, $matches) === 1) {
$status = (int) $matches[1];
}
}
return ['status' => $status, 'body' => $response];
}
}
+18 -7
View File
@@ -7,6 +7,7 @@ namespace Rsgrinko\Proton\Mail\Drivers;
use Rsgrinko\Proton\Mail\Message;
use Rsgrinko\Proton\Mail\Mime;
use Rsgrinko\Proton\Support\Config;
use Rsgrinko\Proton\Support\HttpClient;
use Rsgrinko\Proton\Support\ProtonException;
/**
@@ -114,13 +115,23 @@ final class SmtpDriver implements DriverInterface
$address = ($encryption === 'ssl' ? 'ssl://' : 'tcp://') . $host . ':' . $port;
$context = stream_context_create([
'ssl' => [
'verify_peer' => (bool) Config::get('mail.smtp.verify_peer', true),
'verify_peer_name' => (bool) Config::get('mail.smtp.verify_peer', true),
'allow_self_signed' => !(bool) Config::get('mail.smtp.verify_peer', true),
],
]);
$verify = (bool) Config::get('mail.smtp.verify_peer', true);
$ssl = [
'verify_peer' => $verify,
'verify_peer_name' => $verify,
'allow_self_signed' => !$verify,
];
// У PHP может не быть своего хранилища корневых сертификатов —
// тогда путь к нему берём из настройки HTTP_CA_BUNDLE
$ca = HttpClient::caBundle();
if ($ca !== '') {
$ssl['cafile'] = $ca;
}
$context = stream_context_create(['ssl' => $ssl]);
$socket = @stream_socket_client($address, $code, $error, $timeout, STREAM_CLIENT_CONNECT, $context);