diff --git a/HuanMengProject.sln b/HuanMengProject.sln index 64c2291..0760ebd 100644 --- a/HuanMengProject.sln +++ b/HuanMengProject.sln @@ -44,9 +44,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HuanMeng.MiaoYu.Code", "src EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HuanMeng.MiaoYu.WebApi", "src\2-api\HuanMeng.MiaoYu.WebApi\HuanMeng.MiaoYu.WebApi.csproj", "{729950F2-71EE-42C0-8B46-295740DE20BA}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HuanMeng.Utility", "src\0-core\HuanMeng.Utility\HuanMeng.Utility.csproj", "{48E1532F-8B50-477C-BB78-8AEA89A167CE}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextCensorFilterTest", "src\9-test\TextCensorFilterTest\TextCensorFilterTest.csproj", "{CF7FEDBA-FC1A-4D6D-92F1-6882B5143E0A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TextCensorFilterTest", "src\9-test\TextCensorFilterTest\TextCensorFilterTest.csproj", "{CF7FEDBA-FC1A-4D6D-92F1-6882B5143E0A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -94,10 +92,6 @@ Global {729950F2-71EE-42C0-8B46-295740DE20BA}.Debug|Any CPU.Build.0 = Debug|Any CPU {729950F2-71EE-42C0-8B46-295740DE20BA}.Release|Any CPU.ActiveCfg = Release|Any CPU {729950F2-71EE-42C0-8B46-295740DE20BA}.Release|Any CPU.Build.0 = Release|Any CPU - {48E1532F-8B50-477C-BB78-8AEA89A167CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {48E1532F-8B50-477C-BB78-8AEA89A167CE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {48E1532F-8B50-477C-BB78-8AEA89A167CE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {48E1532F-8B50-477C-BB78-8AEA89A167CE}.Release|Any CPU.Build.0 = Release|Any CPU {CF7FEDBA-FC1A-4D6D-92F1-6882B5143E0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CF7FEDBA-FC1A-4D6D-92F1-6882B5143E0A}.Debug|Any CPU.Build.0 = Debug|Any CPU {CF7FEDBA-FC1A-4D6D-92F1-6882B5143E0A}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -124,7 +118,6 @@ Global {B845C884-AD1A-4483-A2F6-B218DB14EA2D} = {DD14191F-22CE-48D8-A944-B8A41C97ACD4} {6E79742F-1E56-4B7D-94E8-B509D43561FA} = {DD14191F-22CE-48D8-A944-B8A41C97ACD4} {729950F2-71EE-42C0-8B46-295740DE20BA} = {0C0B6EB5-E41D-46D9-9F60-90D320A2EEF3} - {48E1532F-8B50-477C-BB78-8AEA89A167CE} = {DD14191F-22CE-48D8-A944-B8A41C97ACD4} {CF7FEDBA-FC1A-4D6D-92F1-6882B5143E0A} = {8D39E84B-2810-41D7-AFE6-0A58E09E34C3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/src/0-core/HuanMeng.DotNetCore/MiddlewareExtend/MiddlewareExtends.cs b/src/0-core/HuanMeng.DotNetCore/MiddlewareExtend/MiddlewareExtends.cs index a1b0f95..1a37e6d 100644 --- a/src/0-core/HuanMeng.DotNetCore/MiddlewareExtend/MiddlewareExtends.cs +++ b/src/0-core/HuanMeng.DotNetCore/MiddlewareExtend/MiddlewareExtends.cs @@ -14,7 +14,11 @@ namespace HuanMeng.DotNetCore.MiddlewareExtend /// public static IApplicationBuilder UseMiddlewareAll(this IApplicationBuilder builder) { - return builder.UseExceptionMiddleware().UseExecutionTimeMiddleware().UseSignMiddleware(); + return builder + .UseExceptionMiddleware() + .UseExecutionTimeMiddleware() + .UseSignMiddleware() + ; } diff --git a/src/0-core/HuanMeng.DotNetCore/Utility/AssemblyHelper/AssemblyInfo.cs b/src/0-core/HuanMeng.DotNetCore/Utility/AssemblyHelper/AssemblyInfo.cs new file mode 100644 index 0000000..d1d089f --- /dev/null +++ b/src/0-core/HuanMeng.DotNetCore/Utility/AssemblyHelper/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json.Serialization; + +namespace HuanMeng.DotNetCore.Utility.AssemblyHelper +{ + /// + /// 保存各种程序集信息属性的类。 + /// + [Serializable] + public class AssemblyInfo + { + /// + /// 获取或设置程序集的版本。 + /// + public string Version { get; set; } + + /// + /// 获取或设置程序集的文件版本。 + /// + public string FileVersion { get; set; } + + /// + /// 获取或设置程序集版本。 + /// + public string AssemblyVersion { get; set; } + + /// + /// 获取或设置程序集的信息性版本。 + /// + public string InformationalVersion { get; set; } + + ///// + ///// 获取或设置与程序集关联的公司名称。 + ///// + //public string Company { get; set; } + + ///// + ///// 获取或设置与程序集关联的产品名称。 + ///// + //public string Product { get; set; } + + /// + /// 获取或设置与程序集关联的版权信息。 + /// + public string Copyright { get; set; } + + /// + /// 获取或设置程序集的描述信息。 + /// + public string Description { get; set; } + } + +} diff --git a/src/0-core/HuanMeng.DotNetCore/Utility/AssemblyHelper/AssemblyInfoHelper.cs b/src/0-core/HuanMeng.DotNetCore/Utility/AssemblyHelper/AssemblyInfoHelper.cs new file mode 100644 index 0000000..28355a6 --- /dev/null +++ b/src/0-core/HuanMeng.DotNetCore/Utility/AssemblyHelper/AssemblyInfoHelper.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; + +namespace HuanMeng.DotNetCore.Utility.AssemblyHelper +{ + /// + /// 用于检索程序集信息的辅助类。 + /// + public static class AssemblyInfoHelper + { + /// + /// 从正在执行的程序集检索各种属性,并返回一个 AssemblyInfo 对象。 + /// + /// 包含程序集属性的 AssemblyInfo 对象。 + public static AssemblyInfo GetAssemblyInfo() + { + // 获取正在执行的程序集 + Assembly assembly = Assembly.GetExecutingAssembly(); + + // 创建并填充 AssemblyInfo 对象的相关属性 + var assemblyInfo = new AssemblyInfo + { + Version = assembly.GetName().Version.ToString(), + FileVersion = assembly.GetCustomAttributes().FirstOrDefault()?.Version ?? "", + AssemblyVersion = assembly.GetCustomAttributes().FirstOrDefault()?.Version ?? "", + InformationalVersion = assembly.GetCustomAttributes().FirstOrDefault()?.InformationalVersion ?? "", + //Company = assembly.GetCustomAttributes().FirstOrDefault()?.Company ?? "", + //Product = assembly.GetCustomAttributes().FirstOrDefault()?.Product ?? "", + Copyright = assembly.GetCustomAttributes().FirstOrDefault()?.Copyright ?? "", + Description = assembly.GetCustomAttributes().FirstOrDefault()?.Description ?? "" + }; + + return assemblyInfo; + } + } +} diff --git a/src/0-core/HuanMeng.DotNetCore/Utility/DateTimeExtensions.cs b/src/0-core/HuanMeng.DotNetCore/Utility/DateTimeExtensions.cs new file mode 100644 index 0000000..deb92e9 --- /dev/null +++ b/src/0-core/HuanMeng.DotNetCore/Utility/DateTimeExtensions.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HuanMeng.DotNetCore.Utility +{ + /// + /// 时间扩展 + /// + public static class DateTimeExtensions + { + /// + /// 获取时间戳,秒 + /// + /// + /// + public static long ToUnixTimestamp(this DateTime dateTime) + { + return (long)(dateTime.ToUniversalTime() - new DateTime(1970, 1, 1)).TotalSeconds; + } + + /// + /// 获取是时间戳,毫秒 + /// + /// + /// + public static long ToUnixTimestampMilliseconds(this DateTime dateTime) + { + return (long)(dateTime.ToUniversalTime() - new DateTime(1970, 1, 1)).TotalMilliseconds; + } + } +} diff --git a/src/0-core/HuanMeng.DotNetCore/Utility/PhoneNumberValidator.cs b/src/0-core/HuanMeng.DotNetCore/Utility/PhoneNumberValidator.cs new file mode 100644 index 0000000..e5b3289 --- /dev/null +++ b/src/0-core/HuanMeng.DotNetCore/Utility/PhoneNumberValidator.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.RegularExpressions; + +namespace HuanMeng.DotNetCore.Utility; +/// +/// 手机号 +/// +public class PhoneNumberValidator +{ + // 正则表达式用于匹配手机号码。可以根据需要调整以适应不同的国家或地区。 + private static readonly Regex phoneNumberRegex = new Regex(@"^(1[3-9]\d{9})$"); + + public static bool IsPhoneNumber(string input) + { + if (string.IsNullOrWhiteSpace(input)) + { + return false; + } + return phoneNumberRegex.IsMatch(input); + } +} + diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs b/src/0-core/HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs index cc01442..4304b90 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs @@ -8,7 +8,7 @@ using HuanMeng.MiaoYu.Model.DbSqlServer.Db_MiaoYu; using HuanMeng.MiaoYu.Model.Dto.Chat; using HuanMeng.MiaoYu.Model.EnumModel.Chat; using HuanMeng.MiaoYu.Model.EnumModel.User; -using HuanMeng.Utility; + using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; diff --git a/src/0-core/HuanMeng.MiaoYu.Code/GlobalUsings.cs b/src/0-core/HuanMeng.MiaoYu.Code/GlobalUsings.cs index 6bda305..ab2d6b2 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/GlobalUsings.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/GlobalUsings.cs @@ -10,4 +10,5 @@ global using System.Collections.Concurrent; global using HuanMeng.MiaoYu.Code.SysDictionary.Contract; global using HuanMeng.MiaoYu.Code.SysDictionary; global using HuanMeng.MiaoYu.Code.SysDictionary.DictionaryNetwork; -global using HuanMeng.DotNetCore.TextCensor; \ No newline at end of file +global using HuanMeng.DotNetCore.TextCensor; +global using HuanMeng.DotNetCore.Utility; \ No newline at end of file diff --git a/src/0-core/HuanMeng.MiaoYu.Code/HuanMeng.MiaoYu.Code.csproj b/src/0-core/HuanMeng.MiaoYu.Code/HuanMeng.MiaoYu.Code.csproj index 03e3cf0..3407612 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/HuanMeng.MiaoYu.Code.csproj +++ b/src/0-core/HuanMeng.MiaoYu.Code/HuanMeng.MiaoYu.Code.csproj @@ -32,7 +32,6 @@ - diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/.config/dotnet-tools.json b/src/2-api/HuanMeng.MiaoYu.WebApi/.config/dotnet-tools.json new file mode 100644 index 0000000..8612f23 --- /dev/null +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/.config/dotnet-tools.json @@ -0,0 +1,13 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-ef": { + "version": "8.0.7", + "commands": [ + "dotnet-ef" + ], + "rollForward": false + } + } +} \ No newline at end of file diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/AccountController.cs b/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/AccountController.cs index 53ad856..ad75a6c 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/AccountController.cs +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/AccountController.cs @@ -1,13 +1,14 @@ using Azure; using HuanMeng.DotNetCore.Base; +using HuanMeng.DotNetCore.Utility; using HuanMeng.MiaoYu.Code.Other; using HuanMeng.MiaoYu.Code.Users; using HuanMeng.MiaoYu.Model.Dto; using HuanMeng.MiaoYu.Model.Dto.Account; using HuanMeng.MiaoYu.Model.Dto.Shop; using HuanMeng.MiaoYu.WebApi.Base; -using HuanMeng.Utility; + using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj b/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj index bf7fb92..e7d797c 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj @@ -3,6 +3,7 @@ net8.0 enable + false enable True @@ -23,7 +24,6 @@ - diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs b/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs index 462eed9..2e511f1 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs @@ -8,7 +8,6 @@ using HuanMeng.MiaoYu.Code.TencentUtile; using HuanMeng.MiaoYu.Code.Users.UserAccount.VerificationCodeManager; using HuanMeng.MiaoYu.Code.JwtUtil; using Microsoft.AspNetCore.Authentication.JwtBearer; -using HuanMeng.Utility.AssemblyHelper; using HuanMeng.DotNetCore.CustomExtension; using HuanMeng.MiaoYu.Code.Cache; using HuanMeng.MiaoYu.Code.Chat; @@ -20,6 +19,7 @@ using Newtonsoft.Json.Serialization; using HuanMeng.MiaoYu.Code.SysDictionary; using HuanMeng.MiaoYu.Code.Base; using HuanMeng.MiaoYu.Code.Other; +using HuanMeng.DotNetCore.Utility.AssemblyHelper; var builder = WebApplication.CreateBuilder(args); //Log.Logger = new LoggerConfiguration() // .WriteTo.Console() @@ -57,7 +57,8 @@ if (type != null) builder.Services.AddAutoMapper(mapperDomain); #endregion -builder.Services.AddControllers().AddNewtonsoftJson(options => +builder.Services.AddControllers() + .AddNewtonsoftJson(options => { // 配置 Newtonsoft.Json 选项 options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; // 忽略循环引用 @@ -65,7 +66,8 @@ builder.Services.AddControllers().AddNewtonsoftJson(options => options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";// 时间格式化 //options.SerializerSettings.Converters.Add() // 其他配置... -}); +}) + ; // .AddJsonOptions(options => //{ // //options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve; @@ -164,8 +166,8 @@ app.UseMiddlewareAll(); app.MapGet("/", () => "请求成功").WithName("默认请求"); var startDateTime = DateTime.Now; -//var InformationalVersion = Assembly.GetEntryAssembly().GetCustomAttribute().InformationalVersion; -//Console.WriteLine($"version:{InformationalVersion}"); +var InformationalVersion = Assembly.GetEntryAssembly().GetCustomAttribute().InformationalVersion; +Console.WriteLine($"version:{InformationalVersion}"); app.MapGet("/system", () => { @@ -185,4 +187,4 @@ app.MapGet("/system", () => }; }).WithName("获取系统数据"); #endregion -app.Run(); + app.Run();