diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs index b50bdea7..258168fc 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs @@ -7,8 +7,10 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Yi.Framework.Common; +using Yi.Framework.Common.Const; using Yi.Framework.Common.Helper; using Yi.Framework.Common.Models; +using Yi.Framework.Common.QueueModel; using Yi.Framework.Core; using Yi.Framework.DTOModel; using Yi.Framework.Interface; @@ -25,11 +27,13 @@ namespace Yi.Framework.ApiMicroservice.Controllers private IUserService _userService; private IMenuService _menuService; - public AccountController(ILogger logger, IUserService userService, IMenuService menuService) + private RabbitMQInvoker _rabbitMQInvoker; + public AccountController(ILogger logger, IUserService userService, IMenuService menuService,RabbitMQInvoker rabbitMQInvoker) { _logger = logger; _userService = userService; _menuService = menuService; + _rabbitMQInvoker = rabbitMQInvoker; } @@ -83,6 +87,14 @@ namespace Yi.Framework.ApiMicroservice.Controllers return Result.Error(); } + + [HttpGet] + public Result SendSMS(SMSQueueModel test) + { + _rabbitMQInvoker.Send(new Common.IOCOptions.RabbitMQConsumerModel() { ExchangeName=RabbitConst.SMS_Exchange,QueueName=RabbitConst.SMS_Queue_Send} ); + return Result.Success(); + } + /// /// 传入邮箱,需要先到数据库判断该邮箱是否被人注册过,到userservice写mail_exist方法,还有接口别忘了。这个接口不需要洞,只需要完成userservice写mail_exist与接口即可 /// diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/JobController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/JobController.cs index 6104d10a..84566713 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/JobController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/JobController.cs @@ -28,6 +28,10 @@ namespace Yi.Framework.ApiMicroservice.Controllers _quartzInvoker = quartzInvoker; } + /// + /// + /// + /// [HttpPost] public async Task startJob() { @@ -44,18 +48,30 @@ namespace Yi.Framework.ApiMicroservice.Controllers return Result.Success(); } + /// + /// + /// + /// [HttpGet] public async Task getRunJobList() { return Result.Success().SetData(await _quartzInvoker.getRunJobList()); } + /// + /// + /// + /// [HttpGet] public Result getJobClass() { return Result.Success().SetData(_quartzInvoker.getJobClassList()); } + /// + /// + /// + /// [HttpPut] public async Task stopJob() { @@ -63,6 +79,10 @@ namespace Yi.Framework.ApiMicroservice.Controllers return Result.Success(); } + /// + /// + /// + /// [HttpDelete] public async Task DeleteJob() { @@ -70,6 +90,10 @@ namespace Yi.Framework.ApiMicroservice.Controllers return Result.Success(); } + /// + /// + /// + /// [HttpPut] public async Task ResumeJob() { diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs index 60d169f3..c552a081 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs @@ -76,6 +76,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// + /// SetRoleByUser /// 给多个用户设置多个角色,ids有用户id与 角色列表ids,多对多,ids1用户,ids2为角色 /// 用户设置给用户设置角色 /// diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs index af3cb98d..59cd1472 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs @@ -70,7 +70,10 @@ namespace Yi.Framework.ApiMicroservice #endregion services.AddRabbitMQService(); - + #region + //ŷ + #endregion + services.AddSMSService(); } #region Autofacע @@ -158,6 +161,7 @@ namespace Yi.Framework.ApiMicroservice app.UseEndpoints(endpoints => { endpoints.MapControllers(); + }); } } diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/SwaggerDoc.xml b/Yi.Framework/Yi.Framework.ApiMicroservice/SwaggerDoc.xml index 6c8d851c..321734fd 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/SwaggerDoc.xml +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/SwaggerDoc.xml @@ -25,6 +25,12 @@ + + + 发送邮件 + + + 传入邮箱,需要先到数据库判断该邮箱是否被人注册过,到userservice写mail_exist方法,还有接口别忘了。这个接口不需要洞,只需要完成userservice写mail_exist与接口即可 @@ -47,6 +53,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 这个是要递归的,但是要过滤掉删除的,所以,可以写一个通用过滤掉删除的方法 @@ -203,6 +245,7 @@ + SetRoleByUser 给多个用户设置多个角色,ids有用户id与 角色列表ids,多对多,ids1用户,ids2为角色 用户设置给用户设置角色 diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/appsettings.json b/Yi.Framework/Yi.Framework.ApiMicroservice/appsettings.json index e08f7152..af47026f 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/appsettings.json +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/appsettings.json @@ -13,11 +13,12 @@ "Apollo_Enabled": false, "HealthCheck_Enabled": false, "Cors_Enabled": true, - "RabbitMQ_Enabled": false, + "RabbitMQ_Enabled": true, "Redis_Enabled": true, "RedisSeed_Enabled": true, "Kafka_Enabled": false, "MutiDB_Enabled": false, + "SMS_Enabled": true, "DbList": [ "Sqlite", "Mysql", "Sqlserver", "Oracle" ], "DbSelect": "Mysql", @@ -46,6 +47,12 @@ "DB": 1, "Password": "Qz52013142020." }, + "RabbitConn": { + "HostName": "118.195.191.41", + "UserName": "cc", + "Password": "cc", + "Port": 5672 + }, "KafkaOptions": { "BrokerList": "192.168.3.230:9092", "TopicName": "kafkalog" @@ -65,5 +72,11 @@ "DeregisterCriticalServiceAfter": 60, "Tag": "13" }, + "SMS": { + "ID": "LTAI5tJvjPaXCyyPMfXLNbVA", + "Secret": "fLQv7jjj57fUKLFK8REeAQPFVDjUYn", + "Sign": "JiftCC", + "Template": "SMS_221640732" + }, "IPLibraryServiceUrl": "http://gRPCIPLibraryService" } \ No newline at end of file diff --git a/Yi.Framework/Yi.Framework.Common/Const/RabbitConst.cs b/Yi.Framework/Yi.Framework.Common/Const/RabbitConst.cs new file mode 100644 index 00000000..cb7f294e --- /dev/null +++ b/Yi.Framework/Yi.Framework.Common/Const/RabbitConst.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Common.Const +{ + public class RabbitConst + { + private const string prefix = "Yi.Framework."; + public const string SMS_Exchange = prefix+"SMS.Exchange"; + public const string SMS_Queue_Send = prefix+ "SMS.Queue.Send"; + } +} diff --git a/Yi.Framework/Yi.Framework.Common/IOCOptions/RabbitMQOptions.cs b/Yi.Framework/Yi.Framework.Common/IOCOptions/RabbitMQOptions.cs index dd716f86..bdcb0f13 100644 --- a/Yi.Framework/Yi.Framework.Common/IOCOptions/RabbitMQOptions.cs +++ b/Yi.Framework/Yi.Framework.Common/IOCOptions/RabbitMQOptions.cs @@ -25,6 +25,8 @@ namespace Yi.Framework.Common.IOCOptions public string UserName { get; set; } public string Password { get; set; } + public int Port { get; set; } + } public class RabbitMQConsumerModel diff --git a/Yi.Framework/Yi.Framework.Common/IOCOptions/SMSOptions.cs b/Yi.Framework/Yi.Framework.Common/IOCOptions/SMSOptions.cs new file mode 100644 index 00000000..c9f36347 --- /dev/null +++ b/Yi.Framework/Yi.Framework.Common/IOCOptions/SMSOptions.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Common.IOCOptions +{ + public class SMSOptions + { + + public string ID { get; set; } + public string Secret { get; set; } + public string Sign { get; set; } + public string Template { get; set; } + + } +} diff --git a/Yi.Framework/Yi.Framework.Common/QueueModel/SMSQueueModel.cs b/Yi.Framework/Yi.Framework.Common/QueueModel/SMSQueueModel.cs new file mode 100644 index 00000000..242a75c9 --- /dev/null +++ b/Yi.Framework/Yi.Framework.Common/QueueModel/SMSQueueModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Common.QueueModel +{ + public class SMSQueueModel + { + public string code { get; set; } + public string phone { get; set; } + } +} diff --git a/Yi.Framework/Yi.Framework.Core/RabbitMQInvoker.cs b/Yi.Framework/Yi.Framework.Core/RabbitMQInvoker.cs index 8a6f92d3..b28fc22f 100644 --- a/Yi.Framework/Yi.Framework.Core/RabbitMQInvoker.cs +++ b/Yi.Framework/Yi.Framework.Core/RabbitMQInvoker.cs @@ -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 optionsMonitor) : this(optionsMonitor.CurrentValue.HostName, optionsMonitor.CurrentValue.UserName, optionsMonitor.CurrentValue.Password) + private readonly int _Port = 0; + public RabbitMQInvoker(IOptionsMonitor 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(); } diff --git a/Yi.Framework/Yi.Framework.Core/SMS/AliyunSMSInvoker.cs b/Yi.Framework/Yi.Framework.Core/SMS/AliyunSMSInvoker.cs new file mode 100644 index 00000000..eb5bcb4c --- /dev/null +++ b/Yi.Framework/Yi.Framework.Core/SMS/AliyunSMSInvoker.cs @@ -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; + public AliyunSMSInvoker(IOptionsMonitor 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); + } + } +} diff --git a/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj b/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj index d359fcfb..3f7b4706 100644 --- a/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj +++ b/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj @@ -5,6 +5,7 @@ + diff --git a/Yi.Framework/Yi.Framework.PageDetail/Properties/launchSettings.json b/Yi.Framework/Yi.Framework.PageDetail/Properties/launchSettings.json index 2c360cb4..fff2465e 100644 --- a/Yi.Framework/Yi.Framework.PageDetail/Properties/launchSettings.json +++ b/Yi.Framework/Yi.Framework.PageDetail/Properties/launchSettings.json @@ -12,7 +12,7 @@ "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, - "launchUrl": "swagger", + "launchUrl": "", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/Yi.Framework/Yi.Framework.SMSProcessor/Log4net.config b/Yi.Framework/Yi.Framework.SMSProcessor/Log4net.config new file mode 100644 index 00000000..958c7e78 --- /dev/null +++ b/Yi.Framework/Yi.Framework.SMSProcessor/Log4net.config @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Yi.Framework/Yi.Framework.SMSProcessor/Program.cs b/Yi.Framework/Yi.Framework.SMSProcessor/Program.cs new file mode 100644 index 00000000..a0dfebec --- /dev/null +++ b/Yi.Framework/Yi.Framework.SMSProcessor/Program.cs @@ -0,0 +1,77 @@ +using Com.Ctrip.Framework.Apollo; +using Com.Ctrip.Framework.Apollo.Core; +using Com.Ctrip.Framework.Apollo.Enums; +using Com.Ctrip.Framework.Apollo.Logging; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using Yi.Framework.Common.IOCOptions; +using Yi.Framework.Core; +using Yi.Framework.Core.ConsulExtend; +using Yi.Framework.WebCore; +using Yi.Framework.WebCore.MiddlewareExtend; + +namespace Yi.Framework.SMSProcessor +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureAppConfiguration((hostBuilderContext, configurationBuilder) => + { + configurationBuilder.AddCommandLine(args); + configurationBuilder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false); + //configurationBuilder.AddJsonFile("configuration.json", optional: false, reloadOnChange: true); + #region + //Apollo配置 + #endregion + //configurationBuilder.AddApolloService("Yi"); + }) + .ConfigureLogging(loggingBuilder => + { + loggingBuilder.AddFilter("System", Microsoft.Extensions.Logging.LogLevel.Warning); + loggingBuilder.AddFilter("Microsoft", Microsoft.Extensions.Logging.LogLevel.Warning); + loggingBuilder.AddLog4Net(); + }) + .ConfigureServices((hostContext, services) => + { + + IConfiguration configuration = services.BuildServiceProvider().GetRequiredService(); + + #region + //Ioc配置 + #endregion + services.AddSingleton(new Appsettings(configuration)); + services.AddHostedService(); + services.AddHostedService(); + + #region 服务注入 + //services.Configure(configuration.GetSection("MysqlConn")); + + + #region + //RabbitMQ服务配置 + #endregion + services.AddRabbitMQService(); + #endregion + + #region + //短信服务配置 + #endregion + services.AddSMSService(); + + #region Consul + //services.Configure(configuration.GetSection("ConsulClientOption")); + //services.AddTransient(); + #endregion + + }); + } + } diff --git a/Yi.Framework/Yi.Framework.SMSProcessor/SendWorker.cs b/Yi.Framework/Yi.Framework.SMSProcessor/SendWorker.cs new file mode 100644 index 00000000..34519780 --- /dev/null +++ b/Yi.Framework/Yi.Framework.SMSProcessor/SendWorker.cs @@ -0,0 +1,67 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Yi.Framework.Common.Const; +using Yi.Framework.Common.IOCOptions; +using Yi.Framework.Common.Models; +using Yi.Framework.Common.QueueModel; +using Yi.Framework.Core; +using Yi.Framework.Core.ConsulExtend; +using Yi.Framework.Core.SMS; + +namespace Yi.Framework.SMSProcessor +{ + public class SendWorker : BackgroundService + { + private readonly ILogger _logger; + private readonly RabbitMQInvoker _RabbitMQInvoker; + private readonly AliyunSMSInvoker _aliyunSMSInvoker; + public SendWorker(ILogger logger, RabbitMQInvoker rabbitMQInvoker,AliyunSMSInvoker aliyunSMSInvoker) + { + this._logger = logger; + this._RabbitMQInvoker = rabbitMQInvoker; + _aliyunSMSInvoker = aliyunSMSInvoker; + + } + + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + RabbitMQConsumerModel rabbitMQConsumerModel = new RabbitMQConsumerModel() + { + ExchangeName = RabbitConst.SMS_Exchange, + QueueName = RabbitConst.SMS_Queue_Send + }; + HttpClient _HttpClient = new HttpClient(); + this._RabbitMQInvoker.RegistReciveAction(rabbitMQConsumerModel, message => + { + try + { + _aliyunSMSInvoker.SendCode("1234","15949688315"); + + return true; + } + catch (Exception ex) + { + var logModel = new LogModel() + { + OriginalClassName = this.GetType().FullName, + OriginalMethodName = nameof(ExecuteAsync), + Remark = "Ϣд־" + }; + this._logger.LogError(ex, $"{nameof(SendWorker)}, Exception:{ex.Message}", JsonConvert.SerializeObject(logModel)); + return false; + } + }); + await Task.CompletedTask; + } + } +} diff --git a/Yi.Framework/Yi.Framework.SMSProcessor/Worker.cs b/Yi.Framework/Yi.Framework.SMSProcessor/Worker.cs new file mode 100644 index 00000000..09544ed5 --- /dev/null +++ b/Yi.Framework/Yi.Framework.SMSProcessor/Worker.cs @@ -0,0 +1,32 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace Yi.Framework.SMSProcessor +{ + public class Worker : BackgroundService + { + private readonly ILogger _logger; + private readonly IConfiguration _IConfiguration; + public Worker(ILogger logger, IConfiguration configuration) + { + this._logger = logger; + this._IConfiguration = configuration; + } + + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + while (!stoppingToken.IsCancellationRequested) + { + _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); + _logger.LogInformation($"Worker appsetting ConsulClientOption:Ip={this._IConfiguration["ConsulClientOption:Ip"]}"); + await Task.Delay(1000, stoppingToken); + } + } + } +} diff --git a/Yi.Framework/Yi.Framework.SMSProcessor/Yi.Framework.SMSProcessor.csproj b/Yi.Framework/Yi.Framework.SMSProcessor/Yi.Framework.SMSProcessor.csproj new file mode 100644 index 00000000..95a479a4 --- /dev/null +++ b/Yi.Framework/Yi.Framework.SMSProcessor/Yi.Framework.SMSProcessor.csproj @@ -0,0 +1,38 @@ + + + + net5.0 + Exe + Yi.Framework.SMSProcessor.Program + + + + + + + + + Always + true + PreserveNewest + + + + + + + + + + + + + + Always + + + Always + + + + diff --git a/Yi.Framework/Yi.Framework.SMSProcessor/appsettings.Development.json b/Yi.Framework/Yi.Framework.SMSProcessor/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/Yi.Framework/Yi.Framework.SMSProcessor/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/Yi.Framework/Yi.Framework.SMSProcessor/appsettings.json b/Yi.Framework/Yi.Framework.SMSProcessor/appsettings.json new file mode 100644 index 00000000..be9e72f1 --- /dev/null +++ b/Yi.Framework/Yi.Framework.SMSProcessor/appsettings.json @@ -0,0 +1,45 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "RabbitMQ_Enabled": true, + "SMS_Enabled": true, + "RedisConn": { + "Host": "192.168.2.128", + "Prot": 6379, + "DB": 0, + "Password": "123456" + }, + "RabbitConn": { + "HostName": "118.195.191.41", + "UserName": "cc", + "Password": "cc", + "Port": 5672 + }, + //"DetailPageUrl": "http://localhost:5728/item/", + "DetailPageUrl": "http://PageDetail/item/", + "ConsulClientOption": { + "IP": "192.168.2.128", + "Port": "8500", + "Datacenter": "dc1" + }, + "MysqlConn": { + "Url": "server=192.168.2.128;port=3306;database=ECDB;user id=root;password=123456" + }, + "Apollo": { + "AppId": "Yi.Framework.StaticPageProcessor", + "Env": "DEV", + "MetaServer": "http://192.168.2.168:8080", + "ConfigServer": [ "http://192.168.2.168:8080" ] + }, + "SMS": { + "ID": "LTAI5tJvjPaXCyyPMfXLNbVA", + "Secret": "fLQv7jjj57fUKLFK8REeAQPFVDjUYn", + "Sign": "JiftCC", + "Template": "SMS_221640732" + } +} diff --git a/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/RabbitMQExtension.cs b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/RabbitMQExtension.cs index 46b276cf..e98b49c8 100644 --- a/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/RabbitMQExtension.cs +++ b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/RabbitMQExtension.cs @@ -4,6 +4,7 @@ using Microsoft.OpenApi.Models; using System; using System.IO; using Yi.Framework.Common.IOCOptions; +using Yi.Framework.Core; namespace Yi.Framework.WebCore.MiddlewareExtend { @@ -17,6 +18,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend if (Appsettings.appBool("RabbitMQ_Enabled")) { services.Configure(Appsettings.appConfiguration("RabbitConn")); + services.AddTransient(); } return services; diff --git a/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/SMSExtension.cs b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/SMSExtension.cs new file mode 100644 index 00000000..487f02d4 --- /dev/null +++ b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/SMSExtension.cs @@ -0,0 +1,29 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.OpenApi.Models; +using System; +using System.IO; +using Yi.Framework.Common.IOCOptions; +using Yi.Framework.Core; +using Yi.Framework.Core.SMS; + +namespace Yi.Framework.WebCore.MiddlewareExtend +{ + /// + /// Redis扩展 + /// + public static class SMSExtension + { + public static IServiceCollection AddSMSService(this IServiceCollection services) + { + if (Appsettings.appBool("SMS_Enabled")) + { + + services.Configure(Appsettings.appConfiguration("SMS")); + services.AddTransient(); + } + return services; + + } + } +} diff --git a/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/SwaggerExtension.cs b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/SwaggerExtension.cs index cbb7040a..5eb04bca 100644 --- a/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/SwaggerExtension.cs +++ b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/SwaggerExtension.cs @@ -1,4 +1,6 @@ -using Microsoft.AspNetCore.Builder; +using IGeekFan.AspNetCore.Knife4jUI; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Models; using System; @@ -32,7 +34,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend var apiXmlPath = Path.Combine(basePath, @"SwaggerDoc.xml");//控制器层注释 //var entityXmlPath = Path.Combine(basePath, @"SwaggerDoc.xml");//实体注释 //c.IncludeXmlComments(apiXmlPath, true);//true表示显示控制器注释 - c.IncludeXmlComments(apiXmlPath); + c.IncludeXmlComments(apiXmlPath,true); //添加控制器注释 //c.DocumentFilter(); @@ -59,6 +61,17 @@ namespace Yi.Framework.WebCore.MiddlewareExtend } }, Array.Empty() } }); + + c.AddServer(new OpenApiServer() + { + Url = "https://ccnetcore.com", + Description = "Yi-Framework" + }); + c.CustomOperationIds(apiDesc => + { + var controllerAction = apiDesc.ActionDescriptor as ControllerActionDescriptor; + return controllerAction.ActionName; + }); }); #endregion @@ -70,11 +83,14 @@ namespace Yi.Framework.WebCore.MiddlewareExtend //在 Startup.Configure 方法中,启用中间件为生成的 JSON 文档和 Swagger UI 提供服务: // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); - app.UseSwaggerUI(c => + + + app.UseKnife4UI(c => { + c.RoutePrefix = "swagger"; // serve the UI at root if (swaggerModels.Length == 0) { - c.SwaggerEndpoint("/swagger/v1/swagger.json", "Yi.Framework"); + c.SwaggerEndpoint("/v1/swagger.json", "Yi.Framework"); } else { @@ -83,10 +99,25 @@ namespace Yi.Framework.WebCore.MiddlewareExtend c.SwaggerEndpoint(k.url, k.name); } } + }); - } + //app.UseSwaggerUI(c => + //{ + // if (swaggerModels.Length == 0) + // { + // c.SwaggerEndpoint("/swagger/v1/swagger.json", "Yi.Framework"); + // } + // else + // { + // foreach (var k in swaggerModels) + // { + // c.SwaggerEndpoint(k.url, k.name); + // } + // } - ); + //} + + //); } } diff --git a/Yi.Framework/Yi.Framework.WebCore/Yi.Framework.WebCore.csproj b/Yi.Framework/Yi.Framework.WebCore/Yi.Framework.WebCore.csproj index 4e946f1b..396231b7 100644 --- a/Yi.Framework/Yi.Framework.WebCore/Yi.Framework.WebCore.csproj +++ b/Yi.Framework/Yi.Framework.WebCore/Yi.Framework.WebCore.csproj @@ -1,4 +1,4 @@ - + net5.0 @@ -9,6 +9,7 @@ + diff --git a/Yi.Framework/Yi.Framework.sln b/Yi.Framework/Yi.Framework.sln index 5858f43d..c22c9c20 100644 --- a/Yi.Framework/Yi.Framework.sln +++ b/Yi.Framework/Yi.Framework.sln @@ -41,7 +41,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.MSUnitTest", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.PageDetail", "Yi.Framework.PageDetail\Yi.Framework.PageDetail.csproj", "{637501E2-A32E-485C-8680-ED863D1793C2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Job", "Yi.Framework.Task\Yi.Framework.Job.csproj", "{F1C990DD-32C3-4F02-83B0-6E52B18B0B17}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Job", "Yi.Framework.Task\Yi.Framework.Job.csproj", "{F1C990DD-32C3-4F02-83B0-6E52B18B0B17}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.SMSProcessor", "Yi.Framework.SMSProcessor\Yi.Framework.SMSProcessor.csproj", "{7C58FB7C-9AB5-47CF-ACEB-B784CF820E7E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -109,6 +111,10 @@ Global {F1C990DD-32C3-4F02-83B0-6E52B18B0B17}.Debug|Any CPU.Build.0 = Debug|Any CPU {F1C990DD-32C3-4F02-83B0-6E52B18B0B17}.Release|Any CPU.ActiveCfg = Release|Any CPU {F1C990DD-32C3-4F02-83B0-6E52B18B0B17}.Release|Any CPU.Build.0 = Release|Any CPU + {7C58FB7C-9AB5-47CF-ACEB-B784CF820E7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7C58FB7C-9AB5-47CF-ACEB-B784CF820E7E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7C58FB7C-9AB5-47CF-ACEB-B784CF820E7E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7C58FB7C-9AB5-47CF-ACEB-B784CF820E7E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -129,6 +135,7 @@ Global {531255B3-9669-4BC1-B4E5-A0C6E0540F0D} = {C90E38FB-69EA-4997-8B3A-2C71EFA65B2B} {637501E2-A32E-485C-8680-ED863D1793C2} = {026D2797-07D1-4BA5-8070-50CDE0258C59} {F1C990DD-32C3-4F02-83B0-6E52B18B0B17} = {9ABAF6B1-6C02-498A-90A2-ABC1140CF89A} + {7C58FB7C-9AB5-47CF-ACEB-B784CF820E7E} = {D6B44435-EAFA-4D55-90D0-3AF80485FB83} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1ED77A6E-377F-4EEF-A3D0-D65C94657DAF}