How to send Extra parameters in payload via Amazon SNS Push Notification

前端 未结 4 1955
走了就别回头了
走了就别回头了 2020-12-13 02:18

This is something new i am asking as i haven\'t got it any answers for it on SO.

I am using Amazon SNS Push for sending push to my registered devices, everything is

4条回答
  •  情深已故
    2020-12-13 03:11

    The Amazon SNS documentation is still lacking here, with few pointers on how to format a message to use a custom payload. This FAQ explains how to do it, but doesn't provide an example.

    The solution is to publish the notification with the MessageStructure parameter set to json and a Message parameter that is json-encoded, with a key for each transport protocol. There always needs to be a default key too, as a fallback.

    This is an example for iOS notifications with a custom payload:

    array(
        'TargetArn' => $EndpointArn,
        'MessageStructure' => 'json',
        'Message' => json_encode(array(
            'default' => $title,
            'APNS' => json_encode(array(
                'aps' => array(
                    'alert' => $title,
                ),
                // Custom payload parameters can go here
                'id' => '123',
                's' => 'section'
            ))
    
        ))
    );
    

    The same goes for other protocols as well. The format of the json_encoded message must be like this (but you can omit keys if you don't use the transport):

    { 
        "default": "", 
        "email": "", 
        "sqs": "", 
        "http": "", 
        "https": "", 
        "sms": "", 
        "APNS": "{\"aps\":{\"alert\": \"\",\"sound\":\"default\"} }", 
        "APNS_SANDBOX": "{\"aps\":{\"alert\": \"\",\"sound\":\"default\"} }", 
        "GCM": "{ \"data\": { \"message\": \"\" } }", 
        "ADM": "{ \"data\": { \"message\": \"\" } }" 
    }
    

提交回复
热议问题