[英]AmazonSimpleNotificationServiceClient - How to PublishRequest with TargetArn that contains Custom Payload without "default" value?
I have:我有:
{ "GCM": "{ "data": { "MyTitle": "Sample endpoints", "MyMessage": "Important" } }" } { "GCM": "{ "data": { "MyTitle": "示例端点", "MyMessage": "重要" } }" }
Amazon SNS Console - Publish Message Amazon SNS 控制台 - 发布消息
"{MyTitle=Sample endpoints, MyMessage=Important}" “{MyTitle=示例端点,MyMessage=重要}”
Android Studio - Message received Android 工作室 - 收到消息
Visual studio .NET Application视觉工作室 .NET 应用
{default={"GCM": "{ "data": {"MyTitle": "Sample endpoints", "MyMessgae": "Criticald" } } " }} {default={"GCM": "{ "data": {"MyTitle": "示例端点", "MyMessgae": "Criticald" } } " }}
Android Studio - Message received Android 工作室 - 收到消息
Sending the message from the AWS Console is different from sending the message using AmazonSimpleNotificationServiceClient.从 AWS 控制台发送消息不同于使用 AmazonSimpleNotificationServiceClient 发送消息。
You will need to construct "PublishRequest" object.您将需要构建“PublishRequest”object。
This is a working code:这是一个工作代码:
// Android Payload
string payload = "\\\"data\\\":{\\\"MyTitle\\\":\\\"test message \\\", \\\"MyMessage\\\": \\\"Important\\\"}";
// iOS Payload
//string payload = "\\\"notification\\\" : {\\\"content_available\\\" : true }, \\\"data\\\": { \\\"MyTitle\\\": \\\"Sample message for iOS endpoints\\\", \\\"MyMessage\\\":\\\"Hello world\\\",\\\"Payload\\\": {\\\"InstructionID\\\": \\\"f7a87860-11f4-47e1-8a39-3da2ffd6eadb\\\",\\\"IsAlert\\\": false,\\\"Content\\\": \\\"This is new content\\\",\\\"Value\\\": 2.554,\\\"Counter\\\": 290,\\\"DateTime\\\": \\\"2022-09-11T16:13:57.2009482Z\\\"}}";
var request = new PublishRequest
{
Message = "{\"default\": \"default message\",\"GCM\":\"{" + payload + "}\"}",
TargetArn = fcmARN,
MessageStructure = "json"
};
try
{
var response = await snsClient.PublishAsync(request);
if (response.HttpStatusCode.Equals(HttpStatusCode.OK))
Console.WriteLine("Message Sent to Topic");
else
Console.WriteLine("Failed - Message Sent to Topic");
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
Example Message: enter image description here示例消息:在此处输入图像描述
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.