l1044635791 / YunPian

云片网短信服务.NetCore实现版本

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

YunPian.NetCore

NuGet Build Status

基于云片网短信服务SDK的.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 及以上.

参考文档

About

云片网短信服务.NetCore实现版本


Languages

Language:C# 100.0%