prepare($sql); $stmt->execute(); $inactiveUsers = $stmt->fetchAll(PDO::FETCH_ASSOC); $sentCount = 0; $fcmService = new FcmService(); // Assuming we have an FcmService or we can use sendFcmNotification directly if it's in functions.php // In Siro, encryptionHelper is typically used for tokens. Assuming it's required here: require_once __DIR__ . '/../core/Security/EncryptionHelper.php'; $encryptionHelper = new EncryptionHelper(); foreach ($inactiveUsers as $user) { $passengerId = $user['passenger_id']; $encryptedToken = $user['token']; $decryptedToken = $encryptionHelper->decryptData($encryptedToken); if ($decryptedToken) { // Send a silent push notification. // A silent push doesn't have a 'notification' payload (title/body), // it only has a 'data' payload with 'content-available' => 1 for iOS. $dataPayload = [ 'type' => 'location_sync_request', 'action' => 'wake_up' ]; // This is a pseudo implementation relying on your existing push notification setup. // Ensure that your FCM implementation correctly maps 'content-available' for iOS. sendSilentFcmNotification($decryptedToken, $dataPayload); $sentCount++; } } echo "Silent Push triggered for $sentCount inactive users.\n"; /** * Helper to send Silent FCM */ function sendSilentFcmNotification($token, $data) { // Basic curl request to FCM API for silent push $url = 'https://fcm.googleapis.com/fcm/send'; // Replace with your actual server key $serverKey = getenv('FCM_SERVER_KEY') ?: 'YOUR_LEGACY_SERVER_KEY'; $fields = [ 'to' => $token, 'data' => $data, 'content_available' => true, // Required for iOS to wake up in background 'priority' => 'high' // Sometimes required to wake up Android ]; $headers = [ 'Authorization: key=' . $serverKey, 'Content-Type: application/json' ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); $result = curl_exec($ch); curl_close($ch); return $result; } ?>