android php 推送,php-Android通过Firebase推送通知(服务器端)

我正在尝试使用Firebase云消息传递系统从服务器向我的android设备发送推送通知.我能够成功注册我的设备,并且也为我的设备生成了令牌.我无法使用以下脚本将通知发送到我的设备

function send_notification($token1,$message)

{

$url = 'https://fcm.googleapis.com/fcm/send';

$fields = array('registration_ids'=>$token1,'data'=>$message);

$header = array('Authorization:key = ','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

并且没有其他..并且没有通知也传递.无法解决问题.要求您的指导.

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值