2017-06-20 425 views
2

我是AWS的新手,并试图设置我的系统发送短信到最终用户的邮件预订作为确认消息。亚马逊AWS SNS发送短信无法发送短信,返回状态是“WaitingForActivation”

我做了以下至今:

AmazonSimpleNotificationServiceClient smsClient = new AmazonSimpleNotificationServiceClient(key, secreteKey, token, Amazon.RegionEndpoint.APSoutheast2); 

      var smsAttributes = new Dictionary<string, MessageAttributeValue>(); 

      MessageAttributeValue senderID = new MessageAttributeValue(); 
      senderID.DataType = "String"; 
      senderID.StringValue = "my-sender-id"; 

      MessageAttributeValue sMSType = new MessageAttributeValue(); 
      senderID.DataType = "String"; 
      senderID.StringValue = "Transactional"; 

      CancellationTokenSource source = new CancellationTokenSource(); 
      CancellationToken token = source.Token; 


      smsAttributes.Add("SenderID", senderID); 
      smsAttributes.Add("SMSType", sMSType); 

      PublishRequest publishRequest = new PublishRequest(); 
      publishRequest.Message = "This is 2nd sample message"; 
      publishRequest.MessageAttributes = smsAttributes; 
      publishRequest.PhoneNumber = "my number with + and country code"; 

      Task<PublishResponse> result = smsClient.PublishAsync(publishRequest, token); 

但是我没有收到任何短信。

正如我调试代码,我看到下面的消息: enter image description here

谁能帮助请。

回答

2

我resoved下面的变化这一问题, 改变SenderID到AWS.SNS.SMS.SenderID 和sMSType到AWS.SNS.SMS.SMSType

因此,在总,整个流程就像是

  1. 下载金块的AWSSDK简单的通知v3.3.5.12

  2. 使用下面简单的方法来发送一条SMS。

下面

是工作片段与C#.NET核心1.1

AmazonSimpleNotificationServiceClient smsClient = new AmazonSimpleNotificationServiceClient(my_access_key, my_secret_key, Amazon.RegionEndpoint.APSoutheast2); 


       var smsAttributes = new Dictionary<string, MessageAttributeValue>(); 

       MessageAttributeValue senderID = new MessageAttributeValue(); 
       senderID.DataType = "String"; 
       senderID.StringValue = "mySenderId"; 

       MessageAttributeValue sMSType = new MessageAttributeValue(); 
       sMSType.DataType = "String"; 
       sMSType.StringValue = "Transactional"; 

       MessageAttributeValue maxPrice = new MessageAttributeValue(); 
       maxPrice.DataType = "Number"; 
       maxPrice.StringValue = "0.5"; 

       CancellationTokenSource source = new CancellationTokenSource(); 
       CancellationToken token = source.Token; 


       smsAttributes.Add("AWS.SNS.SMS.SenderID", senderID); 
       smsAttributes.Add("AWS.SNS.SMS.SMSType", sMSType); 
       smsAttributes.Add("AWS.SNS.SMS.MaxPrice", maxPrice); 

       PublishRequest publishRequest = new PublishRequest(); 
       publishRequest.Message = "This is 2nd sample message"; 
       publishRequest.MessageAttributes = smsAttributes; 
       publishRequest.PhoneNumber = "received phone no with + and country code"; 

       Task<PublishResponse> result = smsClient.PublishAsync(publishRequest, token); 
+0

如何检查日志,这怎么我想你的代码,构建是成功的,但它不发送短信,也没有给出任何错误 –

+1

你可以通过调试来检查任务结果中的状态,也可以在AWS控制台中为SNS报告定义存储桶并检查报告。如果您第一次尝试此操作,AWS会将该帐户的SMS支出限制限制为1美元,因此您可能不得不提出增加短信限额的请求。只是为了检查您的配额是否用尽尝试从SNS控制台发送短信。 –