new feature on sms and some bugs fixed

This commit is contained in:
2026-07-18 22:22:01 +03:30
parent 518334da11
commit fc9de5198c
20 changed files with 489 additions and 95 deletions
+9
View File
@@ -57,6 +57,15 @@ class ConfigService
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
/**
* سوییچ‌های پیامک اعلان (sms_notif_* / charge_notif).
* کلید نباشد → $default (معمولاً true تا رفتار قبلی حفظ شود).
*/
public function isSmsNotifEnabled(string $key, bool $default = true): bool
{
return $this->getBool($key, $default);
}
/** فروشگاهی (قطره / کشکول) — روت‌ها و رفتار store فقط وقتی true باشد فعال می‌شوند */
public function isStore(): bool
{
@@ -42,6 +42,10 @@ class SmsAlertService
$message = "موجودی کیف پول پیامک {$appName} صفر یا منفی شده است. لطفاً کیف پول را شارژ کنید.";
if (! app(\App\Services\ConfigService::class)->isSmsNotifEnabled('sms_notif_wallet_alert')) {
return;
}
foreach ($this->alertRecipients() as $mobile) {
app(SmsGatewayService::class)->send($mobile, $message, 'wallet_alert', isAlert: true);
}
+69
View File
@@ -0,0 +1,69 @@
<?php
namespace App\Services;
/**
* فیلتر سادهٔ واژه‌های نامناسب فارسی/انگلیسی برای پیامک ادمین به مشتری.
*/
class SmsProfanityFilter
{
/** @var list<string> */
private const BLOCKED = [
// English
'fuck', 'shit', 'bitch', 'asshole', 'bastard', 'dick', 'pussy', 'cunt',
'motherfucker', 'nigger', 'faggot', 'slut', 'whore',
// Persian (transliteration + common)
'کیر', 'کس', 'کص', 'جنده', 'جنده‌', 'گایید', 'گاییدن', 'گایدم', 'بیناموس',
'بی‌ناموس', 'بی ناموس', 'حرومزاده', 'حرامزاده', 'مادرجنده', 'ننه جنده',
'کونی', 'کون', 'لاشی', 'لاشه‌', 'عن', 'اشغال', 'دیوث', 'قرمساق',
'fuckyou', 'fck', 'f*ck', 's*it', 'b!tch',
];
/**
* @return array{ok: bool, matched: string|null}
*/
public function check(string $message): array
{
$normalized = $this->normalize($message);
if ($normalized === '') {
return ['ok' => true, 'matched' => null];
}
foreach (self::BLOCKED as $word) {
$needle = $this->normalize($word);
if ($needle === '') {
continue;
}
if (mb_strpos($normalized, $needle) !== false) {
return ['ok' => false, 'matched' => $word];
}
}
return ['ok' => true, 'matched' => null];
}
public function assertClean(string $message): void
{
$result = $this->check($message);
if (! $result['ok']) {
throw new \Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException(
'متن پیام حاوی محتوای نامناسب است. لطفاً متن را اصلاح کنید.'
);
}
}
private function normalize(string $text): string
{
$text = mb_strtolower($text, 'UTF-8');
$text = str_replace(
['ي', 'ك', 'ة', 'ؤ', 'إ', 'أ', 'آ', '‌', "\u{200c}"],
['ی', 'ک', 'ه', 'و', 'ا', 'ا', 'ا', '', ''],
$text
);
// فاصله‌های اضافه و علائم تکرارشونده را ساده کن
$text = preg_replace('/[^\p{L}\p{N}\s]+/u', ' ', $text) ?? $text;
$text = preg_replace('/\s+/u', ' ', $text) ?? $text;
return trim($text);
}
}