Php 我正在使用firebase从web发送推送通知

Php 我正在使用firebase从web发送推送通知,php,android,firebase,firebase-cloud-messaging,Php,Android,Firebase,Firebase Cloud Messaging,我正在使用firebase从web发送推送通知,但我无法发送推送通知,因为我只能得到一个名称。如何使用firebase help me从web发送推送通知 这是我的php代码 <?php $DEFAULT_URL = 'https://pushnotificatioexample.firebaseio.com/.json'; $mytoken = $_POST['token']; $mymessage = $_POST['message']; echo $mytoken; echo '

我正在使用firebase从web发送推送通知,但我无法发送推送通知,因为我只能得到一个名称。如何使用firebase help me从web发送推送通知

这是我的php代码

<?php
$DEFAULT_URL = 'https://pushnotificatioexample.firebaseio.com/.json';

$mytoken = $_POST['token'];
$mymessage =  $_POST['message'];
echo $mytoken;
echo '<br>'.'</br>';
echo $mymessage;

$registrationIds = array($mytoken);

$message = array
       (
        'message'   => 'My awesome message',
        'title'     => 'My awesome title',
        'subtitle'  => 'My awesome subtitle',
        'tickerText'    => 'My awesome Ticker text',
        'vibrate'   => 1,
        'sound'     => 1,
        'largeIcon' => 'large_icon',
        'smallIcon' => 'small_icon'
       );

       $fields = array(
         'registration_ids' => $registrationIds,
         'data' => $message
        );

       $headers = array(
        'Authorization:key = AIzaSyC9M4KFwqdy3vjcIBx9TNO8M7IysADbY_s',
        'Content-Type: application/json'
        );

       $ch = curl_init();
       curl_setopt($ch, CURLOPT_URL, $DEFAULT_URL);
       curl_setopt($ch, CURLOPT_POST, true);
       curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
       curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);  
       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
       curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
       $result = curl_exec($ch);           
       if ($result === FALSE) {
           die('Curl failed: ' . curl_error($ch));
       }
       curl_close($ch);
       echo $result;
?>

看起来您正在从服务端脚本发送一条云消息。根据Firebase(FCM)的官方文档,您不必使用实时数据库中的url以及所有这些。所以你必须改变你的网址


有关更多详细信息,请参见和。

您是否应该使用FCM端点(
https://fcm.googleapis.com/fcm/send
)而不是
https://pushnotificatioexample.firebaseio.com/.json
?很高兴知道这是可行的。请标明答案并投票表决。因此,这将有助于其他人。
$DEFAULT_URL = 'https://pushnotificatioexample.firebaseio.com/.json';
$DEFAULT_URL = 'https://fcm.googleapis.com/fcm/send';