简体   繁体   English

谷歌云消息不发送通知

[英]Google cloud messaging not sending notification

Hello everyone I am able to get the token from GCM cloud and store it to my data base but when i am going to send notification on the relevant token it's output is something like {"multicast_id":8449678444605960595,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"NotRegistered"}]}大家好,我可以从 GCM 云中获取令牌并将其存储到我的数据库中,但是当我要在相关令牌上发送通知时,它的输出类似于 {"multicast_id":8449678444605960595,"success":0,"失败":1,"canonical_ids":0,"results":[{"error":"NotRegistered"}]}

I don't see error in code but if any one of you know please help me.I am not uploading my code because i think it doesn't have any logical error.but if any of you want so i am uploading my php script here

phpScript

 <?php
    //request url
    $url    = 'https://android.googleapis.com/gcm/send';

     $registrationIDs=array();
     $index=0;

    $host = "mysql7.000webhost.com"; 
        $dbname = "a1861947_lalitdb";     
        $username = "a1861947_lalit12"; 
        $password = "kush123"; 

       $con=mysqli_connect($host,$username,$password,$dbname);




    $apiKey = 'AIzaSyCL-BT0xo6RVB-eLeYKjH-g0n_CdjM9kN0';
     $querySelect="Select Token from token_reg";
         $result=mysqli_query($con,$querySelect);


           while($record = mysqli_fetch_array($result))
            {
                 $registrationIDs[$index++]=$record['Token'];
                }

    //payload datad
    $data   = array('Demo'=>'Accenture ne Pinnacle Bna Diya');

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

    //http header
    $headers = array('Authorization: key='. $apiKey,
                     'Content-Type: application/json');
      $ch = curl_init();

            // Set the url, number of POST vars, POST data
            curl_setopt($ch, CURLOPT_URL, $url);

            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

            // Disabling SSL Certificate support temporarly
            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));
            }

            // Close connection
            curl_close($ch);
            echo $result;

    ?>

//token_reg table has the tokens sent by GCM //token_reg 表包含 GCM 发送的令牌

The value you are passing in the multicast id does not look like a valid GCM token.您在多播 ID 中传递的值看起来不像有效的 GCM 令牌。 GCM tokens are much longer than what you have and usually contain letters numbers and some special characters. GCM 令牌比您拥有的要长得多,通常包含字母数字和一些特殊字符。

If you are registering your device correctly, it is likely an error in the code that saves this token.如果您正确注册了设备,则保存此令牌的代码中可能存在错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM