使用Amazon AWS SNS 发送 SMS 消息 .net

1.浏览aws 开发人员指南

https://docs.aws.amazon.com/zh_cn/sns/latest/dg/sms_publish-to-phone.html

2.安装 aws sms net api : AWSSDK.SimpleNotificationService

3.调用 AmazonSimpleNotificationServiceClient 发送SMS

string defaultSenderID="AppName";
string message = "[AppName] Enter this verification code 000000 in your app now.";//消息
string phoneNumber = "+8618372712159";     //手机号
string defaultSMSType = "Promotional";     //Promotional – 不重要的消息|Transactional – 为客户事务处理提供支持的重要消息
SMS_Entity mode = new SMS_Entity() { Contents = message, MobileNumber = phoneNumber };
try
{
    AmazonSimpleNotificationServiceClient snsClient = new AmazonSimpleNotificationServiceClient(awsAccessKeyId, awsSecretAccessKey, RegionEndpoint.APSoutheast1);
    PublishRequest publishReq = new PublishRequest();
    publishReq.Message = message;
    publishReq.PhoneNumber = phoneNumber;
    publishReq.MessageAttributes = new Dictionary<string, MessageAttributeValue>();
    publishReq.MessageAttributes.Add("AWS.SNS.SMS.SenderID", new MessageAttributeValue() { DataType = "String", StringValue = defaultSenderID });
    publishReq.MessageAttributes.Add("AWS.SNS.SMS.SMSType", new MessageAttributeValue() { DataType = "String", StringValue = defaultSMSType });
    PublishResponse response = snsClient.Publish(publishReq);
    mode.Response = JsonConvert.SerializeObject(response);
    mode.SendStatus = response.HttpStatusCode.ToString();
    if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
        mode.Result = true;
    else
        mode.Result = false;
}
catch (Exception ex)
{
    mode.SendStatus = "error:" + ex.Message;
    mode.Result = false;
}

注意:awsAccessKeyId,awsSecretAccessKey,RegionEndpoint,需要登陆aws的控制台查看

转载于:https://www.cnblogs.com/heyangyi/p/9528265.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值