doufu1970 2017-08-24 11:10
浏览 59

如何从我的服务器向firebase发送主题通知

I am sending a message from my server to firebase for a specific topic, I get back an id, but it does not get a notification to the app when I do it from the console to that topic the notification arrives.

How should I do it for a specific topic but that is a notification?

PHP:

<i>
<?php 
    function send_notification ($message)
    {
        $url = 'https://fcm.googleapis.com/fcm/send';
        $fields = array(

             'to' => "/topics/news",
             'data' => $message
            );
        $headers = array(
            'Authorization: key=AAAApDF81wE:APA91bG7g.....',
            'Content-Type: application/json'
            );
       $ch = curl_init();
       curl_setopt($ch, CURLOPT_URL, $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);
       return $result;
    }

    $message = array("message" => " FCM PUSH NOTIFICATION TEST MESSAGE");
    $message_status = send_notification($message);
    echo $message_status;
 ?>
</i>

I just changed this

$fields = array(

         'to' => "/topics/news",
         'notification' => $message
        );

  • 写回答

1条回答 默认 最新

  • dongxieyou3314 2017-08-25 17:21
    关注

    i Was not doing proper handling in the app, i should handle the logic and code implementation on how to handle incoming messages within the onMessageReceived method.

    评论

报告相同问题?

悬赏问题

  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了