【发布时间】:2017-09-07 08:22:10
【问题描述】:
我对这个庞大的网站推送通知世界非常陌生。如果有人可以通过最佳实践向我展示正确的道路,我将不胜感激。同样,它是关于使用 Firebase 的 WEBSITE 推送通知。
我的测试网站托管在 Azure 上,我在带有 SQL 服务器的 c# 环境中使用 .Net 平台。
我已经“记住”了 Firebase 谷歌文档。我还测试了如何检索令牌,刷新它......并使用邮递员向特定设备发送通知。
但是我还有很多问号。
我的第一个问题:保存在服务器上收到的令牌后的最佳做法是什么?在 SQL 数据库中?
function sendTokenToServer(currentToken) {
if (!isTokenSentToServer()) {
console.log('Sending token to server...');
setTokenSentToServer(true);
} else {
console.log('Token already sent to server so won\'t send it again ' +
'unless it changes');
}
第二个问题:现在假设我在数据库中有 50.000 个订阅者,在没有分组或主题的情况下向所有订阅者动态发送一个推送通知的最佳做法是什么? POST、CURL、FETCH 是最安全的传递方法……假设我正在使用 FETCH,我如何向这 50.000 个订阅者发送相同的通知。通过数据库循环?还是?
var key = 'YOUR-SERVER-KEY';
var to = 'YOUR-IID-TOKEN';
var notification = {
'title': 'Portugal vs. Denmark',
'body': '5 to 1',
'icon': 'firebase-logo.png',
'click_action': 'http://localhost:8081'
};
fetch('https://fcm.googleapis.com/fcm/send', {
'method': 'POST',
'headers': {
'Authorization': 'key=' + key,
'Content-Type': 'application/json'
},
'body': JSON.stringify({
'notification': notification,
'to': to
})
})
.then(function(response) {
console.log(response);
}).catch(function(error) {
console.error(error);
})
我的第三个问题:我可以改用 .Net 和 C# 来完成上述向我的 50.000 个订阅者发送单个通知的方法吗?关于示例代码的任何提示?
“提出愚蠢问题的人可能会在短时间内听起来很愚蠢,但不敢问愚蠢问题的人将在他/她的余生中保持愚蠢”
谢谢!
【问题讨论】:
标签: c# google-chrome firebase firebase-cloud-messaging