优化
This commit is contained in:
21
src/WMS.Web.Domain/Entitys/SendLog.cs
Normal file
21
src/WMS.Web.Domain/Entitys/SendLog.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
using WMS.Web.Core;
|
||||
|
||||
namespace WMS.Web.Domain.Entitys
|
||||
{
|
||||
/// <summary>
|
||||
/// 短信和邮箱发送日志表
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[Table("t_wms_send_log")]
|
||||
public class SendLog : EntityBase
|
||||
{
|
||||
/// <summary>
|
||||
/// ID
|
||||
/// </summary>
|
||||
public override int Id { get; set; }
|
||||
}
|
||||
}
|
||||
13
src/WMS.Web.Domain/IService/Public/IAliyunSmsService.cs
Normal file
13
src/WMS.Web.Domain/IService/Public/IAliyunSmsService.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Domain.IService
|
||||
{
|
||||
/// <summary>
|
||||
/// 阿里云短息服务
|
||||
/// </summary>
|
||||
public interface IAliyunSmsService
|
||||
{
|
||||
}
|
||||
}
|
||||
56
src/WMS.Web.Domain/Services/Public/AliyunSmsService.cs
Normal file
56
src/WMS.Web.Domain/Services/Public/AliyunSmsService.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using WMS.Web.Domain.IService;
|
||||
using Aliyun.Acs.Core;
|
||||
using Aliyun.Acs.Core.Profile;
|
||||
using Aliyun.Acs.Dysmsapi.Model.V20170525;
|
||||
using Aliyun.Acs.Core.Exceptions;
|
||||
|
||||
namespace WMS.Web.Domain.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 阿里云短息服务
|
||||
/// </summary>
|
||||
public class AliyunSmsService: IAliyunSmsService
|
||||
{
|
||||
private readonly ILogger<AliyunSmsService> _logger;
|
||||
private readonly IAcsClient profile;
|
||||
|
||||
public AliyunSmsService(ILogger<AliyunSmsService> logger, string accessKeyId, string accessKeySecret)
|
||||
{
|
||||
_logger = logger;
|
||||
profile = new DefaultAcsClient(DefaultProfile.GetProfile("cn-hangzhou", accessKeyId, accessKeySecret));
|
||||
}
|
||||
|
||||
public bool SendSms(string phoneNumbers, string templateCode, string signName, string templateParam = null)
|
||||
{
|
||||
SendSmsRequest request = new SendSmsRequest
|
||||
{
|
||||
PhoneNumbers = phoneNumbers,
|
||||
SignName = signName,
|
||||
TemplateCode = templateCode,
|
||||
TemplateParam = templateParam
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
SendSmsResponse response = profile.GetAcsResponse(request);
|
||||
return response.Code == "OK";
|
||||
}
|
||||
catch (ServerException ex)
|
||||
{
|
||||
// 处理服务端异常
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
catch (ClientException ex)
|
||||
{
|
||||
// 处理客户端异常
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="aliyun-net-sdk-core" Version="1.5.11" />
|
||||
<PackageReference Include="aliyun-net-sdk-dysmsapi" Version="1.0.0" />
|
||||
<PackageReference Include="AspNetCoreRateLimit" Version="4.0.2" />
|
||||
<PackageReference Include="AspNetCoreRateLimit.Redis" Version="1.0.1" />
|
||||
<PackageReference Include="AutoMapper" Version="10.1.1" />
|
||||
|
||||
Reference in New Issue
Block a user