发布:2023/12/7 15:49:03作者:大数据 来源:大数据 浏览次数:521
https://help.aliyun.com/document_detail/112145.html
本文为您介绍短信服务.NET SDK的使用方法及示例。
您可以通过NuGet程序包管理器来安装,在解决方案资源管理器面板中,右键单击您的项目选择管理NuGet程序包菜单,在打开的NuGet管理面板中单击浏览选项卡输入aliyun-net-sdk-core,选择并单击安装即可。
1 |
dotnet add package aliyun-net-sdk-core |
您可以使用git clone
或其它手段下载aliyun-net-sdk-core并自行添加解决方案。下载安装包,请参见SDK 核心库。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
using System; using Aliyun.Acs.Core; using Aliyun.Acs.Core.Profile; using Aliyun.Acs.Core.Exceptions; using Aliyun.Acs.Core.Http; namespace CommonRequestDemo { class Program { static void Main(string[] args) { IClientProfile profile = DefaultProfile.GetProfile("ap-northeast-1", "<accessKeyId>", "<accessSecret>"); DefaultAcsClient client = new DefaultAcsClient(profile); CommonRequest request = new CommonRequest(); request.Method = MethodType.POST; request.Domain = "dysmsapi.aliyuncs.com"; request.Version = "2017-05-25"; request.Action = "SendSms"; // request.Protocol = ProtocolType.HTTP; request.AddQueryParameters("PhoneNumbers", "1503871****"); //接收短信的手机号码 request.AddQueryParameters("SignName", "阿里云测试专用"); //短信签名名称 request.AddQueryParameters("TemplateCode", "SMS_20933****"); //短信模板CODE request.AddQueryParameters("TemplateParam", "{\"code\":\"1111\"}"); //短信模板变量对应的实际值,JSON格式 try { CommonResponse response = client.GetCommonResponse(request); Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content)); } catch (ServerException e) { Console.WriteLine(e); } catch (ClientException e) { Console.WriteLine(e); } } } } |
1 |
{ "RequestId": "614048FB-0619-4439-A1D5-AA8B218A****", "Message": "OK", "BizId": "386715418801811068^0", "Code": "OK"} |
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4