A recent project, using the SMS service Ali cloud, due to time, there is no sign to send the manual to construct, but sent directly use Ali cloud SDK, so here is considered to be a note, perhaps later also used to get
First of all, we need to install Ali cloud SDK, recommended nuget install, search aliyun-net-sdk-core
, you can directly follow
After installation is complete, you can use the following code:
using Aliyun.Acs.Core; using Aliyun.Acs.Core.Http; using Aliyun.Acs.Core.Profile; using System; namespace DemoConsole2 { class Program { static void Main(string[] args) { IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", "<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", "185XXXXXXXX"); request.AddQueryParameters("SignName", "签名"); request.AddQueryParameters("TemplateCode", "SMS_176375688"); request.AddQueryParameters("TemplateParam", "{\"code\":\"074281\"}"); request.AddQueryParameters("OutId", ""); try { CommonResponse response = client.GetCommonResponse(request); var content = System.Text.Encoding.Default.GetString(response.HttpResponse.Content); Console.WriteLine(content); } catch (Exception e) { Console.WriteLine(e); } } } }
Note which parameter to use AddQueryParameters method, because the parameters are placed QueryString carried past, specifically which parameters can be used in reference to Ali cloud development documents: https://help.aliyun.com/document_detail/101414.html?spm = a2c4g.11186623.6.616.74665f30I95HSl
AccessKeyId and accessSecret which can be viewed on Ali cloud, as shown below
Code signing and templates need to apply and review, as shown below