向多个设备发送SNS推送通知消息

huangapple go评论65阅读模式
英文:

Sending SNS push notification message to multiple devices

问题

我需要使用aws-sdk-go库将SNS推送通知发送到多个设备,传递设备令牌数组。

目前,我使用以下步骤将推送消息发送到SNS:

创建端点:

pl, err := svc.CreatePlatformEndpoint(&sns.CreatePlatformEndpointInput{
    PlatformApplicationArn: aws.String(topic),
    Token: aws.String(n.DeviceToken), // 只有一个设备令牌
})

向端点发送消息:

params := &sns.PublishInput{
    Message:          aws.String(payload),
    TargetArn:        aws.String(*pl.EndpointArn),
    MessageStructure: aws.String("json"),
}

我还没有找到一种只使用一个请求向多个设备发送一条推送消息的方法。这种可能吗?

像这个例子一样说明:

pl, err := svc.CreatePlatformEndpoint(&sns.CreatePlatformEndpointInput{
    PlatformApplicationArn: aws.String(topic),
    Token: []aws.String{token01, token02, token03}, // 设备令牌数组
})
英文:

I need to send SNS push notification to multiple devices passing the array of device tokens using aws-sdk-go lib.

Currently I'm sending the push message to SNS using this steps:

Creating the endpoint:

pl, err := svc.CreatePlatformEndpoint(&sns.CreatePlatformEndpointInput{
    PlatformApplicationArn: aws.String(topic),
    Token: aws.String(n.DeviceToken), // just one device token
})

Sending the message to endpoint:

params := &sns.PublishInput{
    Message:          aws.String(payload),
    TargetArn:        aws.String(*pl.EndpointArn),
    MessageStructure: aws.String("json"),
}

I have not seen a way to send one push message to multiple devices using just one request. Is it possible?

Like this example to illustrate:

pl, err := svc.CreatePlatformEndpoint(&sns.CreatePlatformEndpointInput{
    PlatformApplicationArn: aws.String(topic),
    Token: []aws.String{token01, token02, token03}, //array of device tokens
})

答案1

得分: 3

解决方案:我创建了一个主题,订阅了这个主题的设备,并向主题发送了推送消息。

英文:

Solution: I solved creating a topic, subscribing the devices in this topic and sending the push message to the topic.

huangapple
  • 本文由 发表于 2017年4月26日 05:48:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/43621542.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定