【问题标题】:I am sending push notification from web using firebase我正在使用 firebase 从网络发送推送通知
【发布时间】:2017-04-24 06:25:53
【问题描述】:

我正在使用 firebase 从 Web 发送推送通知,但我无法发送推送通知,而我只能获得名称。如何使用 firebase 从网络发送推送通知帮助我。

这是我的 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;
?>

【问题讨论】:

  • 您不应该使用 FCM 端点 (https://fcm.googleapis.com/fcm/send) 而不是 https://pushnotificatioexample.firebaseio.com/.json

标签: php android firebase firebase-cloud-messaging


【解决方案1】:

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

来自

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

$DEFAULT_URL = 'https://fcm.googleapis.com/fcm/send';

查看Firebase Cloud Messaging HTTP Protocolhere了解更多详情

【讨论】:

  • 很高兴知道这是有效的。请标记它的答案并投票。所以它会对其他人有所帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-11
  • 2020-06-11
  • 2018-06-01
  • 2019-03-18
相关资源
最近更新 更多