php-Android通过Firebase推送通知(服务器端)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php-Android通过Firebase推送通知(服务器端),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2323字,纯文字阅读大概需要4分钟。
内容图文
![php-Android通过Firebase推送通知(服务器端)](/upload/InfoBanner/zyjiaocheng/691/3385764ac02648d191d57d663f989ea6.jpg)
我正在尝试使用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
并且没有其他..并且没有通知也传递.无法解决问题.要求您的指导.
谢谢
解决方法:
尝试使用“至”而不是“ registration_ids”
这是保存在邮递员历史中的身??体数据[我不记得它是否有效]:
{ "data": {
"score": "5x1",
"time": "15:10" }, "to" : "token_id"}
检查此脚本:如果要进行主题消息传递
$url = "https://fcm.googleapis.com/fcm/send";
$topic = "topic_name";
$fields = array(
"to" => "/topics/".$topic,
"data" => $message,
"time_to_live" => 30,
"delay_while_idle" => true
);
$auth_key = "auth_key";
$headers = array(
"Authorization: key=".$auth_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, $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);
希望对您有所帮助
内容总结
以上是互联网集市为您收集整理的php-Android通过Firebase推送通知(服务器端)全部内容,希望文章能够帮你解决php-Android通过Firebase推送通知(服务器端)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。