Php Android推送通知未发送
我试图使用Php Android推送通知未发送,php,android,curl,push-notification,Php,Android,Curl,Push Notification,我试图使用cakephp发送推送通知,但推送通知未发送。 现在GCM id看起来不同的是google在推送通知过程中为eg(FravdrunUUU8:APA91bHvSGxi4AVPx2wGTFWb7OyAPPvXoIAcT)更改了一些内容。 每次我得到一个json,如下所示: { "multicast_id": 5873180458565135923, "success": 0, "failure": 1, "canonical_ids
cakephp
发送推送通知,但推送通知未发送。
现在GCM id看起来不同的是google在推送通知过程中为eg(FravdrunUUU8:APA91bHvSGxi4AVPx2wGTFWb7OyAPPvXoIAcT)更改了一些内容。
每次我得到一个json,如下所示:
{
"multicast_id": 5873180458565135923,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "NotRegistered"
}
]
}
我尝试了很多来自互联网的代码,但每次都得到了相同的结果。
我正在使用的代码在许多其他应用程序上工作得非常完美。
下面是我的代码:
` public function sendMessageAndroid($registatoin_ids, $message){
$url = 'https://android.googleapis.com/gcm/send';
$apiKey = "AIzaSyBf5vaONLbMyGdDoOEeC_MTTh9x1G4Qm-4";
$fields = array(
'registration_ids' => $registatoin_ids,//here my gcm id come in //array form array($device_id)
'data' => $message,//this is my message //$send_message['m']=array('msg'=>$message,'type'=>'chat');
);
$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);
return $result;
}`
我什么都试过了,但运气不好。请帮助。是的,我的问题现在解决了。我的代码中没有错误。这是我的移动开发人员的错误。每当你得到下面这样的回复时
` {
"multicast_id": 5873180458565135923,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [ { "error": "NotRegistered" }
`
这显然是android代码中的错误 你想说的可能重复。我不明白。请详细解释。你说“现在一天GCM id看起来不同是谷歌在推送通知过程中为eg(FravdrunUUU8:APA91bHvSGxi4AVPx2wGTFWb7OyAPPvXoIAcT)更改了一些东西”是什么意思?请改进你的写作,因为不清楚你在问什么。我认为kitkat版本后推送通知不会发送/接收。它们不会发送到棒棒糖和棉花糖上。@Alessandro Cuttin:上面的代码我在很多应用程序中都使用过,它工作得很好,但在我当前的应用程序中,它甚至在一些允许我们发送在线推送的在线网站上也不起作用类似于:也不发送推送通知总是在json下方返回:{“multicast_id”:5873180458565135923,“success”:0,“failure”:1,“canonical_id”:0,“results”:[{“error”:“notregisted”}]}