C#阿里云发送短信
Windows窗体应用新建项目——>Visual C# ——>Windows窗体应用拖一个Button和RichTextBox,用来点击发送和显示http 返回的数据添加引用引用——>管理NuGet程序包——>搜索aliyun-net-sdk-core——>安装引用——>管理NuGet程序包——>搜索Newtonsoft.Json——>安...
·
Windows窗体应用
新建项目——>Visual C# ——>Windows窗体应用
拖一个Button和RichTextBox,用来点击发送和显示http 返回的数据
添加引用
引用——>管理NuGet程序包——>搜索aliyun-net-sdk-core——>安装
引用——>管理NuGet程序包——>搜索Newtonsoft.Json——>安装
代码
很简单
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using Newtonsoft.Json;
using System;
using System.Windows.Forms;
namespace 短信发送
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e1)
{
IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", "LTAI4FwHgQKtSdTnv3rf9bBo", "SaxyW25aCuqVIv2DCPjrf4dHByIvD3");
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", "18150886330");
request.AddQueryParameters("SignName", "中交华安");
request.AddQueryParameters("TemplateCode", "SMS_177552111");
request.AddQueryParameters("TemplateParam", JsonConvert.SerializeObject(new { vehicleID = "闽B666", Time = "11月22日 17点22分", location = "厦门软件园二期西门" }));
try
{
CommonResponse response = client.GetCommonResponse(request);
Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
richTextBox1.Text = ("返回:"+ System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
}
catch (ServerException e)
{
Console.WriteLine(e);
}
catch (ClientException e)
{
Console.WriteLine(e);
}
}
}
}
运行截图


魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)