php - 是否可以检查firebase是否将通知传递到php中的单个设备?
问题描述
我有一个在服务器上使用 MySQL 数据库的 android 应用程序。当新数据插入表中时,我的 php 文件通过 Firebase 推送通知。如果 firebase 将通知发送到单个设备,则数据将保存到 table_1,如果 firebase 无法发送通知,则将数据保存到 table_2。我的问题是;是否可以检查firebase是否在php中传递通知?
FirebaseNotification.php
class FirebaseNotification {
public function send($registration_ids, $notification){
$fields = array(
'registration_ids' => $registration_ids,
'data' => $notification
);
return $this->sendPushNotification($fields);
}
private function sendPushNotification($fields){
require_once dirname(__FILE__) . '/Constants.php';
$url = 'https://fcm.googleapis.com/fcm/send';
$headers = array(
'Authorization: key=' . FIREBASE_API_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);
if ($result === FALSE){
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
return $result;
}
}
PushNotification.php
class PushNotification{
private $mTitle;
private $mContent;
private $mProcess;
function __construct($mTitle, $mContent, $mProcess)
{
$this->mTitle = $mTitle;
$this->mContent = $mContent;
$this->mProcess = $mProcess;
}
public function getPushNotification(){
$res = array();
$res['ntf']['title'] = $this->mTitle;
$res['ntf']['content'] = $this->mContent;
$res['ntf']['process'] = $this->mProcess;
return $res;
}
}
解决方案
不幸的是,这是目前不可能的。从专用后端,您只能检查消息是否已成功传递到 Firebase 或 Firebase 是否拒绝了该消息(例如,当它格式错误或目标不存在时)。
但是,无法从专用后端跟踪或检查从 Firebase 到接收者的交付 - 没有我们可以调用的 API 端点来执行此操作。
据我所知,这目前不适用于通过 Firebase Web 控制台发送的消息。
推荐阅读
- c# - COM 在构建 DLL 时如何补充 .NET Framework?
- python - 格式化小数位
- reactjs - POST 请求返回未在反应中找到但适用于邮递员
- c# - c#从XML读入类并写回文件的最佳方法
- node.js - TypeError:尝试使用 node.js 加密模块中的函数时,generateKeyPair 不是函数
- python - 是否可以在 List.append 等方法上使用 map
- javascript - 为什么状态不会在计算中更新?
- docker - standard_init_linux.go:190: exec 用户进程在运行 Go 二进制文件时导致“exec 格式错误”
- javascript - 如何从对象中的 forEach 中获取搜索结果?
- c# - C# .NET WPF - DataTable (SQLite) 作为带有分组的 DataGrid 源