【问题标题】:how to send a notification for a theme from my server to firebase如何将主题的通知从我的服务器发送到 firebase
【发布时间】:2017-08-24 11:10:27
【问题描述】:

我正在从我的服务器向特定主题的 firebase 发送一条消息,我返回一个 id,但是当我从控制台向通知到达的主题执行此操作时,它没有收到应用程序的通知。

我应该如何针对特定主题执行此操作,但这是一个通知?

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>

我刚刚改了这个

$fields = 数组(

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

【问题讨论】:

  • 嗨卡罗来纳。您是否尝试过发送notification 消息负载?
  • 是这个...'to' => "/topics/news", 'notification' => $message
  • 但是消息是否包含正确的参数?如果您使用详细信息编辑您的帖子,我们会更容易看到。

标签: php android firebase firebase-cloud-messaging


【解决方案1】:

我没有在应用程序中进行适当的处​​理,我应该处理有关如何在 onMessageReceived 方法中处理传入消息的逻辑和代码实现。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-12
    • 2019-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-08
    • 2016-11-14
    相关资源
    最近更新 更多