Compare commits

2 Commits
Author SHA1 Message Date
Hamza-Ayed ae723a75f6 Update: 2026-06-30 21:59:55 2026-06-30 21:59:55 +03:00
Hamza-Ayed e7785c9b2d Log FCM errors in debug_info when push notification fails 2026-06-30 21:59:00 +03:00
2 changed files with 9 additions and 27 deletions
+9 -1
View File
@@ -100,6 +100,7 @@ try {
$sentSms = 0;
$sentWhatsApp = 0;
$dispatchedPassengers = [];
$fcmErrors = [];
// 6. Save broadcast promo for this campaign (Option 1 - promos table adjustment)
$sqlPromo = "INSERT INTO promos
@@ -157,8 +158,14 @@ try {
$logStmt->execute([$passengerId, $countryCode, $regionName]);
$dispatchedPassengers[] = $passengerId;
$pushSent = true;
} else {
$fcmErrors[] = ['passenger_id' => $passengerId, 'error' => $fcmResult];
}
} else {
$fcmErrors[] = ['passenger_id' => $passengerId, 'error' => 'Token decryption failed'];
}
} else {
$fcmErrors[] = ['passenger_id' => $passengerId, 'error' => 'No token in DB'];
}
if (!$pushSent) {
@@ -224,7 +231,8 @@ try {
'requested_country' => $countryCode,
'total_passengers_in_db' => count($allPassengers),
'matched_targets' => count($targets),
'distribution' => $debugCounts
'distribution' => $debugCounts,
'fcm_errors' => $fcmErrors ?? []
]
]);
@@ -53,32 +53,6 @@ class EncryptionHelper
$decoded = base64_decode($cipherText, true);
if ($decoded === false) return false;
// محاولة أولى: استخراج IV عشوائي من أول 16 بايت (كما كان في encrypt_decrypt.php)
if (strlen($decoded) >= 16) {
$iv = substr($decoded, 0, 16);
$payload = substr($decoded, 16);
if (strlen($payload) > 0) {
$decrypted_rand = openssl_decrypt($payload, self::ALGO_CBC, $this->key, OPENSSL_RAW_DATA, $iv);
if ($decrypted_rand !== false) {
$pad = ord($decrypted_rand[strlen($decrypted_rand) - 1]);
if ($pad >= 1 && $pad <= 16) {
// Check if padding is valid
$isValidPad = true;
for ($i = 1; $i <= $pad; $i++) {
if (ord($decrypted_rand[strlen($decrypted_rand) - $i]) !== $pad) {
$isValidPad = false;
break;
}
}
if ($isValidPad) {
return substr($decrypted_rand, 0, -$pad);
}
}
}
}
}
// محاولة ثانية: IV ثابت
$decrypted = openssl_decrypt($decoded, self::ALGO_CBC, $this->key, OPENSSL_RAW_DATA, $this->cbcIv);
if ($decrypted === false) return false;