短信发送

This commit is contained in:
橙子
2021-11-04 15:15:00 +08:00
parent 6f79f870bb
commit 9378cd937c
26 changed files with 615 additions and 15 deletions

View File

@@ -26,16 +26,18 @@ namespace Yi.Framework.Core
private readonly string _HostName = null;
private readonly string _UserName = null;
private readonly string _Password = null;
public RabbitMQInvoker(IOptionsMonitor<RabbitMQOptions> optionsMonitor) : this(optionsMonitor.CurrentValue.HostName, optionsMonitor.CurrentValue.UserName, optionsMonitor.CurrentValue.Password)
private readonly int _Port = 0;
public RabbitMQInvoker(IOptionsMonitor<RabbitMQOptions> optionsMonitor) : this(optionsMonitor.CurrentValue.HostName, optionsMonitor.CurrentValue.UserName, optionsMonitor.CurrentValue.Password,optionsMonitor.CurrentValue.Port)
{
this._rabbitMQOptions = optionsMonitor.CurrentValue;
}
public RabbitMQInvoker(string hostName, string userName = "cc", string password = "cc")
public RabbitMQInvoker(string hostName, string userName = "cc", string password = "cc",int port= 5672)
{
this._HostName = hostName;
this._UserName = userName;
this._Password = password;
this._Port = port;
}
#endregion
@@ -103,7 +105,9 @@ namespace Yi.Framework.Core
{
HostName = this._HostName,
Password = this._Password,
UserName = this._UserName
UserName = this._UserName,
Port=this._Port
};
_CurrentConnection = factory.CreateConnection();
}

View File

@@ -0,0 +1,46 @@
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Common.IOCOptions;
namespace Yi.Framework.Core.SMS
{
public class AliyunSMSInvoker
{
private IOptionsMonitor<SMSOptions> _sMSOptions;
public AliyunSMSInvoker(IOptionsMonitor<SMSOptions> sMSOptions)
{
_sMSOptions = sMSOptions;
}
private static AlibabaCloud.SDK.Dysmsapi20170525.Client CreateClient(string accessKeyId, string accessKeySecret)
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
// 您的AccessKey ID
AccessKeyId = accessKeyId,
// 您的AccessKey Secret
AccessKeySecret = accessKeySecret,
};
// 访问的域名
config.Endpoint = "dysmsapi.aliyuncs.com";
return new AlibabaCloud.SDK.Dysmsapi20170525.Client(config);
}
public void SendCode(string code,string phone)
{
AlibabaCloud.SDK.Dysmsapi20170525.Client client = CreateClient(_sMSOptions.CurrentValue.ID, _sMSOptions.CurrentValue.Secret);
AlibabaCloud.SDK.Dysmsapi20170525.Models.SendSmsRequest sendSmsRequest = new AlibabaCloud.SDK.Dysmsapi20170525.Models.SendSmsRequest
{
PhoneNumbers = phone,
SignName = _sMSOptions.CurrentValue.Sign,
TemplateCode = _sMSOptions.CurrentValue.Template,
TemplateParam = "{\"code\":\""+ code + "\"}",
};
// 复制代码运行请自行打印 API 的返回值
client.SendSms(sendSmsRequest);
}
}
}

View File

@@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AlibabaCloud.SDK.Dysmsapi20170525" Version="2.0.6" />
<PackageReference Include="Consul" Version="1.6.10.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />