本文为您介绍C#调用SendMessageToGlobe发送短信到国际地区的程序样例。

注意事项

参考这个示例您需要注意以下几点:
  • 初始化IClientProfile时,第一个参数(RegionId)必须为cn-hangzhou,请勿修改。
  • Domain必须为dysmsapi.aliyuncs.com,请勿修改。
  • Version必须为2017-05-25,请勿修改。

编写样例程序

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Http;
namespace CommonRpc
{
class Program
{
static void Main(string[] args)
{
IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", "<AccessKeyId>", "<AccessSecret>");
DefaultAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest
{
Method = MethodType.POST,
Domain = "dysmsapi.aliyuncs.com",
Version = "2017-05-25",
Action = "SendMessageToGlobe"
};
// request.Protocol = ProtocolType.HTTPS;
request.AddQueryParameters("To", "62123****8901");
request.AddQueryParameters("PhoneNumber", "156****0987");
// request.AddQueryParameters("From", "1234567890");
request.AddQueryParameters("Message", "have a test.");
// request.AddQueryParameters("Type", "OTP");
try
{
CommonResponse response = client.GetCommonResponse(request);
Console.WriteLine(response.Data);
}
catch (ServerException e)
{
Console.WriteLine(e);
}
catch (ClientException e)
{
Console.WriteLine(e);
}
}
}
}