发送短信
更新时间:2023-09-06
通过以下代码可以发送SMS消息:
private static void Main(string[] args)
{
string accessKeyId = "xxx";
string secretAccessKey = "xxx";
BceClientConfiguration config = new BceClientConfiguration();
config.Credentials = new DefaultBceCredentials(accessKeyId, secretAccessKey);
config.Endpoint = "http://smsv3.bj.baidubce.com";
// 设置HTTP最大连接数为10
config.ConnectionLimit = 10;
// 设置TCP连接超时为5000毫秒
config.TimeoutInMillis = 5000;
// 设置读写数据超时的时间为50000毫秒
config.ReadWriteTimeoutInMillis = 50000;
SmsClient client = new SmsClient(config);
SendMessageRequest request = new SendMessageRequest();
request.Mobile = "18800000000";
request.SignatureId = "sms-sign-xxx";
request.Template = "sms-tmpl-xxx";
request.ContentVar = new Dictionary<string, string>
{
{
"content", "测试"
}
}
SendMessageResponse response = client.SendMessage(request);
Console.Write(response.BceRequestId);
}