此项目为.net core 项目,可跨平台使用,
短信验证码SDK 使用步骤如下:
1. 去 阿里云 或者 SendCloud 申请开通短信服务后,会得到appId和appKey信息
2. 修改 appsettings.json 中的配置信息为第一步申请的appId和appKey
3. 运行程序 即可发送短信(成功之后 会看到如下图)
using BullSofts.Common.SMS;
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
namespace SmsDemo
{
class Program
{
static void Main(string[] args)
{
Startup.Init();//初始化服务
var sms = Startup.ServiceProvider.GetService<ISMS>();
#region sendcloud发送短信
var model = new SMSModel()
{
Phone = "13383236116",
Content = "您的注册验证码是%code%,请不要把验证码泄漏给其他人,如非本人请勿操作。",
TemplateId = "12759",//请将此次换成您的模板id
Vars = new Dictionary<string, string>() { { "code", "1998" } }
};
var isSuccess = sms.SendMsg(model);
#endregion
#region 阿里云发送短信
//var model = new SMSModel()
//{
// Phone = "13383236116",
// Content = "您的验证码为:${code},验证码 5 分钟有效,请勿泄露于他人。",
// TemplateId = "SMS_123667922",//请将此次换成您的模板id
// Vars = new Dictionary<string, string>() { { "code", "1966" } },
//};
//var isSuccess = sms.SendMsg(model);
#endregion
Console.WriteLine("短信发送结果:" isSuccess);
Console.ReadLine();
}
}
}
资源文件列表
BullSofts.Common.SMS/BullSofts.Common.SMS.csproj , 144
BullSofts.Common.SMS/ISMS.cs , 459
BullSofts.Common.SMS/Impl/AliyunSMS.cs , 7406
BullSofts.Common.SMS/Impl/SendCloudSMS.cs , 3762
BullSofts.Common.SMS/SMSConfig.cs , 1032
BullSofts.Common.SMS/SMSModel.cs , 352
BullSofts.Common.SMS/bin/Debug/netcoreapp2.0/BullSofts.Common.SMS.deps.json , 492
BullSofts.Common.SMS/bin/Debug/netcoreapp2.0/BullSofts.Common.SMS.dll , 15872
BullSofts.Common.SMS/bin/Debug/netcoreapp2.0/BullSofts.Common.SMS.pdb , 3996
BullSofts.Common.SMS/obj/BullSofts.Common.SMS.csproj.nuget.cache , 149
BullSofts.Common.SMS/obj/BullSofts.Common.SMS.csproj.nuget.g.props , 1592
BullSofts.Common.SMS/obj/BullSofts.Common.SMS.csproj.nuget.g.targets , 981
BullSofts.Common.SMS/obj/Debug/netcoreapp2.0/BullSofts.Common.SMS.AssemblyInfo.cs , 1043
BullSofts.Common.SMS/obj/Debug/netcoreapp2.0/BullSofts.Common.SMS.AssemblyInfoInputs.cache , 42
BullSofts.Common.SMS/obj/Debug/netcoreapp2.0/BullSofts.Common.SMS.csproj.CoreCompileInputs.cache , 42
BullSofts.Common.SMS/obj/Debug/netcoreapp2.0/BullSofts.Common.SMS.csproj.FileListAbsolute.txt , 2133
BullSofts.Common.SMS/obj/Debug/netcoreapp2.0/BullSofts.Common.SMS.csprojResolveAssemblyReference.cache , 480497
BullSofts.Common.SMS/obj/Debug/netcoreapp2.0/BullSofts.Common.SMS.dll , 15872
BullSofts.Common.SMS/obj/Debug/netcoreapp2.0/BullSofts.Common.SMS.pdb , 3996
BullSofts.Common.SMS/obj/project.assets.json , 39439
SmsDemo/Program.cs , 1502
SmsDemo/SmsDemo.csproj , 1070
SmsDemo/Startup.cs , 2139
SmsDemo/appsettings.json , 463
SmsDemo/bin/Debug/netcoreapp2.0/BullSofts.Common.SMS.dll , 15872
SmsDemo/bin/Debug/netcoreapp2.0/BullSofts.Common.SMS.pdb , 3996
SmsDemo/bin/Debug/netcoreapp2.0/SmsDemo.deps.json , 40755
SmsDemo/bin/Debug/netcoreapp2.0/SmsDemo.dll , 8192
SmsDemo/bin/Debug/netcoreapp2.0/SmsDemo.pdb , 1216
SmsDemo/bin/Debug/netcoreapp2.0/SmsDemo.runtimeconfig.dev.json , 252
SmsDemo/bin/Debug/netcoreapp2.0/SmsDemo.runtimeconfig.json , 154
SmsDemo/bin/Debug/netcoreapp2.0/appsettings.json , 463
SmsDemo/obj/Debug/netcoreapp2.0/SmsDemo.AssemblyInfo.cs , 1004
SmsDemo/obj/Debug/netcoreapp2.0/SmsDemo.AssemblyInfoInputs.cache , 42
SmsDemo/obj/Debug/netcoreapp2.0/SmsDemo.csproj.CopyComplete , 0
SmsDemo/obj/Debug/netcoreapp2.0/SmsDemo.csproj.CoreCompileInputs.cache , 42
SmsDemo/obj/Debug/netcoreapp2.0/SmsDemo.csproj.FileListAbsolute.txt , 1320
SmsDemo/obj/Debug/netcoreapp2.0/SmsDemo.csprojResolveAssemblyReference.cache , 554249
SmsDemo/obj/Debug/netcoreapp2.0/SmsDemo.dll , 8192
SmsDemo/obj/Debug/netcoreapp2.0/SmsDemo.pdb , 1216
SmsDemo/obj/SmsDemo.csproj.nuget.cache , 149
SmsDemo/obj/SmsDemo.csproj.nuget.g.props , 1579
SmsDemo/obj/SmsDemo.csproj.nuget.g.targets , 981
SmsDemo/obj/project.assets.json , 197283
SmsDemo.sln , 1631
