Ниже приведена структура JSON для отправки push-уведомлений из скрипта PHP в приложение для Android, но я не могу этого добиться.Я использую POSTMAN и получаю код состояния 200, но уведомление не получено.
СТРУКТУРА JSON Я СОБЛЮДАЮ:
https://firebase.google.com/docs/cloud-messaging/concept-options
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification":{
"title":"Portugal vs. Denmark",
"body":"great match!"
}
}
}
PHP SCRIPT
<?php
$API_KEY="AAAAoyz8W_Q:APA91bFIJxTqoBnQo218QIIXi7uCmHFRP604RTC......";
$url = "https://fcm.googleapis.com/fcm/send";
$headers = array(
'Authorization:key='.$API_KEY,
'Content-Type:application/json'
);
$token="2tJfPjKZQ6UTVG....";
$notify=array("message"=>
array('token' =>$token,
'notification'=>array('title'=>"Title",
'body'=>"Body")));
$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($notify));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}else{
echo $ch;
}
curl_close ( $ch );
?>