我正在尝试使用 firebase 云消息系统从服务器向我的 android 设备发送推送通知。我能够成功注册我的设备,并且也为我的设备生成了令牌。我无法使用以下脚本向我的设备发送通知
<?php
function send_notification($token1,$message)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array('registration_ids'=>$token1,'data'=>$message);
$header = array('Authorization:key = <my key here>','Content-Type: application/json');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
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;
}
require "init.php"; //my db details here
$sql = "select token from fbuser";
$result = mysqli_query($con,$sql);
$tokens = array();
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_assoc($result))
{
$tokens[] = $row["token"]; // i was able to successfully echo out token as well
}
}
mysqli_close($con);
$message = array("message"=> "This is a test message");
$message_status = send_notification($tokens,$message);
echo $message_status; ***//Trouble here. it just prints out "To" whenever i hit the php script***
?>
现在每当我点击脚本时,响应就会返回
To
没有别的了..也没有通知。无法弄清楚问题。请求您的指导。
谢谢