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;
}
}
}
}
c#---发送短信
于 2023-06-27 10:26:07 首次发布