简体   繁体   English

通过AWS SNS将Json Payload发送到MPNS

[英]Send Json Payload to MPNS by AWS SNS

I want to send a json payload to Windows phone 7+ in push notification. 我想在推送通知中向Windows Phone 7+发送json负载。 I am using MPNS . 我正在使用MPNS I am using AWS SNS service for sending push notification. 我正在使用AWS SNS服务发送推送通知。 IF i am sending a String payload .Everything works for string payload. 如果我发送的是字符串有效负载,则一切适用于字符串有效负载。 I got stuck with Json payload . 我被Json负载卡住了。

paylaod = {default: "None", MPNS:  "<?xml version=\"1.0\" encoding=\"utf-8\"?><wp:Notification xmlns=\"WPNotification\"><wp:Toast><wp:Text1>SNS Test Message</wp:Text1></wp:Toast></wp:Notification>"}

resp = SNS.publish( target_arn: "arn:aws:sns:usXXXb64", message: paylaod.to_json,  message_structure: 'json')

I'm awfully unfamiliar with the Ruby language, but it seems to me that your call lacks message attributes, which are mandatory for JSON-based MPNS messages. 我完全不熟悉Ruby语言,但是在我看来,您的呼叫缺少消息属性,而消息属性对于基于JSON的MPNS消息是必需的。

The two attributes are as follows: 这两个属性如下:

For reference, the attributes are the following: 作为参考,这些属性如下:

  1. Attribute name: AWS.SNS.MOBILE.MPNS.Type 属性名称: AWS.SNS.MOBILE.MPNS.Type
    Type: string 类型:字符串
    Possible values: token (for tile notifications), toast or raw 可能的值: token (用于图块通知), toastraw

  2. Attribute name: AWS.SNS.MOBILE.MPNS.NotificationClass 属性名称: AWS.SNS.MOBILE.MPNS.NotificationClass
    Type: string 类型:字符串
    Possible values: realtime *, priority , regular (realtime worked for me with the Java SDK) 可能的值: realtime *, priorityregular (使用Java SDK的实时功能对我有效)

So your last line should look like this: 因此,您的最后一行应如下所示:

resp = SNS.publish(
    target_arn: "arn:aws:sns:usXXXb64",
    message: paylaod.to_json,
    message_structure: 'json',
    message_attributes: {
        "AWS.SNS.MOBILE.MPNS.Type" => {
            data_type: "String",
            string_value: "toast"
        },
        "AWS.SNS.MOBILE.MPNS.NotificationClass" => {
            data_type: "String",
            string_value: "realtime"
        }
    })

Note that the message_structure: 'json' line is equally important. 注意message_structure: 'json'行同样重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM