Template based aliyun sms sender service.
Name | Version | Downloads |
---|---|---|
EasySms.Abstractions | ||
EasySms.Aliyun |
We are support Aliyun SMS service currently.
Configure follow settings in appsettins.json
{
"AliyunSms": {
"ApiKey": "{Your api key}",
"ApiSecret": "<Your api secret>",
"SignName": "<Your signed>",
"Templates": {
"<TemplateName>": "<TemplateCode in aliyun>",
"Login": "SMS_138011122"
}
}
}
Add service in Startup.cs
services.AddAliyunSms();
Then you can use it in your code like this:
class YourService
{
private readonly ISmsSender _sender;
public YourService(ISmsSender sender)
{
_sender = sender;
}
public async Task SendSmsAsync()
{
var template = new SmsTemplate("SMS_138011122", new {code = "123456"});
var phoneNumber = "13800138000";
await _sender.SendAsync(phoneNumber, template);
}
}
This example will use template SMS_138011122
send verification code 123456
to
phone number '13512345678' by aliyun sms service
The templateName
must declared to Templates in appsettings.json,
service will get the code SMS_138011122
by template name Login
and send
code 123456
to aliyun.
The parameter
will serialize using Json.NET to a string,
then pass to aliyun. The struct of parameter MUST equals with your template SMS_138011122
Leave a comment on GitHub if you have any questions or suggestions.
Turn on the star if you like this project.
This project is licensed under the MIT License