Curl 使用GCM推送通知发布数据

Curl 使用GCM推送通知发布数据,curl,google-cloud-messaging,push,service-worker,Curl,Google Cloud Messaging,Push,Service Worker,我正在试用GCM推送通知API。到目前为止,它运行良好,但我不确定如何发布附加数据 我遵循了本页上的步骤: 因此,我最终编写了一个curl请求,如下所示: curl--header“Authorization:key=myKey”--header“Content-Type:application/json”https://android.googleapis.com/gcm/send -d“{\”注册id\”:[myRegistrationId],“\”附加数据\“:{\”用户id \“:\”1

我正在试用GCM推送通知API。到目前为止,它运行良好,但我不确定如何发布附加数据

我遵循了本页上的步骤:

因此,我最终编写了一个
curl
请求,如下所示:

curl--header“Authorization:key=myKey”--header“Content-Type:application/json”https://android.googleapis.com/gcm/send -d“{\”注册id\”:[myRegistrationId],“\”附加数据\“:{\”用户id \“:\”1\“}}”

然后是我的
sw.js
(我的服务人员)

在这种情况下,是否有办法读取
附加数据
?还是我不应该这样做


谢谢你的阅读

我建议使用中的一个库,它们隐藏了推送有效负载的复杂性,并且支持标准的web推送协议(目前由Firefox支持,很快在Chrome中默认使用)和专有的GCM协议(在Chrome中迟早会被弃用)

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

我遵循了这一点,没有做任何更改

我尝试了
POST
cURL

curl --request POST --url localhost:8080/api/send-push-msg --header 'content-type: application/json' --data '{"subscription":{"endpoint":"https://fcm.googleapis.com/fcm/send/fKr7EsvRiyA:APA.....[Changes with your data]","keys":{"p256dh":"Your Key","auth":"Your Auth"}},"data":"Your Messages Here","applicationKeys":{"public":"Your Public Key Server","private":"Private Key Server"}}'

它对我很有效。:)

您可以在推送通知中发布其他数据,但数据大小有限制。但我如何在推送事件中发布和读取数据?服务器端您使用的是哪种语言?我的意思是,我在问题中发布了
curl
请求。我试图添加
附加数据
。参考Android hive gcm示例,您将获得正确的解决方案
curl --request POST --url localhost:8080/api/send-push-msg --header 'content-type: application/json' --data '{"subscription":{"endpoint":"https://fcm.googleapis.com/fcm/send/fKr7EsvRiyA:APA.....[Changes with your data]","keys":{"p256dh":"Your Key","auth":"Your Auth"}},"data":"Your Messages Here","applicationKeys":{"public":"Your Public Key Server","private":"Private Key Server"}}'