我需要发送200条短信,并查看亚马逊文档,我发现如何通过订阅主题但只能逐一进行。
public static void main(String[] args) {
AmazonSNSClient snsClient = new AmazonSNSClient();
String phoneNumber = "+1XXX5550100";
String topicArn = createSNSTopic(snsClient);
subscribeToTopic(snsClient, topicArn, "sms", phoneNumber);
}
public static void subscribeToTopic(AmazonSNSClient snsClient, String topicArn,
String protocol, String endpoint) {
SubscribeRequest subscribe = new SubscribeRequest(topicArn, protocol,
endpoint);
SubscribeResult subscribeResult = snsClient.subscribe(subscribe);
}
有没有办法向端点发送电话号码列表,或者我订阅了SubscribeRequest列表?
答案 0 :(得分:2)
目前,当您为SNS主题创建订阅时,无法 将 list of phone numbers
作为端点传递。每个订阅只能将 ONE
电话号码作为端点。
对于电子邮件,我们只能提供群组电子邮件ID,电子邮件服务器将处理分发列表。但电话号码不可能类似。 As far as SNS is concerned, it needs a single endpoint for a selected protocol(SMS/EMAIL)
为了简化操作,您可以在代码中维护电话号码列表。您可以遍历列表并每次使用 subscribeToTopic
调用same topic ARN but different phone number
方法。但我相信你会自己想到这个。
答案 1 :(得分:0)
我们可以使用AWS开发工具包将电话号码列表传递给端点。
如果您需要将消息发送给多个收件人,则在阅读发送至多个电话号码的亚马逊文档(https://docs.amazonaws.cn/en_us/sns/latest/dg/sms_publish-to-topic.html)时值得阅读。
SNS服务实现了“发布-订阅”模式,您可以使用它来将消息发送到主题。以下是完成这项工作的步骤:
python代码看起来像这样:
import boto3
# Create an SNS client
client = boto3.client(
"sns",
aws_access_key_id="YOUR ACCES KEY",
aws_secret_access_key="YOUR SECRET KEY",
region_name=us-east-1
)
# Create the topic if it doesn't exist
topic = client.create_topic(Name="invites-for-push-notifications")
topic_arn = topic['TopicArn'] # get its Amazon Resource Name
#Get List of Contacts
list_of_contacts = ["+919*********", "+917********", "+918********"]
# Add SMS Subscribers
for number in some_list_of_contacts:
client.subscribe(
TopicArn=topic_arn,
Protocol='sms',
Endpoint=number # <-- number who'll receive an SMS message.
)
# Publish a message.
client.publish(Message="Good news everyone!", TopicArn=topic_arn)