c#---发送短信

public class SendMessage
    {
        // The AWS Region that you want to use to send the message. For a list of
        // AWS Regions where the Amazon Pinpoint API is available, see
        // https://docs.aws.amazon.com/pinpoint/latest/apireference/
        private static readonly string region = "ap-xxxx-1";

        // The phone number or short code to send the message from. The phone number
        // or short code that you specify has to be associated with your Amazon Pinpoint
        // account. For best results, specify long codes in E.164 format.
        private static readonly string originationNumber = "+xxxx";

        // The recipient's phone number.  For best results, you should specify the
        // phone number in E.164 format.
        //private static readonly string destinationNumber = "+xxxx";

        // The content of the SMS message.
        //private static readonly string message = "This message was sent through Amazon Pinpoint"
                //+ "using the AWS SDK for .NET. Reply STOP to opt out.";

        // The Pinpoint project/application ID to use when you send this message.
        // Make sure that the SMS channel is enabled for the project or application
        // that you choose.
        private static readonly string appId = "xxxx";

        // The type of SMS message that you want to send. If you plan to send
        // time-sensitive content, specify TRANSACTIONAL. If you plan to send
        // marketing-related content, specify PROMOTIONAL.
        private static readonly string messageType = "xxxx";

        // The registered keyword associated with the originating short code.
        private static readonly string registeredKeyword = "xxxx";

        // The sender ID to use when sending the message. Support for sender ID
        // varies by country or region. For more information, see
        // https://docs.aws.amazon.com/pinpoint/latest/userguide/channels-sms-countries.html
        private static readonly string senderId = "xxxx";

        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="destinationNumber">电话号码</param>
        /// <param name="message">内容</param>
        /// <returns></returns>
        public bool SendMessageMain(string destinationNumber,string message)
        {
            using (AmazonPinpointClient client = new AmazonPinpointClient("AKIA5KTRHBUKIFYKQXEE","SpJvwY6VwRKRt1+9v9wZN+uAEsHMOGXdct6eskkW", RegionEndpoint.GetBySystemName(region)))
            {
                SendMessagesRequest sendRequest = new SendMessagesRequest
                {
                    ApplicationId = appId,
                    MessageRequest = new MessageRequest
                    {
                        Addresses = new Dictionary<string, AddressConfiguration>
                        {
                            {
                                destinationNumber,
                                new AddressConfiguration
                                {
                                    ChannelType = "SMS"
                                }
                            }
                        },
                        MessageConfiguration = new DirectMessageConfiguration
                        {
                            SMSMessage = new SMSMessage
                            {
                                Body = message,
                                MessageType = messageType
                                //OriginationNumber = originationNumber,
                                //SenderId = senderId,
                                //Keyword = registeredKeyword
                            }
                        }
                    }
                };
                try
                {
                    SendMessagesResponse response = client.SendMessagesAsync(sendRequest).Result;
                    var StatusCode = response.MessageResponse.Result.Values.ToArray()[0].StatusCode;
                    if (StatusCode ==  200)
                    {
                        return true;
                    }
                    return false;

                }
                catch (Exception ex)
                {
                    return false;

                }
            }
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值