php - PHP脚本发送预定的firebase通知
问题描述
我需要使用没有 cron 作业的 PHP 代码来安排 firebase 云消息传递提供的推送通知。我目前正在使用此代码即时推送通知,但有时我需要在特定时间推送通知。
function push_notification_android($device_id,$message){
//API URL of FCM
$url = 'https://fcm.googleapis.com/fcm/send';
/*api_key available in:
Firebase Console -> Project Settings -> CLOUD MESSAGING -> Server key*/ $api_key = 'AAAAKZLje1I:APbGQDw8FD...TjmtuINVB-g';
$fields = array (
'registration_ids' => array (
$device_id
),
'data' => array (
"message" => $message
)
);
//header includes Content type and api key
$headers = array(
'Content-Type:application/json',
'Authorization:key='.$api_key
);
$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_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('FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);
return $result;
}
我在哪里可以安排推送通知的时间?
解决方案
推荐阅读
- swift - 无法推断 Swift 通用参数“T”
- mongodb - 使用 mongodb 配置进行 vernemq 授权
- ios - 在 ios 上运行 nativescript 时出错,但 xcode 运行成功
- java - 如何将以下一段 java 转换为 kotlin?
- pandas - 使用 If-else 更改 Pandas 中的值
- javascript - 使用 window.stop 停止 Promise
- android - 从与 ROOM 上的数组值部分匹配的列中搜索
- react-hook-form - 允许 Downshift useCombobox 选择不在列表中的项目
- c# - 无法在 AsyncPackage 扩展中命中 OnLoadOptions
- ruby-on-rails - 我在部署heroku时遇到了错误。我正在通过 cloud 9 IDE 做最新的 rails 教程