更新时间:2023-02-16 22:24:21
如果您使用的是网络推送,则可能与加密数据有关. 尝试使用下面的server.js代码:
If you are using web-push it might have something todo with your encrypted data. Try the below code for server.js:
var webPush = require('web-push');
const VALID_SUBSCRIPTION = {
endpoint: 'your-endpoint-id',
keys: {
p256dh: 'userPublicKey',
auth: 'your-auth-secret'
}
};
var payload = {
title: "This is a title",
body: "this is the body",
icon: "images/someImageInPath.png"
}
webPush.setGCMAPIKey("your-gcmapikey");
webPush.sendNotification(VALID_SUBSCRIPTION.endpoint, {
TTL: 10,
payload: JSON.stringify(payload),
userPublicKey: VALID_SUBSCRIPTION.keys.p256dh,
userAuth: VALID_SUBSCRIPTION.keys.auth,
})
.then(function() {
console.log(JSON.stringify(payload));
});