php 带有设备令牌的Firebase推送通知
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 带有设备令牌的Firebase推送通知相关的知识,希望对你有一定的参考价值。
<?php
/*
Firebase push notification with device token
Working for Android and iOS
*/
$device_token = array('device token here');
$apiKey = "Goole API here";
$url = 'https://fcm.googleapis.com/fcm/send';
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);
$notification_data = array(
'message' => 'This is the test message for FCM Testing',
);
$notification = array(
'body' => 'This is the test message for FCM Testing',
'sound' => 'default'
);
$post = array(
'registration_ids' => $device_token,
'notification' => $notification,
"content_available" => true,
'priority' => 'high',
'data' => $notification_data
);
$ch = curl_init();
// Set URL to FCM endpoint
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set JSON post data
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
$result = curl_exec($ch);
$responseJSON = json_decode($result);
curl_close($ch);
var_dump($responseJSON);
?>
以上是关于php 带有设备令牌的Firebase推送通知的主要内容,如果未能解决你的问题,请参考以下文章
Firebase 会惩罚失败的推送通知吗?
Swift iOS 13 推送通知设备令牌在 javascript/php/typescript 中转换
Firebase 网络推送通知令牌未获得
Ionic Firebase 推送通知问题
iOS Firebase 推送通知 - 收到令牌但推送不起作用
我应该自己保存firebase令牌还是在注册远程通知时自动完成?