大家好我能够从GCM云获取令牌并将其存储到我的数据库但是当我要发送相关令牌的通知时,它的输出就像是 {" multicast_id":8449678444605960595,"成功":0,"失效":1," canonical_ids":0,"结果& #34;:[{"错误":" 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表具有GCM发送的令牌
答案 0 :(得分:1)
您在多播ID中传递的值看起来不像有效的GCM令牌。 GCM令牌比你拥有的要长得多,通常包含字母数字和一些特殊字符。
如果您正确注册设备,则代码中可能会出现错误,无法保存此令牌。