基于云片网短信服务SDK的.NetCore版本实现
-
NuGet获取YunPian.NetCore
-
示例
appsettings.json
{
"YunPianApiKey":"你的云片ApiKey",
}
Startup.cs
public void ConfigureServices (IServiceCollection services) {
//添加 YunPian 服务
services.AddYunPianService (options =>
options.ApiKey = Configuration["YunPianApiKey"];
);
}
AccountController.cs
public readonly ISmsService _smsService;
// 通过构造函数依赖注入的方式获取服务实例
public AccountController (ISmsService smsService) {
_smsService = smsService;
}
[HttpGet ("send-verifycode/{mobile}")]
public async Task<IActionResult> SendVerifyCode ([FromRoute] string mobile) {
var message = $"【云片网】您的验证码是123456。如非本人操作,请忽略本短信";
// 发送单条短信
var result = await _smsService.SingleSendAsync (message, mobile);
return result;
}
- YunPian 云片源码
- Services 云片服务实现
- Models 模型对象定义
- Handlers 响应结果处理方法
- YunPianExtensions IServiceCollection扩展方法
- YunPianOptions 客户端配置
- YunPianFields 云片网字段映射
- 需要
.NET Core 3.0
及以上.