如何在gcm推送通知有效负载中获取gcm.notification.body字段 [英] How to get gcm.notification.body field in gcm push notification payload
问题描述
我正在kotlin中制作一组脚本来测试推送通知,以便重构与通知相关的遗留代码。
我需要向gcm服务器发送post请求,其中有效负载会导致通知到达包含字段gcm.notification.body的我的手机,我似乎无法做到这一点。
目前我正在尝试使用Postman来计算有效载荷。我得到的最近是gcm.notification.data和fcm.notification.body。
I'm making set of scripts in kotlin for testing push notifications in order to refactor notification-related legacy code. I need to send post request to gcm server with such payload that would result in notification that arrives at my phone containing field "gcm.notification.body" and I cant seem to be able to do it. Currently I'm trying to figure out the payload by using Postman. "Closest" I got is "gcm.notification.data" and "fcm.notification.body".
首先使用此请求正文:
{
"to": "someDeviceToken",
"notification":{
"data":{
"title": "Title supported",
"message": "Notification Message",
"type": "example",
"id": 345,
"priority": 1,
"data": {
"images": [
"https://someimage.com/image.png"
]
}
}
}
}
第二个这个:
{
"to": "someDeviceToken",
"data":{
"fcm.notification.body":{
"title": "Title supported",
"message": "Notification Message",
"type": "example",
"id": 345,
"priority": 1,
"data": {
"images": [
"https://someimage.com/image.png"
]
}
}
}
}
我在任何地方找不到任何东西。谢谢
I can't find anything anywhere. Thank you
推荐答案
这有点像hacky但是有了同事,我们能够找到解决方案。适当的有效负载JSON将是这样的:
It's a little hacky but with colleague, we were able to figure out solution to this. Proper payload JSON would be like this:
{
"to": "someDeviceToken",
"data":{
"gcm.notification.e": 0,
"gcm.notification.body":{
"title": "Title supported",
"message": "Notification Message",
"type": "example",
"id": 345,
"priority": 1,
"data": {
"images": [
"https://someimage.com/image.png"
]
}
}
}
}
gcm.notification.e:1
不起作用 - 必须为0.
"gcm.notification.e": 1
doesn't work - it has to be 0.
这篇关于如何在gcm推送通知有效负载中获取gcm.notification.body字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!