Update: 2026-07-23 16:56:57
This commit is contained in:
@@ -62,36 +62,13 @@ 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, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
|
||||
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $result;
|
||||
if (function_exists('sendFCM_Internal')) {
|
||||
return sendFCM_Internal($token, '', '', $data, 'SilentPush', false, 'silent');
|
||||
}
|
||||
if (!class_exists('FcmService')) {
|
||||
require_once __DIR__ . '/../core/Services/FcmService.php';
|
||||
}
|
||||
$fcm = new FcmService();
|
||||
return $fcm->send($token, '', '', $data, 'SilentPush', 'silent');
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user