Browse Source

首次提交,从Github迁移

shenzhoukai 3 months ago
commit
2f30afeacc

+ 112 - 0
.gitignore

@@ -0,0 +1,112 @@
+# ---> C Sharp
+# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
+[Bb]in/
+[Oo]bj/
+
+# mstest test results
+TestResults
+
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+[Dd]ebug/
+[Rr]elease/
+x64/
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.log
+*.vspscc
+*.vssscc
+.builds
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*
+
+# NCrunch
+*.ncrunch*
+.*crunch*.local.xml
+
+# Installshield output folder
+[Ee]xpress
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish
+
+# Publish Web Output
+*.Publish.xml
+
+# NuGet Packages Directory
+packages
+
+# Windows Azure Build Output
+csx
+*.build.csdef
+
+# Windows Store app package directory
+AppPackages/
+
+# Others
+[Bb]in
+[Oo]bj
+sql
+TestResults
+[Tt]est[Rr]esult*
+*.Cache
+ClientBin
+[Ss]tyle[Cc]op.*
+~$*
+*.dbmdl
+Generated_Code #added for RIA/Silverlight projects
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+
+.vs
+PublishProfiles

+ 17 - 0
Alchemy.Core.csproj

@@ -0,0 +1,17 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net8.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.0" />
+    <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.7.0" />
+    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
+    <PackageReference Include="RestSharp" Version="112.1.0" />
+    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.7.0" />
+  </ItemGroup>
+
+</Project>

+ 25 - 0
Alchemy.Core.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.9.34728.123
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Alchemy.Core", "Alchemy.Core.csproj", "{08E04E44-AB4E-44F4-B213-0126FE53702E}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{08E04E44-AB4E-44F4-B213-0126FE53702E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{08E04E44-AB4E-44F4-B213-0126FE53702E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{08E04E44-AB4E-44F4-B213-0126FE53702E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{08E04E44-AB4E-44F4-B213-0126FE53702E}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {8C9F401D-0E6A-4E23-8ED2-6A1233818EB4}
+	EndGlobalSection
+EndGlobal

+ 39 - 0
Extensions/DataTableExtension.cs

@@ -0,0 +1,39 @@
+using System.Data;
+using System.Reflection;
+namespace Alchemy.Core.Extensions
+{
+    public static class DataTableExtension
+    {
+        /// <summary>
+        /// 第一种:DataTable 转换为List<T>对象集合
+        /// </summary>
+        /// <typeparam name="TResult">类型</typeparam>
+        /// <param name="dt">DataTable</param>
+        /// <returns></returns>
+        public static List<TResult> DataTableToList<TResult>(this DataTable dt) where TResult : class, new()
+        {
+            //创建一个属性的列表
+            List<PropertyInfo> prlist = new List<PropertyInfo>();
+            //获取TResult的类型实例  反射的入口
+            Type t = typeof(TResult);
+            //获得TResult 的所有的Public 属性 并找出TResult属性和DataTable的列名称相同的属性(PropertyInfo) 并加入到属性列表
+            Array.ForEach(t.GetProperties(), p => { if (dt.Columns.Contains(p.Name)) prlist.Add(p); });
+            //创建返回的集合
+            List<TResult> oblist = new List<TResult>();
+            foreach (DataRow row in dt.Rows)
+            {
+                //创建TResult的实例
+                TResult ob = new TResult();
+                //找到对应的数据  并赋值
+                prlist.ForEach(p =>
+                {
+                    if (row[p.Name] != DBNull.Value)
+                        p.SetValue(ob, row[p.Name], null);
+                });
+                //放入到返回的集合中.
+                oblist.Add(ob);
+            }
+            return oblist;
+        }
+    }
+}

+ 55 - 0
Extensions/DateTimeExtension.cs

@@ -0,0 +1,55 @@
+namespace Alchemy.Core.Extensions
+{
+    public static class DateTimeExtension
+    {
+        public static long ToTimeStampMs(this DateTime dateTime)
+        {
+            long timeStamp = 946656000000;
+            try
+            {
+                timeStamp = (dateTime.Ticks - TimeZoneInfo.ConvertTimeFromUtc(new DateTime(1970, 1, 1), TimeZoneInfo.Local).Ticks) / 10000;
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
+            return timeStamp;
+        }
+        /// <summary>
+        /// 日期转时间戳
+        /// </summary>
+        /// <param name="dateTime"></param>
+        /// <returns></returns>
+        public static long ToTimeStamp(this DateTime dateTime)
+        {
+            long timeStamp = 946656000;
+            try
+            {
+                timeStamp = (dateTime.Ticks - TimeZoneInfo.ConvertTimeFromUtc(new DateTime(1970, 1, 1), TimeZoneInfo.Local).Ticks) / 10000000;
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
+            return timeStamp;
+        }
+        /// <summary>
+        /// 日期转换为日期时间字符串,yyyy-MM-dd HH:mm:ss
+        /// </summary>
+        /// <param name="dt"></param>
+        /// <returns></returns>
+        public static string ToDtString(this DateTime dt)
+        {
+            return dt.ToString("yyyy-MM-dd HH:mm:ss");
+        }
+        /// <summary>
+        /// 日期转换为日期字符串,yyyy-MM-dd
+        /// </summary>
+        /// <param name="dt"></param>
+        /// <returns></returns>
+        public static string ToDateString(this DateTime dt)
+        {
+            return dt.ToString("yyyy-MM-dd");
+        }
+    }
+}

+ 19 - 0
Extensions/FloatExtension.cs

@@ -0,0 +1,19 @@
+namespace Alchemy.Core.Extensions
+{
+    public static class FloatExtension
+    {
+        public static string ToDecimalCount(this float value, int count = 0)
+        {
+            string strFormat = "0";
+            if (count < 0)
+                strFormat = "0";
+            else
+            {
+                strFormat += ".";
+                for (int i = 0; i < count; i++)
+                    strFormat += "0";
+            }
+            return value.ToString(strFormat);
+        }
+    }
+}

+ 163 - 0
Extensions/HttpContextExtension.cs

@@ -0,0 +1,163 @@
+using Microsoft.AspNetCore.Http;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
+namespace Alchemy.Core.Extensions
+{
+    public static class HttpContextExtension
+    {
+        /// <summary>
+        /// 获取请求的Referer
+        /// </summary>
+        /// <param name="context"></param>
+        /// <returns></returns>
+        public static string GetReferer(this HttpContext context)
+        {
+            if (context.Request.Headers.ContainsKey("Referer"))
+                return context.Request.Headers["Referer"].ToString();
+            else
+                return string.Empty;
+        }
+        /// <summary>
+        /// 判断是否本地请求
+        /// </summary>
+        /// <param name="context"></param>
+        /// <returns></returns>
+        public static bool IsLocalRequest(this HttpContext context)
+        {
+            return context.GetFromIp().Equals("127.0.0.1");
+        }
+        /// <summary>
+        /// 获取接口路由
+        /// </summary>
+        /// <param name="context"></param>
+        /// <returns></returns>
+        public static string GetRoute(this HttpContext context)
+        {
+            return context.Request.Path;
+        }
+        /// <summary>
+        /// 获取请求方法
+        /// </summary>
+        /// <param name="context"></param>
+        /// <returns></returns>
+        public static string GetMethod(this HttpContext context)
+        {
+            return context.Request.Method;
+        }
+        /// <summary>
+        /// 获取请求URL
+        /// </summary>
+        /// <param name="context"></param>
+        /// <returns></returns>
+        public static string GetRequestUrl(this HttpContext context)
+        {
+            return $"{context.Request.Scheme}://{context.Request?.Host}{context.Request?.Path}{context.Request?.QueryString}";
+        }
+        /// <summary>
+        /// 获取Authorization
+        /// </summary>
+        /// <param name="context"></param>
+        /// <returns></returns>
+        public static string GetAuthorization(this HttpContext context)
+        {
+            return context.Request.Headers["Authorization"].ToString();
+        }
+        /// <summary>
+        /// 判断是否包含Authorization
+        /// </summary>
+        /// <param name="context"></param>
+        /// <returns></returns>
+        public static bool ContainsAuthorization(this HttpContext context)
+        {
+            return context.Request.Headers.ContainsKey("Authorization");
+        }
+        /// <summary>
+        /// 获取UA
+        /// </summary>
+        /// <param name="context"></param>
+        /// <returns></returns>
+        public static string GetUserAgent(this HttpContext context)
+        {
+            return context.Request.Headers["User-Agent"].ToString();
+        }
+        /// <summary>
+        /// 获取请求者IP
+        /// </summary>
+        /// <param name="context"></param>
+        /// <returns></returns>
+        public static string GetFromIp(this HttpContext context)
+        {
+            if (context.Connection.RemoteIpAddress.IsNull())
+                return string.Empty;
+            else
+                return context.Connection.RemoteIpAddress.ToString().Replace("::ffff:", "");
+        }
+        /// <summary>
+        /// 获取请求者端口
+        /// </summary>
+        /// <param name="context"></param>
+        /// <returns></returns>
+        public static int GetFromPort(this HttpContext context)
+        {
+            return context.Connection.RemotePort;
+        }
+        /// <summary>
+        /// 根据键获取请求的查询参数的值
+        /// </summary>
+        /// <param name="context"></param>
+        /// <param name="strKey"></param>
+        /// <returns></returns>
+        public static string? GetQueryValue(this HttpContext context, string strKey)
+        {
+            return context.Request.Query[strKey];
+        }
+        /// <summary>
+        /// 获取请求的参数json,不分请求方式
+        /// </summary>
+        /// <param name="context"></param>
+        /// <returns></returns>
+        public static async Task<string> GetParamJson(this HttpContext context)
+        {
+            string strParamJson = string.Empty;
+            string strMethod = context.GetMethod();
+            switch (strMethod)
+            {
+                case "GET":
+                case "DELETE":
+                    strParamJson = context.GetQueryJson();
+                    break;
+                case "PUT":
+                case "POST":
+                    strParamJson = await context.GetBodyJson();
+                    break;
+            }
+            return strParamJson;
+        }
+        /// <summary>
+        /// 获取请求的查询参数json
+        /// </summary>
+        /// <param name="context"></param>
+        /// <returns></returns>
+        public static string GetQueryJson(this HttpContext context)
+        {
+            JObject jo = new JObject();
+            foreach (string strKey in context.Request.Query.Keys)
+            {
+                jo.Add(strKey, context.Request.Query[strKey].ToString());
+            }
+            return jo.ToJson();
+        }
+        /// <summary>
+        /// 获取请求的body参数json
+        /// </summary>
+        /// <param name="context"></param>
+        /// <returns></returns>
+        public static async Task<string> GetBodyJson(this HttpContext context)
+        {
+            StreamReader stream = new StreamReader(context.Request.Body);
+            string strRawJson = await stream.ReadToEndAsync();
+            return JsonConvert.DeserializeObject(strRawJson).ToJson();
+        }
+    }
+}

+ 82 - 0
Extensions/IntExtension.cs

@@ -0,0 +1,82 @@
+using System.Numerics;
+
+namespace Alchemy.Core.Extensions
+{
+    public static class IntExtension
+    {
+        /// <summary>
+        /// 整出取余
+        /// </summary>
+        /// <param name="timerCount"></param>
+        /// <param name="timerInterval"></param>
+        /// <returns></returns>
+        public static bool RemainderSuccess(this int timerCount, int timerInterval)
+        {
+            return BigInteger.Remainder(new BigInteger(timerCount), new BigInteger(timerInterval)).Equals(0);
+        }
+        /// <summary>
+        /// 判断是否合规端口
+        /// </summary>
+        /// <param name="param"></param>
+        /// <returns></returns>
+        public static bool IsPort(this int param)
+        {
+            if (param >= 1 && param <= 65535)
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+        /// <summary>
+        /// 判断是否合规正整数和零
+        /// </summary>
+        /// <param name="param"></param>
+        /// <returns></returns>
+        public static bool IsIntNotNegative(this int param)
+        {
+            if (param >= 0)
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+        /// <summary>
+        /// 判断是否合规月份数
+        /// </summary>
+        /// <param name="param"></param>
+        /// <returns></returns>
+        public static bool IsMonth(this int param)
+        {
+            if (param >= 1 && param <= 12)
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+        /// <summary>
+        /// 判断是否合规正整数
+        /// </summary>
+        /// <param name="param"></param>
+        /// <returns></returns>
+        public static bool IsIntPositive(this int param)
+        {
+            if (param > 0)
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+    }
+}

+ 83 - 0
Extensions/JsonExtension.cs

@@ -0,0 +1,83 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+namespace Alchemy.Core.Extensions
+{
+    public static class JsonExtension
+    {
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="token"></param>
+        /// <returns></returns>
+        public static string GetValue(this JToken token)
+        {
+            string result = "null";
+            switch (token.Type)
+            {
+                case JTokenType.Null:
+                    result = "null";
+                    break;
+                case JTokenType.Boolean:
+                    result = $"{token}".ToLower();
+                    break;
+                case JTokenType.String:
+                    result = $"\"{token}\"";
+                    break;
+                default:
+                    result = $"{token}";
+                    break;
+            }
+            return result;
+        }
+        /// <summary>
+        /// Json字符串转换为实体对象
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        public static T? FromJson<T>(this string input)
+        {
+            try
+            {
+                return JsonConvert.DeserializeObject<T>(input);
+            }
+            catch
+            {
+                return default;
+            }
+        }
+        /// <summary>
+        /// 实体对象转换为Json字符串
+        /// </summary>
+        /// <param name="obj">对象</param>
+        /// <returns>Json字符串</returns>
+        public static string ToJson(this object? obj)
+        {
+            if (obj.IsNull())
+                return string.Empty;
+            return JsonConvert.SerializeObject(obj);
+        }
+        /// <summary>
+        /// 实体对象转换为Json格式化字符串
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <returns></returns>
+        public static string ToPrettyJson(this object obj)
+        {
+            if (obj.IsNull())
+                return string.Empty;
+            return JsonConvert.SerializeObject(obj, Formatting.Indented);
+        }
+        /// <summary>
+        /// 对象转安全Json字符串
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <returns></returns>
+        public static string ToSafeJson(this object obj)
+        {
+            if (obj.IsNull())
+                return string.Empty;
+            return JsonConvert.SerializeObject(obj).Replace("\"", "\\\"");
+        }
+    }
+}

+ 42 - 0
Extensions/LongExtension.cs

@@ -0,0 +1,42 @@
+namespace Alchemy.Core.Extensions
+{
+    public static class LongExtension
+    {
+        /// <summary>
+        /// 时间戳转DateTime
+        /// </summary>
+        /// <param name="timeStamp"></param>
+        /// <returns></returns>
+        public static DateTime ToDateTime(this long timeStamp)
+        {
+            DateTime dt = new DateTime(2000, 1, 1, 0, 0, 0);
+            try
+            {
+                dt = DateTimeOffset.FromUnixTimeSeconds(timeStamp).LocalDateTime;
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
+            return dt;
+        }
+        /// <summary>
+        /// 时间戳转DateTimeUtc
+        /// </summary>
+        /// <param name="timeStamp"></param>
+        /// <returns></returns>
+        public static DateTime ToDateTimeUtc(this long timeStamp)
+        {
+            DateTime dt = new DateTime(2000, 1, 1, 0, 0, 0);
+            try
+            {
+                dt = DateTimeOffset.FromUnixTimeSeconds(timeStamp).DateTime;
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
+            return dt;
+        }
+    }
+}

+ 19 - 0
Extensions/ObjectExtension.cs

@@ -0,0 +1,19 @@
+namespace Alchemy.Core.Extensions
+{
+    public static class ObjectExtension
+    {
+        /// <summary>
+        /// 判断对象是否为null
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <returns></returns>
+        public static bool IsNull(this object? obj)
+        {
+            return obj is null;
+        }
+        public static bool IsNotNull(this object? obj)
+        {
+            return !obj.IsNull();
+        }
+    }
+}

+ 217 - 0
Extensions/StringExtension.cs

@@ -0,0 +1,217 @@
+using Alchemy.Core.Services;
+
+namespace Alchemy.Core.Extensions
+{
+    public static class StringExtension
+    {
+        /// <summary>
+        /// 字符串转Double
+        /// </summary>
+        /// <param name="strInput"></param>
+        /// <returns></returns>
+        public static double ToDouble(this string? strInput)
+        {
+            if (strInput.IsNull())
+                return -1;
+            bool result = double.TryParse(strInput, out double number);
+            if (result)
+                return number;
+            else
+                return -1;
+        }
+        /// <summary>
+        /// 字符串转Long
+        /// </summary>
+        /// <param name="strInput"></param>
+        /// <returns></returns>
+        public static long ToLong(this string? strInput)
+        {
+            if (strInput.IsNull())
+                return -1;
+            bool result = long.TryParse(strInput, out long number);
+            if (result)
+                return number;
+            else
+                return -1;
+        }
+        /// <summary>
+        /// 字符串转Int
+        /// </summary>
+        /// <param name="strInput"></param>
+        /// <returns></returns>
+        public static int ToInt(this string? strInput)
+        {
+            if (strInput.IsNull())
+                return -1;
+            bool result = int.TryParse(strInput, out int number);
+            if (result)
+                return number;
+            else
+                return -1;
+        }
+        /// <summary>
+        /// 字符串转Float
+        /// </summary>
+        /// <param name="strInput"></param>
+        /// <returns></returns>
+        public static float ToFloat(this string? strInput)
+        {
+            if (strInput.IsNull())
+                return -1;
+            bool result = float.TryParse(strInput, out float number);
+            if (result)
+                return number;
+            else
+                return -1;
+        }
+        /// <summary>
+        /// 字符串转布尔值
+        /// </summary>
+        /// <param name="strInput"></param>
+        /// <returns></returns>
+        public static bool ToBool(this string? strInput)
+        {
+            if (strInput.IsNull())
+                return false;
+            return bool.Parse(strInput);
+        }
+        /// <summary>
+        /// 字符串转字节
+        /// </summary>
+        /// <param name="strInput"></param>
+        /// <returns></returns>
+        public static byte ToByte(this string strInput)
+        {
+            return Convert.ToByte(strInput);
+        }
+        /// <summary>
+        /// 字符串转日期格式
+        /// </summary>
+        /// <param name="strDt"></param>
+        /// <returns></returns>
+        public static DateTime ToDt(this string strDt)
+        {
+            strDt = strDt.Replace("-0", "/");
+            strDt = strDt.Replace("-", "/");
+            return DateTime.Parse(strDt);
+        }
+        /// <summary>
+        /// 字符串日期转时间戳
+        /// </summary>
+        /// <param name="strDateTime"></param>
+        /// <returns></returns>
+        public static long ToTimeStamp(this string strDateTime)
+        {
+            long timeStamp = 946656000;
+            try
+            {
+                timeStamp = (Convert.ToDateTime(strDateTime).Ticks - TimeZoneInfo.ConvertTimeFromUtc(new DateTime(1970, 1, 1), TimeZoneInfo.Local).Ticks) / 10000000;
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
+            return timeStamp;
+        }
+        /// <summary>
+        /// 字符串是否为空
+        /// </summary>
+        /// <param name="strParam"></param>
+        /// <returns></returns>
+        public static bool IsNull(this string? strParam)
+        {
+            return string.IsNullOrEmpty(strParam);
+        }
+        public static bool IsNotNull(this string? strParam)
+        {
+            return !string.IsNullOrEmpty(strParam);
+        }
+        /// <summary>
+        /// 判断是否合规日期时间字符串
+        /// </summary>
+        /// <param name="strParam"></param>
+        /// <returns></returns>
+        public static bool IsDateTime(this string strParam)
+        {
+            if (strParam.IsNull())
+                return false;
+            return RegexService.IsMatch(strParam, @"^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d$");
+        }
+        /// <summary>
+        /// 判断是否合规日期字符串
+        /// </summary>
+        /// <param name="strParam"></param>
+        /// <returns></returns>
+        public static bool IsDate(this string strParam)
+        {
+            if (strParam.IsNull())
+                return false;
+            return RegexService.IsMatch(strParam, @"^((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29))$");
+        }
+        /// <summary>
+        /// 判断是否合规IP地址或域名
+        /// </summary>
+        /// <param name="strParam"></param>
+        /// <returns></returns>
+        public static bool IsIPorDomain(this string strParam)
+        {
+            if (strParam.IsNull())
+                return false;
+            bool value = strParam.IsIPv4();
+            if (!value)
+            {
+                if (strParam.Contains("."))
+                {
+                    value = true;
+                }
+            }
+            return value;
+        }
+        /// <summary>
+        /// 检测是否IP地址
+        /// </summary>
+        /// <param name="strIP"></param>
+        /// <returns></returns>
+        public static bool IsIPv4(this string strIP)
+        {
+            if (strIP.IsNull())
+                return false;
+            if (strIP.Length < 7 || strIP.Length > 15)
+                return false;
+            string pattern = @"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$";
+            return RegexService.IsMatch(strIP, pattern);
+        }
+        /// <summary>
+        /// 检测是否手机号
+        /// </summary>
+        /// <param name="strMobilePhone"></param>
+        /// <returns></returns>
+        public static bool IsMobilePhone(this string strMobilePhone)
+        {
+            string pattern = @"^1[3-9]\d{9}$";
+            return RegexService.IsMatch(strMobilePhone, pattern);
+        }
+        /// <summary>
+        /// 判断是否版本号
+        /// </summary>
+        /// <param name="strParam"></param>
+        /// <returns></returns>
+        public static bool IsVersion(this string strParam)
+        {
+            bool value = false;
+            if (strParam.Contains("."))
+            {
+                string[] arrVer = strParam.Split('.');
+                if (arrVer.Length > 1)
+                {
+                    value = true;
+                    foreach (string strVerNum in arrVer)
+                    {
+                        value = value & int.TryParse(strVerNum, out int verNum);
+                    }
+                }
+            }
+            return value;
+        }
+    }
+}

+ 21 - 0
LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2024 焦糖蚂拐
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 2 - 0
README.md

@@ -0,0 +1,2 @@
+# Alchemy.Core
+A terrible .NET Core back-end framework.

+ 95 - 0
Services/ApiClientService.cs

@@ -0,0 +1,95 @@
+using Alchemy.Core.Extensions;
+using Newtonsoft.Json.Linq;
+using RestSharp;
+namespace Alchemy.Core.Services
+{
+    public static class ApiClientService
+    {
+        /// <summary>
+        /// 发起API请求
+        /// </summary>
+        /// <param name="reqMethod"></param>
+        /// <param name="strBaseUrl"></param>
+        /// <param name="strRouteUrl"></param>
+        /// <param name="queryParam"></param>
+        /// <param name="body"></param>
+        /// <param name="headerList"></param>
+        /// <param name="timeOut"></param>
+        /// <returns></returns>
+        public static ApiResponse Request(Method reqMethod, string strBaseUrl, string strRouteUrl = null, Dictionary<string, string> queryParam = null, object body = null, Dictionary<string, string> headerList = null, string strContentType = "application/json", int timeOut = 3)
+        {
+            ApiResponse resp = new ApiResponse()
+            {
+                StatusCode = -1,
+                Content = string.Empty
+            };
+            RestClient client = new RestClient(strBaseUrl);
+            if (queryParam is not null)
+            {
+                if (queryParam.Count > 0)
+                    strRouteUrl += "?";
+                int index = 0;
+                foreach (KeyValuePair<string, string> kvp in queryParam)
+                {
+                    strRouteUrl += $"{System.Web.HttpUtility.UrlEncode(kvp.Key)}={System.Web.HttpUtility.UrlEncode(kvp.Value)}";
+                    if (index < queryParam.Count - 1)
+                        strRouteUrl += "&";
+                    index++;
+                }
+            }
+            RestRequest request = new RestRequest(strRouteUrl, reqMethod);
+            if (headerList is not null)
+            {
+                foreach (KeyValuePair<string, string> kvp in headerList)
+                {
+                    request.AddHeader(kvp.Key, kvp.Value);
+                }
+            }
+            request.Timeout = TimeSpan.FromSeconds(timeOut);
+            if (!body.IsNull())
+            {
+                if (body is JObject && strContentType.StartsWith("application/json"))
+                {
+                    request.AddHeader("Content-Type", strContentType);
+                    request.RequestFormat = DataFormat.Json;
+                    request.AddJsonBody(body.ToJson());
+                }
+                if (body is JObject && strContentType.StartsWith("multipart/form-data"))
+                {
+                    JObject jo = (JObject)body;
+                    foreach (JProperty? jp in jo.Properties())
+                    {
+                        if (jp.IsNull())
+                            continue;
+                        if (jp.Name.Equals("size"))
+                            request.AddParameter(jp.Name, jp.Value.ToString().ToLong());
+                        if (!jp.Name.Equals("file"))
+                            request.AddParameter(jp.Name, jp.Value.ToString());
+                        else
+                            request.AddFile("file", jp.Value.ToString());
+                    }
+                }
+            }
+            string strResp = string.Empty;
+            try
+            {
+                RestResponse<ApiResponse> response = client.Execute<ApiResponse>(request);
+                if (response is not null)
+                {
+                    resp.StatusCode = (int)response.StatusCode;
+                    resp.Content = response.Content;
+                }
+            }
+            catch (Exception ex)
+            {
+                resp.Content = ex.Message;
+            }
+            return resp;
+        }
+    }
+    public class ApiResponse
+    {
+        public int StatusCode { get; set; }
+        public string Content { get; set; }
+    }
+}

+ 44 - 0
Services/ConvertService.cs

@@ -0,0 +1,44 @@
+using Alchemy.Core.Extensions;
+using System.Reflection;
+namespace Alchemy.Core.Services
+{
+    public class ConvertService
+    {
+        /// <summary>
+        /// 字节数组转换为16进制表示的字符串
+        /// </summary>
+        public static string ByteArrayToHexString(byte[] buf)
+        {
+            string returnStr = string.Empty;
+            if (buf.IsNotNull())
+            {
+                for (int i = 0; i < buf.Length; i++)
+                {
+                    returnStr += buf[i].ToString("X2");
+                }
+            }
+            return returnStr;
+        }
+        /// <summary>
+        /// 类转换成IDic
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <returns></returns>
+        public static Dictionary<string, string> ObjToDictionary(object obj)
+        {
+            Type type = obj.GetType();
+            PropertyInfo[] properties = type.GetProperties();
+            Dictionary<string, string> dict = new Dictionary<string, string>();
+            foreach (PropertyInfo property in properties)
+            {
+                if (!property.CanRead || !property.CanWrite)
+                    continue;
+                object value = property.GetValue(obj);
+                string key = property.Name;
+                string strValue = value?.ToString();
+                dict[key] = strValue ?? string.Empty;
+            }
+            return dict;
+        }
+    }
+}

+ 407 - 0
Services/DateTimeService.cs

@@ -0,0 +1,407 @@
+using Alchemy.Core.Extensions;
+
+namespace Alchemy.Core.Services
+{
+    public class DateTimeService
+    {
+        /// <summary>
+        /// 获取当前日期的字符串
+        /// </summary>
+        /// <returns></returns>
+        public static string Now(bool hasSymbol = true)
+        {
+            if (hasSymbol)
+                return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+            else
+                return DateTime.Now.ToString("yyyyMMddHHmmss");
+        }
+        /// <summary>
+        /// 获取当前日期的字符串
+        /// </summary>
+        /// <returns></returns>
+        public static string Today()
+        {
+            return DateTime.Now.ToDateString();
+        }
+        /// <summary>
+        /// 获取当前日期的Dt
+        /// </summary>
+        /// <returns></returns>
+        public static DateTime DtNow()
+        {
+            return DateTime.Now;
+        }
+        /// <summary>
+        /// 获取当前日期的时间戳
+        /// </summary>
+        /// <returns></returns>
+        public static long TsNow()
+        {
+            return DateTime.Now.ToTimeStamp();
+        }
+        /// <summary>
+        /// 时间戳转日期格式
+        /// </summary>
+        /// <param name="timeStamp"></param>
+        /// <returns></returns>
+        public static DateTime TimeStampToDateTime(string timeStamp)
+        {
+            try
+            {
+                DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
+                long lTime = long.Parse(timeStamp + "0000000");
+                TimeSpan toNow = new TimeSpan(lTime);
+                return dateTimeStart.Add(toNow);
+            }
+            catch
+            {
+                return "2000-01-01 00:00:00".ToDt();
+            }
+        }
+        /// <summary>
+        /// 2000年的日期格式
+        /// </summary>
+        /// <returns></returns>
+        public static DateTime Dt2000()
+        {
+            return "2000-01-01 00:00:00".ToDt();
+        }
+        /// <summary>
+        /// 获取当前日期的年份,0000
+        /// </summary>
+        /// <returns></returns>
+        public static int ThisYear()
+        {
+            return DateTime.Now.Year;
+        }
+        /// <summary>
+        /// 获取当前日期的月份,1-12
+        /// </summary>
+        /// <returns></returns>
+        public static int ThisMonth()
+        {
+            return DateTime.Now.Month;
+        }
+        /// <summary>
+        /// 获取当前日期的天数,1-31
+        /// </summary>
+        /// <returns></returns>
+        public static int ThisDay()
+        {
+            return DateTime.Now.Day;
+        }
+        /// <summary>
+        /// 获取当前日期的年份,0000
+        /// </summary>
+        /// <returns></returns>
+        public static string ThisYearString()
+        {
+            return DateTime.Now.Year.ToString();
+        }
+        /// <summary>
+        /// 获取当前日期的月份,00
+        /// </summary>
+        /// <param name="prefix"></param>
+        /// <returns></returns>
+        public static string ThisMonthString(bool prefix = false)
+        {
+            int mon = DateTime.Now.Month;
+            string value = mon.ToString();
+            if (prefix)
+            {
+                if (mon < 10)
+                {
+                    return "0" + value;
+                }
+                else
+                {
+                    return value;
+                }
+            }
+            else
+            {
+                return value;
+            }
+        }
+        /// <summary>
+        /// 获取当前日期的上个月,00
+        /// </summary>
+        /// <param name="prefix"></param>
+        /// <returns></returns>
+        public static string LastMonthString(bool prefix = false)
+        {
+            int mon = DateTime.Now.Month - 1;
+            if (mon == 0)
+            {
+                mon = 12;
+            }
+            string value = mon.ToString();
+            if (prefix)
+            {
+                if (mon < 10)
+                {
+                    return "0" + value;
+                }
+                else
+                {
+                    return value;
+                }
+            }
+            else
+            {
+                return value;
+            }
+        }
+        /// <summary>
+        /// 获取当前日期的天数,00
+        /// </summary>
+        /// <param name="prefix"></param>
+        /// <returns></returns>
+        public static string ThisDayString(bool prefix = false)
+        {
+            int day = DateTime.Now.Day;
+            string value = day.ToString();
+            if (prefix)
+            {
+                if (day < 10)
+                {
+                    return "0" + value;
+                }
+                else
+                {
+                    return value;
+                }
+            }
+            else
+            {
+                return value;
+            }
+        }
+        /// <summary>
+        /// 判断日期是否是今年
+        /// </summary>
+        /// <param name="strDt"></param>
+        /// <returns></returns>
+        public static bool InThisYear(string strDt)
+        {
+            if (strDt.Substring(0, 4) == ThisYearString())
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+        /// <summary>
+        /// 判断日期是否是这个半年
+        /// </summary>
+        /// <param name="strDt"></param>
+        /// <returns></returns>
+        public static bool InThisHalfYear(string strDt)
+        {
+            if (strDt.Substring(0, 4) == ThisYearString())
+            {
+                string strMon = strDt.Substring(5, 2);
+                if (strMon.Substring(0, 1) == "0")
+                {
+                    strMon = strMon.Substring(1, 1);
+                }
+                int mon = int.Parse(strMon);
+                int thisMon = ThisMonth();
+                if (thisMon <= 6)
+                {
+                    if (mon <= 6)
+                    {
+                        return true;
+                    }
+                    else
+                    {
+                        return false;
+                    }
+                }
+                else
+                {
+                    if (mon >= 7)
+                    {
+                        return true;
+                    }
+                    else
+                    {
+                        return false;
+                    }
+                }
+            }
+            else
+            {
+                return false;
+            }
+        }
+        /// <summary>
+        /// 判断日期是否是本月
+        /// </summary>
+        /// <param name="strDt"></param>
+        /// <returns></returns>
+        public static bool InThisMonth(string strDt)
+        {
+            if (strDt.Substring(5, 2) == ThisMonthString(true))
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+        /// <summary>
+        /// 判断日期是否是上个月
+        /// </summary>
+        /// <param name="strDt"></param>
+        /// <returns></returns>
+        public static bool InLastMonth(string strDt)
+        {
+            if (strDt.Substring(5, 2) == LastMonthString(true))
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+        /// <summary>
+        /// 判断日期是否是今天
+        /// </summary>
+        /// <param name="strDt"></param>
+        /// <returns></returns>
+        public static bool IsToday(string strDt)
+        {
+            if (strDt == Today())
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+        /// <summary>
+        /// 计算时间差
+        /// </summary>
+        /// <param name="dtStart"></param>
+        /// <param name="dtEnd"></param>
+        /// <returns></returns>
+        public static TimeSpan DiffTimeSpan(DateTime dtStart, DateTime dtEnd)
+        {
+            TimeSpan ts = new TimeSpan();
+            ts = dtEnd - dtStart;
+            return ts;
+        }
+        /// <summary>
+        /// 计算时间差,天数
+        /// </summary>
+        /// <param name="dtStart"></param>
+        /// <param name="dtEnd"></param>
+        /// <returns></returns>
+        public static double DiffDays(DateTime dtStart, DateTime dtEnd)
+        {
+            double days = 0;
+            TimeSpan ts = DiffTimeSpan(dtStart, dtEnd);
+            days = ts.TotalDays;
+            return days;
+        }
+        /// <summary>
+        /// 计算时间差,小时数
+        /// </summary>
+        /// <param name="dtStart"></param>
+        /// <param name="dtEnd"></param>
+        /// <returns></returns>
+        public static double DiffHrs(DateTime dtStart, DateTime dtEnd)
+        {
+            double hrs = 0;
+            TimeSpan ts = DiffTimeSpan(dtStart, dtEnd);
+            hrs = ts.TotalHours;
+            return hrs;
+        }
+        /// <summary>
+        /// 计算时间差,分钟数
+        /// </summary>
+        /// <param name="dtStart"></param>
+        /// <param name="dtEnd"></param>
+        /// <returns></returns>
+        public static double DiffMins(DateTime dtStart, DateTime dtEnd)
+        {
+            double mins = 0;
+            TimeSpan ts = DiffTimeSpan(dtStart, dtEnd);
+            mins = ts.TotalMinutes;
+            return mins;
+        }
+        /// <summary>
+        /// 计算时间差,秒数
+        /// </summary>
+        /// <param name="dtStart"></param>
+        /// <param name="dtEnd"></param>
+        /// <returns></returns>
+        public static double DiffSecs(DateTime dtStart, DateTime dtEnd)
+        {
+            double secs = 0;
+            TimeSpan ts = DiffTimeSpan(dtStart, dtEnd);
+            secs = ts.TotalSeconds;
+            return secs;
+        }
+        /// <summary>
+        /// 计算时间差,毫秒数
+        /// </summary>
+        /// <param name="dtStart"></param>
+        /// <param name="dtEnd"></param>
+        /// <returns></returns>
+        public static double DiffMs(DateTime dtStart, DateTime dtEnd)
+        {
+            double ms = 0;
+            TimeSpan ts = DiffTimeSpan(dtStart, dtEnd);
+            ms = ts.TotalMilliseconds;
+            return ms;
+        }
+        /// <summary>
+        /// 判断时间是否在范围内
+        /// </summary>
+        /// <param name="myDt"></param>
+        /// <param name="dtStart"></param>
+        /// <param name="dtEnd"></param>
+        /// <returns></returns>
+        public static bool DateInRange(DateTime myDt, DateTime dtStart, DateTime dtEnd)
+        {
+            bool value = false;
+            double diff1 = DiffSecs(dtStart, myDt);
+            if (diff1 >= 0)
+            {
+                double diff2 = DiffSecs(myDt, dtEnd);
+                if (diff2 >= 0)
+                {
+                    value = true;
+                }
+            }
+            return value;
+        }
+        /// <summary>
+        /// 获取时间戳
+        /// </summary>
+        /// <returns></returns>
+        public static string TimeStamp(int length = 10)
+        {
+            string value = string.Empty;
+            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
+            switch (length)
+            {
+                default:
+                case 10:
+                    value = Convert.ToInt64(ts.TotalSeconds).ToString();
+                    break;
+                case 13:
+                    value = Convert.ToInt64(ts.TotalMilliseconds).ToString();
+                    break;
+            }
+            return value;
+        }
+    }
+}

+ 31 - 0
Services/FileService.cs

@@ -0,0 +1,31 @@
+using System.Text;
+namespace Alchemy.Core.Services
+{
+    public class FileService
+    {
+        //编码格式:去除BOM头的UTF8
+        private static Encoding _enc = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
+        /// <summary>
+        /// 读取文件内容
+        /// </summary>
+        /// <param name="strFilePath"></param>
+        /// <returns></returns>
+        public static string ReadAll(string strFilePath)
+        {
+            FileInfo fileInfo = new FileInfo(strFilePath);
+            if (fileInfo.Exists)
+                return File.ReadAllText(strFilePath, _enc);
+            else
+                return string.Empty;
+        }
+        /// <summary>
+        /// 写入文件内容
+        /// </summary>
+        /// <param name="strFilePath"></param>
+        /// <param name="strContent"></param>
+        public static void WriteAll(string strFilePath, string strContent)
+        {
+            File.WriteAllText(strFilePath, strContent, _enc);
+        }
+    }
+}

+ 17 - 0
Services/GenService.cs

@@ -0,0 +1,17 @@
+namespace Alchemy.Core.Services
+{
+    public class GenService
+    {
+        public static string GenNumberCode(int degit)
+        {
+            if (degit > 1)
+            {
+                Random random = new Random();
+                string code = random.Next(10 ^ degit - 1, 10 ^ degit).ToString();
+                return code.PadLeft(degit, '0');
+            }
+            else
+                return "0";
+        }
+    }
+}

+ 186 - 0
Services/JsonService.cs

@@ -0,0 +1,186 @@
+using Alchemy.Core.Extensions;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
+namespace Alchemy.Core.Services
+{
+    public class JsonService
+    {
+        /// <summary>
+        /// 写入JSON
+        /// </summary>
+        /// <param name="fi"></param>
+        /// <param name="strValue"></param>
+        public static void WriteJson(FileInfo fi, string strValue)
+        {
+            WriteJson(fi.FullName, strValue);
+        }
+        /// <summary>
+        /// 写入JSON
+        /// </summary>
+        /// <param name="strJsonPath"></param>
+        /// <param name="strValue"></param>
+        public static void WriteJson(string strJsonPath, string strValue)
+        {
+            JObject jo = strValue.FromJson<JObject>();
+            string output = JsonConvert.SerializeObject(jo, Formatting.Indented);
+            File.WriteAllText(strJsonPath, output);
+        }
+        /// <summary>
+        /// 写入JSON
+        /// </summary>
+        /// <param name="fi"></param>
+        /// <param name="strValue"></param>
+        public static void WriteJsonArray(FileInfo fi, string strValue)
+        {
+            WriteJsonArray(fi.FullName, strValue);
+        }
+        /// <summary>
+        /// 写入JSON
+        /// </summary>
+        /// <param name="strJsonPath"></param>
+        /// <param name="strValue"></param>
+        public static void WriteJsonArray(string strJsonPath, string strValue)
+        {
+            JArray ja = strValue.FromJson<JArray>();
+            string output = JsonConvert.SerializeObject(ja, Formatting.Indented);
+            File.WriteAllText(strJsonPath, output);
+        }
+        /// <summary>
+        /// 读取文件路径,写入Json内容
+        /// </summary>
+        /// <param name="fi"></param>
+        /// <param name="strKey"></param>
+        /// <param name="strValue"></param>
+        public static void SetJson(FileInfo fi, string strKey, string strValue)
+        {
+            string strJson = File.ReadAllText(fi.FullName);
+            SetJson(fi.FullName, strJson, strKey, strValue);
+        }
+        /// <summary>
+        /// 读取文件路径,写入Json内容
+        /// </summary>
+        /// <param name="strJsonPath"></param>
+        /// <param name="strJson"></param>
+        /// <param name="strKey"></param>
+        /// <param name="strValue"></param>
+        public static void SetJson(string strJsonPath, string strJson, string strKey, string strValue)
+        {
+            JObject jo = strJson.FromJson<JObject>();
+            jo[strKey] = strValue.FromJson<JToken>();
+            string output = JsonConvert.SerializeObject(jo, Formatting.Indented);
+            File.WriteAllText(strJsonPath, output);
+        }
+        /// <summary>
+        /// 读取文件路径,写入Json内容
+        /// </summary>
+        /// <param name="fi"></param>
+        /// <param name="strKey"></param>
+        /// <param name="strValue"></param>
+        public static void SetValue(FileInfo fi, string strKey, string strValue)
+        {
+            string strJson = FileService.ReadAll(fi.FullName);
+            SetValue(fi.FullName, strJson, strKey, strValue);
+        }
+        /// <summary>
+        /// 读取文件路径,写入Json内容
+        /// </summary>
+        /// <param name="strJsonPath"></param>
+        /// <param name="strJson"></param>
+        /// <param name="strKey"></param>
+        /// <param name="strValue"></param>
+        public static void SetValue(string strJsonPath, string strJson, string strKey, string strValue)
+        {
+            JObject jo = (JObject)JsonConvert.DeserializeObject(strJson);
+            jo[strKey] = strValue;
+            string output = JsonConvert.SerializeObject(jo, Formatting.Indented);
+            FileService.WriteAll(strJsonPath, output);
+        }
+        /// <summary>
+        /// 读取文件路径,获取Json内容
+        /// </summary>
+        /// <param name="strFilePath"></param>
+        /// <returns></returns>
+        public static string GetAllContent(string strFilePath)
+        {
+            return FileService.ReadAll(strFilePath);
+        }
+        /// <summary>
+        /// 读取文件路径,获取Json内容
+        /// </summary>
+        /// <param name="fi"></param>
+        /// <returns></returns>
+        public static string GetAllContent(FileInfo fi)
+        {
+            return GetAllContent(fi.FullName);
+        }
+        /// <summary>
+        /// 读取文件路径,从Json字符串的对象中获取Json字符串
+        /// </summary>
+        /// <param name="fi"></param>
+        /// <param name="strKey"></param>
+        /// <returns></returns>
+        public static string GetJson(FileInfo fi, string strKey)
+        {
+            string strJson = FileService.ReadAll(fi.FullName);
+            return GetJson(strJson, strKey);
+        }
+        /// <summary>
+        /// 读取文件内容,从Json字符串的对象中获取Json字符串
+        /// </summary>
+        /// <param name="strJson"></param>
+        /// <param name="strKey"></param>
+        /// <returns></returns>
+        public static string GetJson(string strJson, string strKey)
+        {
+            JObject jo = (JObject)JsonConvert.DeserializeObject(strJson);
+            return jo[strKey].ToJson();
+        }
+        /// <summary>
+        /// 读取文件路径,从Json字符串的对象中获取值
+        /// </summary>
+        /// <param name="fi"></param>
+        /// <param name="strKey"></param>
+        /// <returns></returns>
+        public static string GetValue(FileInfo fi, string strKey)
+        {
+            string strJson = FileService.ReadAll(fi.FullName);
+            return GetValue(strJson, strKey);
+        }
+        /// <summary>
+        /// 读取文件内容,从Json字符串的对象中获取值
+        /// </summary>
+        /// <param name="strJson"></param>
+        /// <param name="strKey"></param>
+        /// <returns></returns>
+        public static string GetValue(string strJson, string strKey)
+        {
+            JObject jo = (JObject)JsonConvert.DeserializeObject(strJson);
+            return jo[strKey].ToString();
+        }
+        /// <summary>
+        /// 读取文件路径,从Json字符串的数组中获取值
+        /// </summary>
+        /// <param name="fi"></param>
+        /// <param name="index"></param>
+        /// <param name="strKey"></param>
+        /// <returns></returns>
+        public static string GetValue(FileInfo fi, int index, string strKey)
+        {
+            string strJson = FileService.ReadAll(fi.FullName);
+            return GetValue(strJson, index, strKey);
+        }
+        /// <summary>
+        /// 读取文件内容,从Json字符串的数组中获取值
+        /// </summary>
+        /// <param name="strJson"></param>
+        /// <param name="index"></param>
+        /// <param name="strKey"></param>
+        /// <returns></returns>
+        public static string GetValue(string strJson, int index, string strKey)
+        {
+            JArray ja = (JArray)JsonConvert.DeserializeObject(strJson);
+            return ja[index][strKey]?.ToJson();
+        }
+    }
+}

+ 59 - 0
Services/JwtService.cs

@@ -0,0 +1,59 @@
+using Alchemy.Core.Extensions;
+using Microsoft.IdentityModel.Tokens;
+using System.IdentityModel.Tokens.Jwt;
+using System.Security.Claims;
+using System.Text;
+
+namespace Alchemy.Core.Services
+{
+    public class JwtService
+    {
+        public static string GenerateJwtToken(string strSecretKey, string strIssuer, string strAudience, Dictionary<string, object> claims, int expireInMinutes)
+        {
+            var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(strSecretKey));
+            var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
+            var tokenDescriptor = new SecurityTokenDescriptor
+            {
+                Issuer = strIssuer,
+                Audience = strAudience,
+                SigningCredentials = credentials,
+                Claims = claims,
+                Expires = DateTime.UtcNow.AddMinutes(expireInMinutes)
+            };
+            var tokenHandler = new JwtSecurityTokenHandler();
+            var token = tokenHandler.CreateToken(tokenDescriptor);
+            var tokenString = tokenHandler.WriteToken(token);
+            return tokenString;
+        }
+        public static bool DecodeJwtToken(string strSecretKey, string strToken, out List<Claim> claims)
+        {
+            bool result = false;
+            claims = new List<Claim>();
+            var handler = new JwtSecurityTokenHandler();
+            var validationParameters = new TokenValidationParameters
+            {
+                ValidateIssuerSigningKey = true,
+                IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(strSecretKey)),
+                ValidateIssuer = false,
+                ValidateAudience = false,
+                // 其他可能需要的验证参数
+            };
+            try
+            {
+                SecurityToken validatedToken;
+                var principal = handler.ValidateToken(strToken, validationParameters, out validatedToken);
+                var jwtToken = validatedToken as JwtSecurityToken;
+                if (jwtToken.IsNotNull())
+                {
+                    claims = jwtToken.Claims.ToList();
+                    result = true;
+                }
+            }
+            catch (Exception ex)
+            {
+                //Console.WriteLine($"Token validation failed: {ex.Message}");
+            }
+            return result;
+        }
+    }
+}

+ 18 - 0
Services/RegexService.cs

@@ -0,0 +1,18 @@
+using System.Text.RegularExpressions;
+namespace Alchemy.Core.Services
+{
+    public class RegexService
+    {
+        /// <summary>
+        /// 判断正则表达式
+        /// </summary>
+        /// <param name="strRaw"></param>
+        /// <param name="strFormat"></param>
+        /// <returns></returns>
+        public static bool IsMatch(string strRaw, string strFormat)
+        {
+            Regex regex = new Regex(strFormat, RegexOptions.None);
+            return regex.IsMatch(strRaw);
+        }
+    }
+}

+ 7 - 0
Services/ValidService.cs

@@ -0,0 +1,7 @@
+namespace Alchemy.Core.Services
+{
+    public class ValidService
+    {
+
+    }
+}