.net调用阿里云的短信接口
电脑版发表于:2020/6/29 11:46
先要去开通短信服务

然后去添加签名和模板
发送短信的时候需要

然后就是需要充值了
主要有两种计费方式,一种是包年,比如下面这种2年5000条180,。哈哈哈其实就是一件T恤或者一个皮肤的价格就可以玩2年了还是不算贵

或者你可以选择按需付费就是发送多少条就花多少钱,在前期短信消耗很少的时候可以用这种方式。
这种方式不需要购买,保证你的账户上面有钱即可。

比如我账号这里有10块钱,哈哈哈
为什么只有10块钱....
然后这些都搞定了就可以发送短信了
在快速学习里边有个api Demo

里边有各种语言的demo安装这个写就行了还是很简单

贴一下c#调用的代码:
using System;
using System.Collections.Generic;
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("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", "需要发送的电话号码");
request.AddQueryParameters("SignName", "TNBLOG");
request.AddQueryParameters("TemplateCode", "申请的模块code");
request.AddQueryParameters("TemplateParam", "{\"code\":\"短信内容\"}");
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);
}
}
}
}其中accessKeyId和accessSecret需要自己去申请一下

需要的sdk版本下载地址:https://develop.aliyun.com/tools/sdk?spm=a2c4g.11186623.2.15.617e3854cp97wA#/dotnet

