Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon短信,用于从c#sdk发送单个数字,无需创建主题_C#_Sms_Amazon Sns - Fatal编程技术网

Amazon短信,用于从c#sdk发送单个数字,无需创建主题

Amazon短信,用于从c#sdk发送单个数字,无需创建主题,c#,sms,amazon-sns,C#,Sms,Amazon Sns,根据文档,要发送单个号码的短信,我们不需要创建SNS主题。 显然,他们给出了一个示例代码,显示我们可以为发布请求方法设置电话号码 根据java文档,我可以清楚地看到该方法 但是,我们如何在c#中实现相同的功能呢?我找不到任何不创建SNS主题就发送短信的方法 有人能告诉我如何在不从C#SDK创建SNS主题的情况下发送短信吗?请参见 具有PhoneNumber属性,用于在发送直接短信时设置号码。我相信您会在这里找到答案: 基本上是这样说和引用的:“…PhoneNumber属性是在AWSSDK.S

根据文档,要发送单个号码的短信,我们不需要创建SNS主题。 显然,他们给出了一个示例代码,显示我们可以为发布请求方法设置电话号码

根据java文档,我可以清楚地看到该方法

但是,我们如何在c#中实现相同的功能呢?我找不到任何不创建SNS主题就发送短信的方法

有人能告诉我如何在不从C#SDK创建SNS主题的情况下发送短信吗?

请参见


具有
PhoneNumber
属性,用于在发送直接短信时设置号码。

我相信您会在这里找到答案:

基本上是这样说和引用的:“…PhoneNumber属性是在AWSSDK.SimpleNotificationService的3.1.1.0版本中添加的…”

由于请求中缺少了PhoneNumber属性,因此我没有给出示例代码,其余部分应该与Java示例类似:D.

我希望这有助于:

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 = "Promotional";

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

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 = vm.Message;
publishRequest.MessageAttributes = smsAttributes;
publishRequest.PhoneNumber = vm.PhoneNumber;
AmazonSimpleNotificationServiceClient client = new AmazonSimpleNotificationServiceClient(vm.AccessKey, vm.SecretKey, config);
AmazonSNSResponse resp = new AmazonSNSResponse();
await client.PublishAsync(publishRequest);

AmazonSNSResponse response = new AmazonSNSResponse();
response.Status = HttpStatusCode.OK.ToString();
response.Message = "Success";
return response;    
var smsAttributes=new Dictionary();
MessageAttributeValue senderID=新MessageAttributeValue();
senderID.DataType=“字符串”;
senderID.StringValue=“mySenderId”;
MessageAttributeValue sMSType=新MessageAttributeValue();
sMSType.DataType=“字符串”;
sMSType.StringValue=“促销”;
////MessageAttributeValue maxPrice=新MessageAttributeValue();
////maxPrice.DataType=“编号”;
////maxPrice.StringValue=“0.1”;
CancellationTokenSource=新的CancellationTokenSource();
CancellationToken=source.token;
添加(“AWS.SNS.SMS.SenderID”,SenderID);
添加(“AWS.SNS.SMS.SMSType”,SMSType);
////添加(“AWS.SNS.SMS.MaxPrice”,MaxPrice);
PublishRequest PublishRequest=新PublishRequest();
publishRequest.Message=vm.Message;
publishRequest.MessageAttributes=smsAttributes;
publishRequest.PhoneNumber=vm.PhoneNumber;
AmazonSimpleNotificationServiceClient=新的AmazonSimpleNotificationServiceClient(vm.AccessKey,vm.SecretKey,config);
amazonsresponse resp=新的amazonsresponse();
等待client.PublishAsync(publishRequest);
amazonsresponse response=新的amazonsresponse();
response.Status=HttpStatusCode.OK.ToString();
response.Message=“Success”;
返回响应;

示例代码将有所帮助。我用过同一个图书馆。但无法找到设置电话号码的方法@MichaelLink不起作用。这是说找不到指定的线程[0]。我自己再次测试了该链接,并且正在工作。您的位置可能不可用,我用他们在论坛中的评论更新了答案。我也遇到过同样的情况,升级包版本后,我能够看到属性。