How to get gcm.notification.body field in gcm push

2019-08-31 00:21发布

问题:

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".

First with this request body:

{  
    "to":  "someDeviceToken",
    "notification":{
        "data":{
            "title": "Title supported",
            "message": "Notification Message",
            "type": "example",
            "id": 345,
            "priority": 1,
            "data": {
                "images": [ 
                    "https://someimage.com/image.png"
                ]
            }
        }
    }
}

Second with this one:

{  
    "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

回答1:

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 doesn't work - it has to be 0.