本文为您介绍了C#调用SendMessageToGlobe接口发送短信。
请求参数
名称 | 类型 | 是否必选 | 示例值 | 描述 |
---|---|---|---|---|
To | String | 是 | 45***0121 | 每次只支持一个号码调用发送,号码格式为:Country Code+ Phone Number。 |
From | String | 否 | abc1**** | 支持SenderId的发送,只允许支持数字+字母,含有字母数字的最长11位,纯数字支持15位。 |
Message | String | 是 | 你好 | 短信的完整内容。 |
返回数据
名称 | 类型 | 示例值 | 描述 |
---|---|---|---|
MessageId | String | 10080303003003 | 发送回执ID,可根据该ID查询具体的发送状态。 |
To | String | 13900001234 | 发送号码。 |
From | String | Alicloud | 目前支持SenderId,返回传入的SenderId。 |
ResponseCode | String | OK | 状态码-返回OK代表请求成功,其他错误码详见错误码列表。 |
ResponseDescription | String | The SMS Send Request was accepted | 状态码的描述。 |
Segments | String | 1 | 短信的计费条数。 |
NumberDetail | String | 号码的详细属性。 | |
└Country | String | Hongkong, China | 号码所属国家。 |
└Region | String | HongKong | Number Region。 |
└Carrier | String | CMI | 号码所属的运营商网络。 |
引入阿里云核心包
- 方法1:通过Nuget安装:单击查看安装说明。
- 方法2:core-sdk下载地址:C# API SDK。
调用示例
注意事项如下:
- 初始化IClientProfile时,第一个参数(RegionId)必须为ap-southeast-1,请勿修改。
- Domain必须为dysmsapi.ap-southeast-1.aliyuncs.com,请勿修改。
- Version必须为2018-05-01,请勿修改。
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("ap-southeast-1", "<AccessKeyId>", "<AccessSecret>");
DefaultAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest
{
Method = MethodType.POST,
Domain = "dysmsapi.ap-southeast-1.aliyuncs.com",
Version = "2018-05-01",
Action = "SendMessageToGlobe"
};
// request.Protocol = ProtocolType.HTTPS;
request.AddQueryParameters("To", "6212345678901");
request.AddQueryParameters("PhoneNumber", "PhoneNumber");
// request.AddQueryParameters("From", "1234567890");
request.AddQueryParameters("Message", "have a test.");
try
{
CommonResponse response = client.GetCommonResponse(request);
Console.WriteLine(response.Data);
}
catch (ServerException e)
{
Console.WriteLine(e);
}
catch (ClientException e)
{
Console.WriteLine(e);
}
}
}
}