2015-10-16 65 views

回答

2

您可以使用AWS的SNS发送短信。您可以通过发送电子邮件将SES端点连接到SNS来完成此操作。

目前,只有美国的电话号码可以接受短信。

在多个协议兑现http://aws.amazon.com/sns/

+0

你能提供一个源发送短信群发美国只限制? – michaelbahr

+1

当然 - 看看http://aws.amazon.com/sns/下面的**交付多个协议**标题。 – Richard

0

是美国可以使用Amazon SNS(简单通知服务)

import java.util.HashMap; 
import java.util.Map; 

import com.amazonaws.services.sns.AmazonSNSClient; 
import com.amazonaws.services.sns.model.CreateTopicRequest; 
import com.amazonaws.services.sns.model.CreateTopicResult; 
import com.amazonaws.services.sns.model.MessageAttributeValue; 
import com.amazonaws.services.sns.model.PublishRequest; 
import com.amazonaws.services.sns.model.PublishResult; 
import com.amazonaws.services.sns.model.SubscribeRequest; 
import com.amazonaws.services.sns.model.SubscribeResult; 

public class BulkSMSSender { 
    static String topicArn; 
    static Map<String, MessageAttributeValue> smsAttributes; 
    static AmazonSNSClient snsClient = AwsSNSCredentials.getSnsClient(); 

    public static void main(String[] args) { 
     // AmazonSNSClient snsClient = new AmazonSNSClient(); 

     if (topicArn == null) { 
      topicArn = createSNSTopic(snsClient); 

     } 
     smsAttributes = initializeMessage(); 
     String message = "*********"; 
     String phoneNumber[] = { "+91**********" }; 
     subscribeToTopic(snsClient, topicArn, "sms", phoneNumber[0]); 

     sendSMSMessageToTopic(snsClient, topicArn, message, smsAttributes); 
    } 

    public static String createSNSTopic(AmazonSNSClient snsClient) { 
     CreateTopicRequest createTopic = new CreateTopicRequest("Topic"); 
     CreateTopicResult result = snsClient.createTopic(createTopic); 
     System.out.println("Create topic request: " + snsClient.getCachedResponseMetadata(createTopic)); 
     return result.getTopicArn(); 
    } 

    public static void subscribeToTopic(AmazonSNSClient snsClient, String topicArn, String protocol, String endpoint) { 
     SubscribeRequest subscribe = new SubscribeRequest(topicArn, protocol, endpoint); 
     SubscribeResult subscribeResult = snsClient.subscribe(subscribe); 
     System.out.println("Subscribe request: " + snsClient.getCachedResponseMetadata(subscribe)); 
    } 

    public static void sendSMSMessageToTopic(AmazonSNSClient snsClient, String topicArn, String message, 
      Map<String, MessageAttributeValue> smsAttributes) { 
     PublishResult result = snsClient.publish(
       new PublishRequest().withTopicArn(topicArn).withMessage(message).withMessageAttributes(smsAttributes)); 
     System.out.println(result); 
    } 

    private static Map<String, MessageAttributeValue> initializeMessage() { 
     if (smsAttributes == null) { 
      smsAttributes = new HashMap<String, MessageAttributeValue>(); 
      smsAttributes.put("AWS.SNS.SMS.SenderID", 
        new MessageAttributeValue().withStringValue("MSGGGG").withDataType("String")); 
      smsAttributes.put("AWS.SNS.SMS.MaxPrice", 
        new MessageAttributeValue().withStringValue("0.05").withDataType("Number")); 
      smsAttributes.put("AWS.SNS.SMS.SMSType", 
        new MessageAttributeValue().withStringValue("Transactional").withDataType("String")); 
     } 
     return smsAttributes; 

    } 

} 

的AWS证书可以在这里把

import com.amazonaws.auth.BasicAWSCredentials; 
import com.amazonaws.regions.Regions; 
import com.amazonaws.services.sns.AmazonSNSClient; 

import common.PropertiesFileReader; 
import constants.StringConstants; 

public class AwsSNSCredentials { 
    private static final String CLIENT_SMS_TOKEN = "AWS Secret Id"; 
    private static final String CLIENT_SMS_SECRET = "AWS Secret Key"; 
    private static final BasicAWSCredentials CREDENTIALS = new BasicAWSCredentials(CLIENT_SMS_TOKEN, CLIENT_SMS_SECRET); 

    private static AmazonSNSClient snsClient = null; 
    public static AmazonSNSClient getSnsClient() { 
     if(null == snsClient) { 
     snsClient = new AmazonSNSClient(CREDENTIALS) 
       .withRegion(Regions.US_WEST_2); 
     } 
     return snsClient; 
    } 
}