所以我有这个测试应用程序,我用它来学习如何从我桌面上托管的外部服务器向虚拟设备或智能手机发送推送通知。
然后我使用一个简单的表单并输入标题和消息,然后单击提交按钮发送通知。
我已经进行了三次检查,通知的编码很好,并且我能够将firebase令牌从android应用程序传递到服务器,服务器将其存储在MySQL数据库中。
该应用程序也正确发送令牌,server_key也正确(使用firebase网站内置的复制功能)
为什么我的通知没有显示?这是php中脚本的源代码,用于将通知发送到firebase:
<?php
require "init.php";
$message = $_POST['message'];
$title = $_POST['title'];
$path_to_fcm = 'https://fcm.googleapis.com/fcm/send';
$server_key = "AAAA0Tedu0Y:APA91bGF1k9LAVw90LVM9IdWludKeG1ueVo2V7HesN4CVz2KFvcwGvLkDymuHjm0IvfRvZ6wOEu5Q33pBgYDUXopvTOBSDKQJf2zFFp_22gTCrg6zxNxKyw8_0M9ciPLt3YyJOwkmNYR";
$sql = "select fcm_token from fcm_info";
$result = mysqli_query($con,$sql);
//these lines get the key that has been store (i only store one key from one app, so it takes the first value of the result
$row = mysqli_fetch_row($result);
$key = $row[0];
$header = array(
'Authorization:key=' .$server_key,
'Content-Type:application/json'
);
$field = array( 'to'=>$key,
'notification'=>array('title'=>$title,'body'=>$message)
);
$payload = json_encode($field);
//If echo $payload, It print the following:
/*
{
"to":"esM8_IMRWrw:APA91bEVOTjpC5kkqAWqWwEs7gNq5-4iUvL6fC947cfWkg1G0VhKDiuibSOr_xSNcIJ8rb4VewjNJ2Jd_0AXBdQgTbOO0FO-stmP3ymOCLGQlka3s2RQ3854UiPr_puc274hXSlQMLen",
"notification":{
"title":"asdasd",
"body":"asdasd"
}
}
So the json is properly formatted
*/
/*this generates the http url connection from my server to firebase push notification sending url. I think the error is somewhere in these lines, but i dont know where*/
$curl_session = curl_init();
curl_setopt($curl_session,CURLOPT_URL,$path_to_fcm);
curl_setopt($curl_session,CURLOPT_POST,TRUE);
curl_setopt($curl_session,CURLOPT_HTTPHEADER,$header);
curl_setopt($curl_session,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($curl_session,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($curl_session,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);
curl_setopt($curl_session,CURLOPT_POSTFIELDS,$payload);
$result = curl_exec($curl_session);
curl_close($curl_session);
mysqli_close($con);
?>
感谢任何帮助,提前谢谢!
答案 0 :(得分:1)
检查此链接以获取有关推送通知的更多信息
How to handle notification when app in background in Firebase