我正在尝试通过简单的curl请求发送fcm通知,并确认他们是否在浏览器上获取了
。我的代码
manifest.json
{
"gcm_sender_id": "103953800507"
}
app.js
var config = {
apiKey: "<API KEY>",
authDomain: "<ddd>",
databaseURL: "<dd>",
projectId: "<dd>",
storageBucket: "<bb>",
messagingSenderId: "<Server Id>"
};
firebase.initializeApp(config);
const messaging = firebase.messaging();
messaging.requestPermission().then(function() {
//getToken(messaging);
return messaging.getToken();
}).then(function(token){
console.log(token);
})
.catch(function(err) {
console.log('Permission denied', err);
});
messaging.onMessage(function(payload){
console.log('onMessage: ',payload);
});
firebase-messaging-sw.js
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js');
// Initialize Firebase
var config = {
apiKey: "<API KEY>",
authDomain: "<dd>",
databaseURL: "<dd>",
projectId: "<dd>",
storageBucket: "<dd>",
messagingSenderId: "<SERVER KEY>"
};
firebase.initializeApp(config);
const messaging = firebase.messaging();
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js"></script>
<script src="app.js"></script>
<link rel="manifest" href="manifest.json">
</head>
<body>
My firebase app
</body>
</html>
现在,当我第一次运行index.html时,它显示了用于订阅通知并返回令牌的弹出窗口
现在我使用curl命令发送消息
curl -X POST -H "Authorization: key=<SERVER API KEY>" -H "Content-Type: application/json" \
-d '{
"data": {
"notification": {
"title": "FCM Message",
"body": "This is an FCM Message"
}
},
"to": "<DEVICE KEY>"
}' https://fcm.googleapis.com/fcm/send
响应是
{"multicast_id":7157312120735409,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1531738949596250%7031b6f9fd7ecd"}]}
但是我仍然没有收到message.onMessage触发?我想念什么?
有什么方法可以在Firebase控制台上查看发送的邮件列表和状态吗?