您可以通过 POST 请求执行此操作,但需要您首先使用服务凭据进行身份验证。最简单的方法是使用具有以下内容的节点应用程序:
var {google} = require('googleapis');
var MESSAGING_SCOPE = 'https://www.googleapis.com/auth/firebase.messaging';
var SCOPES = [MESSAGING_SCOPE];
function getAccessToken() {
return new Promise(function(resolve, reject) {
var key = require('./service-account.json');
var jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
SCOPES,
null
);
}
}
- 输入请求 URL 为
https://fcm.googleapis.com/v1/projects/<your-project-id>/messages:send
带标题'Authorization': 'Bearer ' + accesstoken
使用 POSTMAN 进行设置
Body > raw > JSON (application/json) 并添加以下代码:
{
"message": {
"token": "FCM_TOKEN",
"data": {
"body": "Body of Your Notification in data",
"title": "Title of Your Notification in data",
"key_1": "Value for key_1",
"key_2": "Value for key_2"
}
}
}
但是,如果您想跳过所有麻烦:Firebase 有一个内置的 FCM 工具,可让您发送手动通知HERE