feat: update allowed frontend hosts and add clinic-pro.ir domain
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Sms\Provider;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
@@ -57,6 +58,9 @@ class KavehNegarProvider implements SmsProviderInterface
|
||||
'sender' => $this->sender(),
|
||||
]);
|
||||
return ($data['return']['status'] ?? 0) === 200;
|
||||
} catch (HttpExceptionInterface $e) {
|
||||
$this->logger->warning(sprintf('SMS send rejected (kavenegar): HTTP %d', $e->getResponse()->getStatusCode()), ['mobile' => $mobile]);
|
||||
return false;
|
||||
} catch (\Throwable $e) {
|
||||
$this->logger->error(sprintf('SMS send failed (kavenegar): %s @ %s:%d', $e->getMessage(), $e->getFile(), $e->getLine()), ['exception' => $e, 'mobile' => $mobile]);
|
||||
return false;
|
||||
@@ -66,12 +70,20 @@ class KavehNegarProvider implements SmsProviderInterface
|
||||
// token/token2/token3 مقدارِ دارای فاصله را رد میکنند؛ فاصله را با نیمفاصله (ZWNJ) جایگزین میکنیم.
|
||||
private const NO_SPACE_SLOTS = ['token', 'token2', 'token3'];
|
||||
|
||||
// کاوهنگار روی طول توکن سقف دارد؛ مقدار بلند (مثلاً نام کلینیک فارسی که هر کاراکترش
|
||||
// ۹ بایت URL-encode میشود) درخواست را بزرگ میکند و پاسخ 431 میگیریم. مقدار را cap میکنیم.
|
||||
private const MAX_TOKEN_LEN = 60;
|
||||
|
||||
private function forSlot(string $slot, string $value): string
|
||||
{
|
||||
if (!in_array($slot, self::NO_SPACE_SLOTS, true)) {
|
||||
return $value;
|
||||
$value = trim($value);
|
||||
if (in_array($slot, self::NO_SPACE_SLOTS, true)) {
|
||||
$value = preg_replace('/\s+/u', "\u{200C}", $value) ?? $value;
|
||||
}
|
||||
return preg_replace('/\s+/u', "\u{200C}", $value) ?? $value;
|
||||
if (mb_strlen($value, 'UTF-8') > self::MAX_TOKEN_LEN) {
|
||||
$value = mb_substr($value, 0, self::MAX_TOKEN_LEN, 'UTF-8');
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function sendTemplate(string $mobile, string $templateCode, array $vars): bool
|
||||
@@ -95,6 +107,11 @@ class KavehNegarProvider implements SmsProviderInterface
|
||||
}
|
||||
$data = $this->get('/verify/lookup.json', $params);
|
||||
return ($data['return']['status'] ?? 0) === 200;
|
||||
} catch (HttpExceptionInterface $e) {
|
||||
// 4xx/5xx از کاوهنگار (مثل 431): خطای دائم درخواست است نه transient؛
|
||||
// warning کوتاه با کد وضعیت، بدون dump کامل exception.
|
||||
$this->logger->warning(sprintf('SMS sendTemplate rejected (kavenegar): HTTP %d', $e->getResponse()->getStatusCode()), ['mobile' => $mobile, 'template' => $templateCode]);
|
||||
return false;
|
||||
} catch (\Throwable $e) {
|
||||
$this->logger->error(sprintf('SMS sendTemplate failed (kavenegar): %s @ %s:%d', $e->getMessage(), $e->getFile(), $e->getLine()), ['exception' => $e, 'mobile' => $mobile, 'template' => $templateCode]);
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user