芝麻web文件管理V1.00
编辑当前文件:/home/palsarh/web/palsarh.in/public_html/send_notification.php
'🎉 Hello Everyone!', 'body' => 'This is a broadcast to all users.', 'sound' => 'custom_sound', // No extension if it's an Android raw resource 'click_action' => 'FLUTTER_NOTIFICATION_CLICK' ]; $fields = [ 'to' => '/topics/all_users', // Send to all users subscribed to this topic 'notification' => $notification, 'priority' => 'high' ]; $headers = [ 'Authorization: key=' . FCM_SERVER_KEY, 'Content-Type: application/json' ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); $response = curl_exec($ch); if ($response === FALSE) { die('Curl failed: ' . curl_error($ch)); } curl_close($ch); echo 'FCM Response: ' . $response; ?> Project Settings -> Cloud Messaging) define('FCM_SERVER_KEY', 'YOUR_SERVER_KEY_HERE'); // Target device token $deviceToken = 'TARGET_DEVICE_FCM_TOKEN'; // Notification payload $notification = [ 'title' => '🔔 Urgent Alert!', 'body' => 'This will ring until you tap it!', 'sound' => 'custom_sound', // Custom sound (without extension if raw resource in Android) 'click_action' => 'FLUTTER_NOTIFICATION_CLICK' ]; // Data payload (optional) $data = [ 'key1' => 'value1', 'key2' => 'value2' ]; // Message body $fields = [ 'to' => $deviceToken, 'notification' => $notification, 'data' => $data, 'android' => [ 'priority' => 'high', ], 'priority' => 'high' ]; // Headers $headers = [ 'Authorization: key=' . FCM_SERVER_KEY, 'Content-Type: application/json' ]; // Send request $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); $response = curl_exec($ch); if ($response === FALSE) { die('Curl failed: ' . curl_error($ch)); } curl_close($ch); // Output response echo 'FCM Response: ' . $response; */ ?>