【发布时间】:2020-01-22 04:06:33
【问题描述】:
我想从节点 js 向我的 android 设备的 chrome 浏览器发送推送通知。这可能吗?如果是这样,如何实现?提前致谢。
【问题讨论】:
-
您使用SNS服务发送通知
标签: node.js push-notification web-push
我想从节点 js 向我的 android 设备的 chrome 浏览器发送推送通知。这可能吗?如果是这样,如何实现?提前致谢。
【问题讨论】:
标签: node.js push-notification web-push
看看漂亮的模块web-push 你需要有GCM API key和VAPID key,第一次生成哪个模块帮你搞定。
const webpush = require('web-push');
// VAPID keys should only be generated only once.
const vapidKeys = webpush.generateVAPIDKeys();
webpush.setGCMAPIKey('<Your GCM API Key Here>');
webpush.setVapidDetails(
'mailto:example@yourdomain.org',
vapidKeys.publicKey,
vapidKeys.privateKey
);
// This is the same output of calling JSON.stringify on a PushSubscription
const pushSubscription = {
endpoint: '.....',
keys: {
auth: '.....',
p256dh: '.....'
}
};
webpush.sendNotification(pushSubscription, 'Your Push Payload Text');
祝你好运!
【讨论】: