【发布时间】:2019-04-06 07:34:45
【问题描述】:
我遵循以下 JSON 结构将推送通知从 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 脚本
<?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 );
?>
【问题讨论】:
-
Sumit,看来是你的
$notifyArray出错了,能不能改成下面答案给出的格式试试?