2017-02-22 1 views
8

ich unter Skript bin mit Benachrichtigung an bestimmte Benutzer senden:Firebase, wie Thema Mitteilung senden

<?php 
// API access key from Google API's Console 
define('API_ACCESS_KEY', 'My_API_KEY'); 
$registrationIds = array(TOKENS); 
// prep the bundle 
$msg = array 
(
    'body' => "abc", 
    'title'  => "Hello from Api", 
    'vibrate' => 1, 
    'sound'  => 1, 
); 

$fields = array 
(
    'registration_ids' => $registrationIds, 
    'notification'   => $msg 
); 

$headers = array 
(
    'Authorization: key=' . API_ACCESS_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_SSL_VERIFYPEER, false); 
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($fields)); 
$result = curl_exec($ch); 
curl_close($ch); 
echo $result; 
?> 

Script funktioniert gut, aber wie kann ich Benachrichtigung an alle Benutzer senden, meine App installiert. Ich habe ein Thema in meiner App (Benachrichtigungen) erstellt, und ich kann Benachrichtigungen an alle Benutzer über Firebase-Konsole senden. Kann mir jemand helfen, das obige Skript für das Thema zu aktualisieren.

+0

Können Sie den Code von Push-Benachrichtigungen an dem IDE zur Verfügung stellen? ! [Ich habe den PHP-Skriptteil codiert] (https://i.stack.imgur.com/LpuFJ.png) Ich weiß nicht, wie ich eine Anfrage an den Firebase-Server senden soll. Bitte teilen Sie die Codes in der IDE, die die Push-Benachrichtigung behandeln! [.] (Https://i.stack.imgur.com/cE21r.png) – Aacs

Antwort

11

I durch

ersetzt
$fields = array 
(
    'registration_ids' => $registrationIds, 
    'notification'   => $msg 
); 

Um

Fest
$fields = array 
(
    'to' => '/topics/alerts', 
    'notification'   => $msg 
); 
Verwandte Themen