Push push, via php, to all users

0

I'm working on a project with ionic 3 and backend in php / mysql. In the current phase I need to send push notifications and I chose to work with the firebase and the phonegap-plugin-push plugin. I installed and tested via firebase console and the notification was sent correctly. I did this, I came up with a php template for sending notifications without using the firebase console, but I encountered a difficulty: I do not know how to send a notification to all devices (not by id).

Follow the PHP code used:

<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' );
// set only for one for safety
$registrationId = $_GET['id'];
$texto = $_GET['texto'];
// prep the bundle
$msg = array
(
'title' => 'Notificação',
'body' => $texto,
'icon' => 'myicon',
'sound' => 'default'
);
$fields = array
(
'priority' => 'high',
'to' => $registrationId,
'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, true );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;
?>

Obs. 1: In the firebase console you have both options.

Obs. 2: The above code works correctly when given the id.

What do I put in 'to' => $registrationId, so that all devices receive the notification?

    
asked by anonymous 23.09.2017 / 18:24

0 answers