GCM中的canonical_id为零 - Android
Posted
技术标签:
【中文标题】GCM中的canonical_id为零 - Android【英文标题】:canonical_id zero in GCM - Android 【发布时间】:2016-05-13 17:36:42 【问题描述】:我正在努力解决我在使用 GCM 时遇到的问题。推送通知未在我的手机中发送:(。从简单表单发送消息后(我输入用户的电子邮件和消息),我得到以下json响应。
"multicast_id":5448677994062381651,
"success":1,
"failure":0,
"canonical_ids":0,
"results":["message_id":"0:1463160271625523%cbfca9dcf9fd7ecd"
]
这是我的 php 文件。
<?php
include("init.php");
$url = 'https://gcm-http.googleapis.com/gcm/send';
$apikey = 'xxxxxxxxxxxxxxxxxx';
$message="";
$registration_ids = array();
if(isset($_POST['submit']))
$name = $_POST['email'];
$message = $_POST['message'];
$sql = "SELECT * FROM user_info where email = '".$name."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result))
array_push($registration_ids,$row['token_id']);
$message_send = array("Notice"=>$message);
$fields = array(
'registration_ids' => $registration_ids,
'data' => $message_send
);
$headers = array('Authorization: key='.$apikey,
'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_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);
echo "done".$result;
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin Area</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<form method="post" action="index.php">
<label>Enter email:</label>
<input type="text" name="email"/>
<label>Enter message:</label>
<input type="message" name="message" rows="2" cols="30"/>
<input type="submit" name="submit" value="Send"/>
</form>
可能出了什么问题?端口号可能是什么?
谢谢, 西奥。
【问题讨论】:
【参考方案1】:基于此documentation,"success":1
是已处理且未出现错误的消息数。这并不意味着消息已成功发送。这也可能意味着消息已排队等待发送。
另外,"canonical_ids":0
并不意味着有错误,这意味着没有需要更新其 ID 的设备。
检查这些相关问题:
I've Got This Response From The GCM Server "success":1 But the Notification not Come to the Device
Success:1 still no notification in android
Android GCM server sent but GCM not pushing to device【讨论】:
谢谢。我修好了它。我在 android.xml 文件中声明了错误的服务名称。哈哈.. 不错。 :) 编码愉快!以上是关于GCM中的canonical_id为零 - Android的主要内容,如果未能解决你的问题,请参考以下文章