使用GCM推送通知发布数据

时间:2016-06-22 11:39:20

标签: curl google-cloud-messaging push service-worker

我正在尝试GCM推送通知API。到目前为止它工作正常,但我不确定如何发布其他数据。

我按照此页面上的步骤操作:https://developers.google.com/web/fundamentals/getting-started/push-notifications/step-07

所以我最终写了curl --header "Authorization: key=myKey" --header "Content-Type: application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[myRegistrationId], \"additionalData\": {\"user_id\":\"1\"}}"这样的请求:

sw.js

然后是我的self.addEventListener('push', function(event) { console.log('Push message', event); var title = 'test a'; event.waitUntil( self.registration.showNotification(title, { body: 'The Message', icon: '/assets/img/logo.png', tag: 'my-tag' })); }); (我的服务人员)

additionalData

有没有办法在这次活动中宣读a - (b * (a / b)) =98-((2000000000123450*100)-(97*((2000000000123450*100)/97))) ?或者我不应该这样做?

感谢阅读!

1 个答案:

答案 0 :(得分:2)

我建议使用https://github.com/web-push-libs中的一个库,它们隐藏了与推送有效负载相关的复杂性,它们支持标准的网络推送协议(目前支持Firefox,很快就会在Chrome中使用)和专有的GCM协议(迟早会在Chrome中弃用)。

目前有Node.js,PHP,Python和Java库。