我通過php代碼從服務器端推消息,總共有6個android設備,當我通過我的php腳本推送消息,然後我得到下面的響應,我得到通知4設備,但在2我以前不得到任何通知,我看到了 「成功」:6,在結果JSON響應另外這兩個Android設備ID打印,而 「canonical_ids」:2 PHP腳本:沒有從推到服務器端的推送通知
<?php
$registatoin_ids = array("XXXXXXX","XXXXXXX","XXXXXXX","XXXXXXX","XXXXXXX","XXXXXXX","XXXXXXX")
define('API_ACCESS_KEY', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
$message = array("notification_status"=>1,"message"=>"Hello Android"); // Response for android
$fields = array
(
'registration_ids' => $registatoin_ids,
'data' => array("price" => $message)
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send');
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);
curl_close($ch);
echo $result;
?>
響應:
{
"multicast_id": 5091283388403222000,
"success": 6,
"failure": 0,
"canonical_ids": 2,
"results": [
{
"registration_id": "XXXXXXXXXXXXXXXXXXXXXXXXXXX",
"message_id": "0:1439532747953065%12153c37f9fd7ecd"
},
{
"registration_id": "XXXXXXXXXXXXXXXXXXXXXXXXXXX",
"message_id": "0:1439532747954730%12153c37f9fd7ecd"
},
{
"message_id": "0:1439532747954278%12153c37f9fd7ecd"
},
{
"message_id": "0:1439532747963956%12153c37f9fd7ecd"
},
{
"message_id": "0:1439532747953665%12153c37f9fd7ecd"
},
{
"message_id": "0:1439532747954836%12153c37f9fd7ecd"
}
]
}
首先,對問題和標籤進行更具描述性的描述。 即將到來的問題,其設備的問題,假設你運行相同的代碼。因爲谷歌沒有錯誤迴應。 – Raja
想象一下,我們有**絕對不知道你在談論什麼樣的「設備」或「服務器」或「推」系統。在任何人能夠對此事進行任何說明之前,這需要更多的澄清。 – deceze
嗨Deceze然後讓你重播,你可以請檢閱我的代碼。並希望你能再次給我答覆,謝謝。 –