我是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);
但是我没有收到任何短信。
任何人都可以帮忙。
答案 0 :(得分:3)
我通过以下更改重新解决了这个问题, 将SenderID更改为AWS.SNS.SMS.SenderID 和sMSType到AWS.SNS.SMS.SMSType
总的来说,整体流程就像
为简单通知v3.3.5.12下载AWSSDK的金块
使用以下简单方法发送单个短信。
下面是使用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);