我正在向用戶發送消息。該消息已成功發送。但我不是在android手機上收到通知。我有代碼: -在android中使用php發送推送通知使用php
enter code here
public function send_android_notification($device,$message,$user,$sender_id,$reciever_id,$list_id,$username)
{
define('API_ACCESS_KEY', 'My key(i already embed)');
$registrationIds = array($device);
// prep the bundle
$msg = array
(
'message' => $message['Message']['message'],
'user'=>$user,
'sender_id' =>$sender_id,
'reciever_id' =>$reciever_id,
'list_id'=>$list_id,
'username' =>$username
);
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg
);
$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」:8119665273981115453, 「成功」:0, 「失敗」:1, 「canonical_ids」:0
失敗'InvalidRegistration',不成功。看文檔瞭解錯誤:https://developers.google.com/cloud-messaging/http-server-ref#table8 –
我不明白會發生什麼。該消息已成功發送但未收到通知。請幫忙! – kunal
「success」:0,「failure」:1 –