亚马逊AWS SNS发送短信无法发送短信,返回状态为" WaitingForActivation"

时间:2017-06-20 03:18:56

标签: c# amazon-web-services amazon-sns asp.net-core-1.0

我是AWS新手并尝试设置我的系统,以便在预订时向最终用户发送短信作为确认消息。

我到目前为止做到了:

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

任何人都可以帮忙。

1 个答案:

答案 0 :(得分:3)

我通过以下更改重新解决了这个问题, 将SenderID更改为AWS.SNS.SMS.SenderID 和sMSType到AWS.SNS.SMS.SMSType

总的来说,整体流程就像

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

  2. 使用以下简单方法发送单个短信。

  3. 下面是使用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);