dqrnsg6439 2016-10-24 06:37 采纳率: 100%
浏览 220

通过FCM向多个用户发送PUSH通知

I want to send the PUSH notification to the Multiple USERS through PHP script. When I run my script it shows the result successful, but on my device I am not getting any Notification.

But when I use the FCM console, I got the Notifications on my Device.

PHP script:

<?php
        function send_notification ($tokens, $message)
        {
                $url = 'https://fcm.googleapis.com/fcm/send';
                $fields = array(
                         'registration_ids' => $tokens,
                         'data' => $message,
                         'click_action' => ACTIVITY_CIRCULAR
                        );
                $headers = array(
                        'Authorization:key = my key',
                        '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;
        }


        $conn = mysqli_connect("connection set-up");
        $sql = "Select FirebaseID From Coordinates";
        $result = mysqli_query($conn,$sql);
        $tokens = array();
//var_dump(result);
        if(mysqli_num_rows($result) > 0 ){
                while ($row = mysqli_fetch_assoc($result)) {
                        $tokens[] = $row["FirebaseID"];
                }
        }
    var_dump($tokens);

        mysqli_close($conn);
        $message = array("message" => "Hello World");
        $message_status = send_notification($tokens, $message);
        echo $message_status;
 ?> 

My result:

{"multicast_id":6386552330832519***,"success":2,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1477******764957%e8a8d907f9fd7ecd"},{"message_id":"0:1477293027764959%e8a8d907f9f***cd"}]}

EDIT : Is there any way to check where the message is failing because it shows the Successful in Result...but it doesn't reach to device

  • 写回答

3条回答 默认 最新

  • doutang1946 2016-10-24 06:40
    关注

    please check that you have saved the device id properly or not ,and also check that you have used the same server key as per project android key ,check your google account

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP