我已经按照谷歌教程https://developers.google.com/web/fundamentals/getting-started/codelabs/push-notifications/实现了Web Push API。
这个教程包括一种方法,可以用来将订阅推送到后端服务器:
function updateSubscriptionOnServer(subscription) {
// TODO: Send subscription to application server
...
}
我想将订阅与用户标识一起存储,以便可以选择要发送通知的用户。现在我在想,我需要将订阅的哪个部分存储在数据库中。我的订阅对象看起来像这样:
{"endpoint":"https://fcm.googleapis.com/fcm/send/...","keys":{"p256dh":"...","auth":"..."}}
我应该只创建一个包含(Id|User_Id|Subscription)列的“订阅”表格,其中包括整个JSON订阅吗?这是最佳实践吗? JSON的有效性是无限的吗?在取消订阅的情况下,我可以使用哪个字段来标识订阅?