From 04956fce30bded82267844718fa5e4e04148e487 Mon Sep 17 00:00:00 2001
From: 移动系统liao <liaoxujun@qq.com>
Date: 星期三, 14 八月 2024 14:11:44 +0800
Subject: [PATCH] no message
---
cylsg/EzWechat/WechatConfig.json | 7
cylsg/cylsg.services/cylsg.services.csproj | 14
cylsg/cylsg.Application/System/Services/ISystemService.cs | 2
.gitignore | 7
cylsg/cylsg.Web.Core/cylsg.Web.Core.csproj | 1
cylsg/cylsg.redis/RedisConfig.json | 8
cylsg/cylsg.Authorization/cylsg.Authorization.csproj | 15
cylsg/cylsg.Authorization/cylsgException.cs | 34 +
cylsg/cylsg.redis/IEzCoreNetRedisService.cs | 80 ++
cylsg/cylsg.sln | 24
cylsg/cylsg.Web.Core/Startup.cs | 7
cylsg/EzUpFiles/EzFileUploadService.cs | 709 +++++++++++++++++++++++
cylsg/cylsg.redis/opentions.cs | 23
cylsg/EzUpFiles/IEzFileUploadService.cs | 30 +
cylsg/cylsg.Web.Entry/appsettings.json | 27
cylsg/EzWechat/EzWechat.csproj | 17
cylsg/cylsg.Web.Core/cylsg.Web.Core.xml | 89 ++
cylsg/cylsg.redis/EzCoreNetRedisService.cs | 104 +++
cylsg/cylsg.Web.Core/Handlers/JwtHandler.cs | 2
cylsg/EzWechat/IWechatService.cs | 13
cylsg/cylsg.redis/cylsg.redis.csproj | 17
cylsg/EzWechat/WechatService.cs | 36 +
cylsg/cylsg.Authorization/IEzAuthorizationService.cs | 40 +
cylsg/EzWechat/Startup.cs | 22
cylsg/cylsg.Authorization/Startup.cs | 21
cylsg/EzUpFiles/EzUpFiles.csproj | 9
cylsg/cylsg.Application/System/Services/SystemService.cs | 2
cylsg/cylsg.Authorization/EzAuthorizationService.cs | 154 +++++
cylsg/cylsg.Authorization/EzJwtModel.cs | 38 +
cylsg/cylsg.Web.Core/Handlers/EzCoreRESTFulResultProvider.cs | 174 +++++
cylsg/cylsg.redis/Startup.cs | 53 +
31 files changed, 1,768 insertions(+), 11 deletions(-)
diff --git a/.gitignore b/.gitignore
index d625e6b..6d2e95a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,10 @@
cylsg/cylsg.Web.Core/obj/
cylsg/cylsg.Web.Entry/bin/
cylsg/cylsg.Web.Entry/obj/
+cylsg/cylsg.Authorization/bin/
+cylsg/cylsg.Authorization/obj/
+cylsg/cylsg.redis/obj/
+cylsg/cylsg.services/obj/
+cylsg/EzUpFiles/obj/
+cylsg/EzWechat/obj/
+cylsg/cylsg.redis/bin/
diff --git a/cylsg/EzUpFiles/EzFileUploadService.cs b/cylsg/EzUpFiles/EzFileUploadService.cs
new file mode 100644
index 0000000..9cb626b
--- /dev/null
+++ b/cylsg/EzUpFiles/EzFileUploadService.cs
@@ -0,0 +1,709 @@
+锘縰sing Aliyun.OSS;
+using Aliyun.OSS.Util;
+using COSXML;
+using COSXML.Auth;
+using EzCoreNet.Utility;
+using EzCoreNet.Utility.Extend;
+using EzCoreNetFurion.IServices;
+using EzCoreNetFurion.IServices.SysSet;
+using EzCoreNetFurion.Model.Emun;
+using Furion;
+using Furion.DependencyInjection;
+using Furion.FriendlyException;
+using Microsoft.AspNetCore.Http;
+using Qiniu.Storage;
+using Qiniu.Util;
+using SqlSugar;
+using System.Globalization;
+namespace EzUpFiles
+{
+ /// <summary>
+ /// 闄勪欢鏈嶅姟绋嬪簭
+ /// </summary>
+ public class EzFileUploadService : IEzFileUploadService, IScoped
+ {
+ private readonly ISYSSettingService _SYSSetting;
+ private readonly HttpRequest? _request;
+ private readonly ISqlSugarClient _sqlSugarClient;
+ public EzFileUploadService(ISYSSettingService sYSSetting, IHttpContextAccessor httpContext, ISqlSugarClient sqlSugarClient)
+ {
+ _SYSSetting = sYSSetting;
+ _request = httpContext.HttpContext?.Request ?? null;
+ _sqlSugarClient = sqlSugarClient;
+ }
+
+ /// <summary>
+ /// 涓婁紶闄勪欢
+ /// </summary>
+ /// <returns></returns>
+ public async Task<string> UploadFiles()
+ {
+ var op = _SYSSetting.GetAttachmentSetting();
+ if (op == null)
+ throw Oops.Oh("浣犳病鏈夊闄勪欢淇濆瓨杩涜璁剧疆锛岃璁剧疆闄勪欢淇濆瓨");
+ var maxSize = 1024 * 1024 * (op.AttachmentSaveFileSize?.toInt() ?? 0); //涓婁紶澶у皬5M
+
+ var file = _request?.Form?.Files["file"];
+ if (file == null)
+ {
+ throw Oops.Oh("浣犳病鏈夐�夋嫨鏂囦欢");
+ }
+
+ var fileName = file.FileName;
+ var fileExt = Path.GetExtension(fileName).ToLowerInvariant();
+
+ //妫�鏌ュぇ灏�
+ if (file.Length > maxSize)
+ {
+ throw Oops.Oh("鏂囦欢澶т簬璁剧疆鏂囦欢");
+ }
+
+ //妫�鏌ユ枃浠舵墿灞曞悕
+ if (string.IsNullOrEmpty(fileExt) || Array.IndexOf(op.AttachmentSaveFileExtName?.Split(',') ?? new string[] { "" }, fileExt.Substring(1).ToLower()) == -1)
+ {
+ throw Oops.Oh("涓婁紶鏂囦欢鎵╁睍鍚嶆槸涓嶅厑璁哥殑鎵╁睍鍚�,璇蜂笂浼犲悗缂�鍚嶄负锛�" + op.AttachmentSaveFileExtName);
+
+ }
+
+ string url = string.Empty;
+ switch (op.AttachmentSaveMode)
+ {
+ case AttachmentSaveMode.AliOSS:
+ url = await UpLoadFileForAliYunOSS(op, fileExt, file);
+ break;
+ case AttachmentSaveMode.TencentCOS:
+ url = await UpLoadFileForQCloudOSS(op, fileExt, file);
+ break;
+ case AttachmentSaveMode.QiNiuKodo:
+ url = await UpLoadFileForQiNiuKoDo(op, fileExt, file);
+ break;
+ case AttachmentSaveMode.Logical:
+ url = await UpLoadFileForLocalStorage(op, fileExt, file);
+ break;
+ case AttachmentSaveMode.DataBase:
+ throw Oops.Oh("涓嶆敮鎸�");
+ break;
+ default:
+ break;
+ }
+
+
+ return url;
+
+
+ }
+
+ /// <summary>
+ /// 涓婁紶base64
+ /// </summary>
+ /// <param name="base64"></param>
+ /// <returns></returns>
+ public async Task<string> UploadFilesFByBase64(string base64)
+ {
+ var op = _SYSSetting.GetAttachmentSetting();
+ if (op == null)
+ throw Oops.Oh("浣犳病鏈夊闄勪欢淇濆瓨杩涜璁剧疆锛岃璁剧疆闄勪欢淇濆瓨");
+ if (string.IsNullOrEmpty(base64))
+ {
+ throw Oops.Oh("娌℃湁鍐呭");
+ }
+
+ //妫�鏌ヤ笂浼犲ぇ灏�
+ if (!CommonHelper.CheckBase64Size(base64, op.AttachmentSaveFileSize?.toInt() ?? 5))
+ {
+ throw Oops.Oh("涓婁紶鏂囦欢澶у皬瓒呰繃闄愬埗锛屾渶澶у厑璁镐笂浼�" + op.AttachmentSaveFileSize + "M");
+
+ }
+
+ base64 = base64.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "").Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", "");//灏哹ase64澶撮儴淇℃伅鏇挎崲
+ byte[] bytes = Convert.FromBase64String(base64);
+ MemoryStream memStream = new MemoryStream(bytes);
+
+ string url = string.Empty;
+ switch (op.AttachmentSaveMode)
+ {
+ case AttachmentSaveMode.AliOSS:
+ url = await UpLoadBase64ForAliYunOSS(op, memStream);
+ break;
+ case AttachmentSaveMode.TencentCOS:
+ url = await UpLoadBase64ForQCloudOSS(op, bytes);
+ break;
+ case AttachmentSaveMode.QiNiuKodo:
+ url = await UpLoadBase64ForQiNiuKoDo(op, bytes);
+ break;
+ case AttachmentSaveMode.Logical:
+ url = await UpLoadBase64ForLocalStorage(op, memStream);
+ break;
+ case AttachmentSaveMode.DataBase:
+ throw Oops.Oh("涓嶆敮鎸�");
+ break;
+ default:
+ break;
+ }
+
+
+ return url;
+ }
+
+ /// <summary>
+ /// 鍒犻櫎鏂囦欢
+ /// </summary>
+ /// <param name="Path"></param>
+ /// <returns></returns>
+ public async Task<bool> DelFile(string Path)
+ {
+ var op = _SYSSetting.GetAttachmentSetting();
+ if (op == null)
+ throw Oops.Oh("浣犳病鏈夊闄勪欢淇濆瓨杩涜璁剧疆锛岃璁剧疆闄勪欢淇濆瓨");
+ bool ret = false;
+ switch (op.AttachmentSaveMode)
+ {
+ case AttachmentSaveMode.AliOSS:
+ ret = await DelFileForAliYunOSS(op, Path);
+ break;
+ case AttachmentSaveMode.TencentCOS:
+ ret = await DelFileForQCloudOSS(op, Path);
+ break;
+ case AttachmentSaveMode.QiNiuKodo:
+ ret = await DelFileForQiNiuKoDo(op, Path);
+ break;
+ case AttachmentSaveMode.Logical:
+ ret = await DelFileForLocalStorage(op, Path);
+ break;
+ case AttachmentSaveMode.DataBase:
+ throw Oops.Oh("涓嶆敮鎸�");
+
+ default:
+ break;
+ }
+
+
+ return ret;
+ }
+
+ #region 鏈湴涓婁紶鏂规硶(File)
+
+ /// <summary>
+ /// 鏈湴涓婁紶鏂规硶(File)
+ /// </summary>
+ /// <param name="options"></param>
+ /// <param name="fileExt"></param>
+ /// <param name="file"></param>
+ /// <returns></returns>
+ public async Task<string> UpLoadFileForLocalStorage(SYSDictionaryAttachmentSetting options, string fileExt, IFormFile file)
+ {
+
+ var newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt;
+ var today = DateTime.Now.ToString("yyyyMMdd");
+
+ var saveUrl = options.AttachmentSavePath + today + "/";
+ var dirPath = App.WebHostEnvironment.WebRootPath + saveUrl;
+ if (!Directory.Exists(dirPath)) Directory.CreateDirectory(dirPath);
+ var filePath = dirPath + newFileName;
+ var fileUrl = saveUrl + newFileName;
+
+
+
+ await using (var fs = File.Create(filePath))
+ {
+ await file.CopyToAsync(fs);
+ fs.Flush();
+ }
+
+ return options.AttachmentSave_LogicalSaveBaseUrl + fileUrl;
+ }
+ #endregion
+
+ #region 闃块噷浜戜笂浼犳柟娉曪紙File锛�
+ /// <summary>
+ /// 闃块噷浜戜笂浼犳柟娉曪紙File锛�
+ /// </summary>
+ /// <param name="options"></param>
+ /// <param name="fileExt"></param>
+ /// <param name="file"></param>
+ /// <returns></returns>
+ public async Task<string> UpLoadFileForAliYunOSS(SYSDictionaryAttachmentSetting options, string fileExt, IFormFile file)
+ {
+
+
+ var newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt;
+ var today = DateTime.Now.ToString("yyyyMMdd");
+
+ //涓婁紶鍒伴樋閲屼簯
+ await using var fileStream = file.OpenReadStream();
+ var md5 = OssUtils.ComputeContentMd5(fileStream, file.Length);
+
+ var filePath = options.AttachmentSavePath + today + "/" + newFileName; //浜戞枃浠朵繚瀛樿矾寰�
+ //鍒濆鍖栭樋閲屼簯閰嶇疆--澶栫綉Endpoint銆佽闂甀D銆佽闂畃assword
+ var aliYun = new OssClient(options.AttachmentSave_AliOSSEndpoint, options.AttachmentSave_AliOSSAccessKeyID, options.AttachmentSave_AliOSSAccessKeySecret);
+ //灏嗘枃浠秏d5鍊艰祴鍊肩粰meat澶翠俊鎭紝鏈嶅姟鍣ㄩ獙璇佹枃浠禡D5
+ var objectMeta = new ObjectMetadata
+ {
+ ContentMd5 = md5
+ };
+
+
+ var task = Task.Run(() =>
+ //鏂囦欢涓婁紶--绌洪棿鍚嶃�佹枃浠朵繚瀛樿矾寰勩�佹枃浠舵祦銆乵eta澶翠俊鎭�(鏂囦欢md5) //杩斿洖meta澶翠俊鎭�(鏂囦欢md5)
+ aliYun.PutObject(options.AttachmentSave_AliOSSBucketName, filePath, fileStream, objectMeta)
+
+
+
+ );
+ //绛夊緟瀹屾垚
+ try
+ {
+ task.Wait();
+ }
+ catch (AggregateException ex)
+ {
+
+ throw Oops.Oh(ex.Message);
+ }
+
+ //杩斿洖缁橴Editor鐨勬彃鍏ョ紪杈戝櫒鐨勫浘鐗囩殑src
+
+ return options.AttachmentSave_AliOSSSaveBaseUrl + filePath;
+ }
+
+ #endregion
+
+ #region 鑵捐浜戝瓨鍌ㄤ笂浼犳柟娉曪紙File锛�
+ /// <summary>
+ /// 鑵捐浜戝瓨鍌ㄤ笂浼犳柟娉曪紙File锛�
+ /// </summary>
+ /// <param name="options"></param>
+ /// <param name="fileExt"></param>
+ /// <param name="file"></param>
+ /// <returns></returns>
+ public async Task<string> UpLoadFileForQCloudOSS(SYSDictionaryAttachmentSetting options, string fileExt, IFormFile file)
+ {
+
+ var newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt;
+ var today = DateTime.Now.ToString("yyyyMMdd");
+
+ var filePath = options.AttachmentSavePath + today + "/" + newFileName; //浜戞枃浠朵繚瀛樿矾寰�
+
+ //涓婁紶鍒拌吘璁簯OSS
+ //鍒濆鍖� CosXmlConfig
+ string appid = options.AttachmentSave_TencentAPPID;//璁剧疆鑵捐浜戣处鎴风殑璐︽埛鏍囪瘑 APPID
+ string region = options.AttachmentSave_TencentCosRegion; //璁剧疆涓�涓粯璁ょ殑瀛樺偍妗跺湴鍩�
+ CosXmlConfig config = new CosXmlConfig.Builder()
+ //.SetAppid(appid)
+ .IsHttps(true) //璁剧疆榛樿 HTTPS 璇锋眰
+ .SetRegion(region) //璁剧疆涓�涓粯璁ょ殑瀛樺偍妗跺湴鍩�
+ .SetDebugLog(true) //鏄剧ず鏃ュ織
+ .Build(); //鍒涘缓 CosXmlConfig 瀵硅薄
+
+ long durationSecond = 600; //姣忔璇锋眰绛惧悕鏈夋晥鏃堕暱锛屽崟浣嶄负绉�
+ QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(options.AttachmentSave_TencentSecretId, options.AttachmentSave_TencentSecretKey, durationSecond);
+
+
+ byte[] bytes;
+ await using (var ms = new MemoryStream())
+ {
+ await file.CopyToAsync(ms);
+ bytes = ms.ToArray();
+ }
+ try
+ {
+
+ var cosXml = new CosXmlServer(config, qCloudCredentialProvider);
+ COSXML.Model.Object.PutObjectRequest putObjectRequest = new COSXML.Model.Object.PutObjectRequest(options.AttachmentSave_TencentBucketName, filePath, bytes);
+ cosXml.PutObject(putObjectRequest);
+ }
+ catch (COSXML.CosException.CosClientException clientEx)
+ {
+
+ throw Oops.Oh(clientEx.Message);
+ }
+ catch (COSXML.CosException.CosServerException serverEx)
+ {
+
+ throw Oops.Oh(serverEx.GetInfo);
+ }
+
+
+ return options.AttachmentSave_TencentSaveBaseUrl + filePath;
+ }
+ #endregion
+
+ #region 涓冪墰浜戝瓨鍌ㄤ笂浼狅紙File锛�
+ /// <summary>
+ /// 涓冪墰浜戝瓨鍌ㄤ笂浼狅紙File锛�
+ /// </summary>
+ /// <param name="options"></param>
+ /// <param name="fileExt"></param>
+ /// <param name="file"></param>
+ /// <returns></returns>
+ public async Task<string> UpLoadFileForQiNiuKoDo(SYSDictionaryAttachmentSetting options, string fileExt, IFormFile file)
+ {
+
+ var newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_fffff", DateTimeFormatInfo.InvariantInfo) + fileExt;
+
+ Mac mac = new Mac(options.AttachmentSave_QiNiuKodoAK, options.AttachmentSave_QiNiuKodoSK);
+
+ byte[] bytes;
+ await using (var ms = new MemoryStream())
+ {
+ await file.CopyToAsync(ms);
+ bytes = ms.ToArray();
+ }
+
+ // 璁剧疆涓婁紶绛栫暐
+ PutPolicy putPolicy = new PutPolicy();
+ // 璁剧疆瑕佷笂浼犵殑鐩爣绌洪棿
+ putPolicy.Scope = options.AttachmentSave_QiNiuKodoBucketName;
+ // 涓婁紶绛栫暐鐨勮繃鏈熸椂闂�(鍗曚綅:绉�)
+ putPolicy.SetExpires(3600);
+ // 鏂囦欢涓婁紶瀹屾瘯鍚庯紝鍦ㄥ灏戝ぉ鍚庤嚜鍔ㄨ鍒犻櫎
+ //putPolicy.DeleteAfterDays = 1;
+ // 鐢熸垚涓婁紶token
+ string token = Qiniu.Util.Auth.CreateUploadToken(mac, putPolicy.ToJsonString());
+
+ Config config = new Config();
+ // 璁剧疆 http 鎴栬�� https 涓婁紶
+ config.UseHttps = true;
+ config.UseCdnDomains = true;
+ config.ChunkSize = ChunkUnit.U512K;
+
+ UploadManager um = new UploadManager(config);
+ var fileTemp = (options?.AttachmentSavePath?.Substring(1) ?? "") + newFileName;
+ var task = Task.Run(() => um.UploadData(bytes, fileTemp, token, null));
+ task.Wait();
+ var outData = task.Result;
+ if (outData?.Code != 200)
+ throw Oops.Oh(outData?.Text);
+ return options.AttachmentSave_QiNiuKodoSaveBaseUrl + options.AttachmentSavePath + newFileName;
+ }
+ #endregion
+
+
+ #region 鏈湴涓婁紶鏂规硶(Base64)
+
+ /// <summary>
+ /// 鏈湴涓婁紶鏂规硶(Base64)
+ /// </summary>
+ /// <param name="options"></param>
+ /// <param name="memStream"></param>
+ /// <returns></returns>
+ public async Task<string> UpLoadBase64ForLocalStorage(SYSDictionaryAttachmentSetting options, MemoryStream memStream)
+ {
+
+
+ var newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + ".jpg";
+ var today = DateTime.Now.ToString("yyyyMMdd");
+
+ byte[] data = new byte[memStream.Length];
+ memStream.Seek(0, SeekOrigin.Begin);
+ memStream.Read(data, 0, Convert.ToInt32(memStream.Length));
+ SixLabors.ImageSharp.Image image = SixLabors.ImageSharp.Image.Load(new MemoryStream(data));
+
+ var saveUrl = options.AttachmentSavePath + today + "/";
+ var dirPath = App.WebHostEnvironment.WebRootPath + saveUrl;
+ if (!Directory.Exists(dirPath)) Directory.CreateDirectory(dirPath);
+ var filePath = dirPath + newFileName;
+ var fileUrl = saveUrl + newFileName;
+
+
+ //淇濆瓨鍒板浘鐗�
+ await image.SaveAsync(filePath);
+
+ return options.AttachmentSave_LogicalSaveBaseUrl + fileUrl;
+ }
+ #endregion
+
+ #region 闃块噷浜戜笂浼犳柟娉曪紙Base64锛�
+ /// <summary>
+ /// 闃块噷浜戜笂浼犳柟娉曪紙Base64锛�
+ /// </summary>
+ /// <param name="options"></param>
+ /// <param name="memStream"></param>
+ /// <returns></returns>
+ public async Task<string> UpLoadBase64ForAliYunOSS(SYSDictionaryAttachmentSetting options, MemoryStream memStream)
+ {
+
+
+ var newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + ".jpg";
+ var today = DateTime.Now.ToString("yyyyMMdd");
+
+ // 璁剧疆褰撳墠娴佺殑浣嶇疆涓烘祦鐨勫紑濮�
+ memStream.Seek(0, SeekOrigin.Begin);
+
+ await using var fileStream = memStream;
+ var md5 = OssUtils.ComputeContentMd5(fileStream, memStream.Length);
+
+ var filePath = options.AttachmentSavePath + today + "/" + newFileName; //浜戞枃浠朵繚瀛樿矾寰�
+ //鍒濆鍖栭樋閲屼簯閰嶇疆--澶栫綉Endpoint銆佽闂甀D銆佽闂畃assword
+ var aliyun = new OssClient(options.AttachmentSave_AliOSSEndpoint, options.AttachmentSave_AliOSSAccessKeyID, options.AttachmentSave_AliOSSAccessKeySecret);
+ //灏嗘枃浠秏d5鍊艰祴鍊肩粰meat澶翠俊鎭紝鏈嶅姟鍣ㄩ獙璇佹枃浠禡D5
+ var objectMeta = new ObjectMetadata
+ {
+ ContentMd5 = md5
+ };
+ try
+ {
+ //鏂囦欢涓婁紶--绌洪棿鍚嶃�佹枃浠朵繚瀛樿矾寰勩�佹枃浠舵祦銆乵eta澶翠俊鎭�(鏂囦欢md5) //杩斿洖meta澶翠俊鎭�(鏂囦欢md5)
+ aliyun.PutObject(options.AttachmentSave_AliOSSBucketName, filePath, fileStream, objectMeta);
+ }
+ catch (AggregateException ex)
+ {
+
+ throw Oops.Oh(ex.Message);
+ }
+
+
+ //杩斿洖缁橴Editor鐨勬彃鍏ョ紪杈戝櫒鐨勫浘鐗囩殑src
+
+ return options.AttachmentSave_AliOSSSaveBaseUrl + filePath;
+
+ }
+
+ #endregion
+
+ #region 鑵捐浜戝瓨鍌ㄤ笂浼犳柟娉曪紙Base64锛�
+
+ /// <summary>
+ /// 鑵捐浜戝瓨鍌ㄤ笂浼犳柟娉曪紙Base64锛�
+ /// </summary>
+ /// <param name="options"></param>
+ /// <param name="bytes"></param>
+ /// <returns></returns>
+ public async Task<string> UpLoadBase64ForQCloudOSS(SYSDictionaryAttachmentSetting options, byte[] bytes)
+
+ {
+
+
+ var newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + ".jpg";
+ var today = DateTime.Now.ToString("yyyyMMdd");
+
+ //鍒濆鍖� CosXmlConfig
+ string appid = options.AttachmentSave_TencentAPPID;//璁剧疆鑵捐浜戣处鎴风殑璐︽埛鏍囪瘑 APPID
+ string region = options.AttachmentSave_TencentCosRegion; //璁剧疆涓�涓粯璁ょ殑瀛樺偍妗跺湴鍩�
+ CosXmlConfig config = new CosXmlConfig.Builder()
+ //.SetAppid(appid)
+ .IsHttps(true) //璁剧疆榛樿 HTTPS 璇锋眰
+ .SetRegion(region) //璁剧疆涓�涓粯璁ょ殑瀛樺偍妗跺湴鍩�
+ .SetDebugLog(true) //鏄剧ず鏃ュ織
+ .Build(); //鍒涘缓 CosXmlConfig 瀵硅薄
+
+ long durationSecond = 600; //姣忔璇锋眰绛惧悕鏈夋晥鏃堕暱锛屽崟浣嶄负绉�
+
+ QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(options.AttachmentSave_TencentSecretId, options.AttachmentSave_TencentSecretKey, durationSecond);
+
+ var cosXml = new CosXmlServer(config, qCloudCredentialProvider);
+
+ var filePath = options.AttachmentSavePath + today + "/" + newFileName; //浜戞枃浠朵繚瀛樿矾寰�
+ try
+ {
+ COSXML.Model.Object.PutObjectRequest putObjectRequest = new COSXML.Model.Object.PutObjectRequest(options.AttachmentSave_TencentBucketName, filePath, bytes);
+ var task = Task.Run(() => cosXml.PutObject(putObjectRequest));
+
+
+
+ task.Wait();
+
+ }
+
+
+ catch (COSXML.CosException.CosClientException clientEx)
+ {
+
+ throw Oops.Oh(clientEx.Message);
+ }
+ catch (COSXML.CosException.CosServerException serverEx)
+ {
+
+ throw Oops.Oh(serverEx.GetInfo());
+ }
+
+
+ return options.AttachmentSave_TencentSaveBaseUrl + filePath;
+ }
+ #endregion
+
+ #region 鐗涗簯涓婁紶鏂规硶锛圔ase64锛�
+
+ /// <summary>
+ /// 涓冪墰浜戜笂浼犳柟娉曪紙Base64锛�
+ /// </summary>
+ /// <param name="options"></param>
+ /// <param name="bytes"></param>
+ /// <returns></returns>
+ public async Task<string> UpLoadBase64ForQiNiuKoDo(SYSDictionaryAttachmentSetting options, byte[] bytes)
+ {
+ var newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_fffff", DateTimeFormatInfo.InvariantInfo) + ".jpg";
+
+ Mac mac = new Mac(options.AttachmentSave_QiNiuKodoAK, options.AttachmentSave_QiNiuKodoSK);
+
+ // 璁剧疆涓婁紶绛栫暐
+ PutPolicy putPolicy = new PutPolicy();
+ // 璁剧疆瑕佷笂浼犵殑鐩爣绌洪棿
+ putPolicy.Scope = options.AttachmentSave_QiNiuKodoBucketName;
+ // 涓婁紶绛栫暐鐨勮繃鏈熸椂闂�(鍗曚綅:绉�)
+ putPolicy.SetExpires(3600);
+ // 鏂囦欢涓婁紶瀹屾瘯鍚庯紝鍦ㄥ灏戝ぉ鍚庤嚜鍔ㄨ鍒犻櫎
+ //putPolicy.DeleteAfterDays = 1;
+ // 鐢熸垚涓婁紶token
+ string token = Qiniu.Util.Auth.CreateUploadToken(mac, putPolicy.ToJsonString());
+
+ Config config = new Config();
+ // 璁剧疆 http 鎴栬�� https 涓婁紶
+ config.UseHttps = true;
+ config.UseCdnDomains = true;
+ config.ChunkSize = ChunkUnit.U512K;
+ var fileTemp = (options?.AttachmentSavePath?.Substring(1) ?? "") + newFileName;
+ UploadManager um = new UploadManager(config);
+ var task = Task.Run(() => um.UploadData(bytes, fileTemp, token, null));
+ // var outData = um.UploadData(bytes, newFileName, token, null);
+ task.Wait();
+ var outdata = task.Result;
+ if (outdata?.Code != 200)
+ throw Oops.Oh(outdata?.Text);
+ return options.AttachmentSave_QiNiuKodoSaveBaseUrl + options.AttachmentSavePath + newFileName;
+ }
+ #endregion
+
+
+
+ #region 鍒犻櫎鏂囦欢
+
+ /// <summary>
+ /// 鍒犻櫎鏈湴鏂囦欢
+ /// </summary>
+ /// <param name="options"></param>
+ /// <param name="fileUrl"></param>
+ /// <returns></returns>
+ public async Task<bool> DelFileForLocalStorage(SYSDictionaryAttachmentSetting options, string fileUrl)
+ {
+ string key = App.WebHostEnvironment.WebRootPath + (options.AttachmentSavePath?.RemoveStartWithStr("/") ?? "") + fileUrl.GetFileName();
+
+ File.Delete(key);
+ return true;
+ }
+ /// <summary>
+ /// 鍒犻櫎涓冪墰鏂囦欢澶�
+ /// </summary>
+ /// <param name="options"></param>
+ /// <param name="fileUrl"></param>
+ /// <returns></returns>
+ public async Task<bool> DelFileForQiNiuKoDo(SYSDictionaryAttachmentSetting options, string fileUrl)
+ {
+ Config config = new Config();
+ var a = fileUrl.GetFileName();
+ Mac mac = new Mac(options.AttachmentSave_QiNiuKodoAK, options.AttachmentSave_QiNiuKodoSK);
+ BucketManager bucketManager = new BucketManager(mac, config);
+ string key = (options.AttachmentSavePath?.RemoveStartWithStr("/") ?? "") + fileUrl.GetFileName();
+
+ var task = Task.Run(() => bucketManager.Delete(options.AttachmentSave_QiNiuKodoBucketName, key));
+ // var outData = um.UploadData(bytes, newFileName, token, null);
+ task.Wait();
+ var outdata = task.Result;
+ if (outdata?.Code != 200)
+ throw Oops.Oh(outdata?.Text);
+ return true;
+
+ }
+ /// <summary>
+ /// 鑵捐浜戝垹闄�
+ /// </summary>
+ /// <param name="options"></param>
+ /// <param name="fileUrl">甯xx.xx鐨勯摼鎺ュ湴鍧�</param>
+ /// <returns></returns>
+ public async Task<bool> DelFileForQCloudOSS(SYSDictionaryAttachmentSetting options, string fileUrl)
+
+ {
+
+
+
+
+ //鍒濆鍖� CosXmlConfig
+ string appid = options.AttachmentSave_TencentAPPID;//璁剧疆鑵捐浜戣处鎴风殑璐︽埛鏍囪瘑 APPID
+ string region = options.AttachmentSave_TencentCosRegion; //璁剧疆涓�涓粯璁ょ殑瀛樺偍妗跺湴鍩�
+ CosXmlConfig config = new CosXmlConfig.Builder()
+ //.SetAppid(appid)
+ .IsHttps(true) //璁剧疆榛樿 HTTPS 璇锋眰
+ .SetRegion(region) //璁剧疆涓�涓粯璁ょ殑瀛樺偍妗跺湴鍩�
+ .SetDebugLog(true) //鏄剧ず鏃ュ織
+ .Build(); //鍒涘缓 CosXmlConfig 瀵硅薄
+
+ long durationSecond = 600; //姣忔璇锋眰绛惧悕鏈夋晥鏃堕暱锛屽崟浣嶄负绉�
+
+ QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(options.AttachmentSave_TencentSecretId, options.AttachmentSave_TencentSecretKey, durationSecond);
+
+ var cosXml = new CosXmlServer(config, qCloudCredentialProvider);
+
+ string key = (options.AttachmentSavePath?.RemoveStartWithStr("/") ?? "") + fileUrl.GetFileName();
+ try
+ {
+ COSXML.Model.Object.DeleteObjectRequest DelObjectRequest = new COSXML.Model.Object.DeleteObjectRequest(options.AttachmentSave_TencentBucketName, key);
+ var task = Task.Run(() => cosXml.DeleteObject(DelObjectRequest));
+
+
+
+ task.Wait();
+
+ }
+
+
+ catch (COSXML.CosException.CosClientException clientEx)
+ {
+
+ throw Oops.Oh(clientEx.Message);
+ }
+ catch (COSXML.CosException.CosServerException serverEx)
+ {
+
+ throw Oops.Oh(serverEx.GetInfo());
+ }
+
+
+ return true;
+ }
+
+ /// <summary>
+ /// 鑵捐浜戝垹闄�
+ /// </summary>
+ /// <param name="options"></param>
+ /// <param name="fileUrl">甯xx.xx鐨勯摼鎺ュ湴鍧�</param>
+ /// <returns></returns>
+ public async Task<bool> DelFileForAliYunOSS(SYSDictionaryAttachmentSetting options, string fileUrl)
+ {
+
+
+
+
+
+
+
+
+
+
+ //鍒濆鍖栭樋閲屼簯閰嶇疆--澶栫綉Endpoint銆佽闂甀D銆佽闂畃assword
+ var aliyun = new OssClient(options.AttachmentSave_AliOSSEndpoint, options.AttachmentSave_AliOSSAccessKeyID, options.AttachmentSave_AliOSSAccessKeySecret);
+
+ try
+ {
+ var task = Task.Run(() => aliyun.DeleteObject(options.AttachmentSave_AliOSSBucketName, (options.AttachmentSavePath?.RemoveStartWithStr("/") ?? "") + fileUrl.GetFileName()));
+
+
+ task.Wait();
+
+ }
+ catch (Exception ex)
+ {
+
+ throw Oops.Oh(ex.Message);
+ }
+
+
+ //杩斿洖缁橴Editor鐨勬彃鍏ョ紪杈戝櫒鐨勫浘鐗囩殑src
+
+ return true;
+
+ }
+ #endregion
+
+
+ }
+}
diff --git a/cylsg/EzUpFiles/EzUpFiles.csproj b/cylsg/EzUpFiles/EzUpFiles.csproj
new file mode 100644
index 0000000..fa71b7a
--- /dev/null
+++ b/cylsg/EzUpFiles/EzUpFiles.csproj
@@ -0,0 +1,9 @@
+锘�<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>net8.0</TargetFramework>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+ </PropertyGroup>
+
+</Project>
diff --git a/cylsg/EzUpFiles/IEzFileUploadService.cs b/cylsg/EzUpFiles/IEzFileUploadService.cs
new file mode 100644
index 0000000..94e08b0
--- /dev/null
+++ b/cylsg/EzUpFiles/IEzFileUploadService.cs
@@ -0,0 +1,30 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EzUpFiles
+{
+ public interface IEzFileUploadService
+ {
+ /// <summary>
+ /// 涓婁紶base64
+ /// </summary>
+ /// <param name="base64"></param>
+ /// <returns></returns>
+ Task<string> UploadFilesFByBase64(string base64);
+ /// <summary>
+ /// 涓婁紶鏂囦欢
+ /// </summary>
+ /// <returns></returns>
+ Task<string> UploadFiles();
+ /// <summary>
+ /// 鍒犻櫎鏂囦欢
+ /// </summary>
+ /// <param name="Path"></param>
+ /// <returns></returns>
+ Task<bool> DelFile(string Path);
+
+ }
+}
diff --git a/cylsg/EzWechat/EzWechat.csproj b/cylsg/EzWechat/EzWechat.csproj
new file mode 100644
index 0000000..f8face4
--- /dev/null
+++ b/cylsg/EzWechat/EzWechat.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="SKIT.FlurlHttpClient.Wechat.Api" Version="3.4.0" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\cylsg.Core\cylsg.Core.csproj" />
+ </ItemGroup>
+
+</Project>
diff --git a/cylsg/EzWechat/IWechatService.cs b/cylsg/EzWechat/IWechatService.cs
new file mode 100644
index 0000000..935346f
--- /dev/null
+++ b/cylsg/EzWechat/IWechatService.cs
@@ -0,0 +1,13 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EzWechat
+{
+
+ public interface IWechatService
+ {
+ }
+}
diff --git a/cylsg/EzWechat/Startup.cs b/cylsg/EzWechat/Startup.cs
new file mode 100644
index 0000000..8070729
--- /dev/null
+++ b/cylsg/EzWechat/Startup.cs
@@ -0,0 +1,22 @@
+锘縰sing Furion;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.DependencyInjection;
+using SqlSugar;
+
+namespace cylsg.Authorization
+{
+ public class Startup : AppStartup
+ {
+ public void ConfigureServices(IServiceCollection services)
+ {
+
+
+ }
+
+ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+ {
+
+ }
+ }
+}
diff --git a/cylsg/EzWechat/WechatConfig.json b/cylsg/EzWechat/WechatConfig.json
new file mode 100644
index 0000000..a6540e1
--- /dev/null
+++ b/cylsg/EzWechat/WechatConfig.json
@@ -0,0 +1,7 @@
+{
+ "WechatAPP" :{
+ "AppId": "寰俊 AppId",
+ "AppSecret": "寰俊 AppSecret"
+
+ }
+}
\ No newline at end of file
diff --git a/cylsg/EzWechat/WechatService.cs b/cylsg/EzWechat/WechatService.cs
new file mode 100644
index 0000000..cc1cf84
--- /dev/null
+++ b/cylsg/EzWechat/WechatService.cs
@@ -0,0 +1,36 @@
+锘縰sing Furion;
+using SKIT.FlurlHttpClient.Wechat.Api;
+using SKIT.FlurlHttpClient.Wechat.Api.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EzWechat
+{
+
+ public class WechatService:IWechatService
+ {
+
+ public WechatService() {
+
+ /* 浠ュ叕浼楀彿鑾峰彇鐢ㄦ埛淇℃伅鎺ュ彛涓轰緥 */
+ var request = new WechatApiClientOptions()
+ {
+ AppId = App.Configuration["WechatAPP:AppId"],
+ AppSecret = App.Configuration["WechatAPP:AppSecret"],
+
+ //ImmeDeliveryAppKey = "鍗虫椂閰嶉�佺浉鍏虫湇鍔� AppKey锛屼笉鐢ㄥ垯涓嶅~",
+ //ImmeDeliveryAppSecret = "鍗虫椂閰嶉�佺浉鍏虫湇鍔� AppSecret锛屼笉鐢ㄥ垯涓嶅~",
+ //VirtualPaymentAppKey = "铏氭嫙鏀粯鐩稿叧鏈嶅姟 AppKey锛屼笉鐢ㄥ垯涓嶅~",
+ //MidasOfferId = "绫冲ぇ甯� 1.0 鐩稿叧鏈嶅姟 OfferId锛屼笉鐢ㄥ垯涓嶅~",
+ //MidasAppKey = "绫冲ぇ甯� 1.0 鐩稿叧鏈嶅姟 AppKey锛屼笉鐢ㄥ垯涓嶅~",
+ //MidasOfferIdV2 = "绫冲ぇ甯� 2.0 鐩稿叧鏈嶅姟 OfferId锛屼笉鐢ㄥ垯涓嶅~",
+ //MidasAppKeyV2 = "绫冲ぇ甯� 2.0 鐩稿叧鏈嶅姟 AppKey锛屼笉鐢ㄥ垯涓嶅~"
+
+
+ };
+ }
+ }
+}
diff --git a/cylsg/cylsg.Application/System/Services/ISystemService.cs b/cylsg/cylsg.Application/System/Services/ISystemService.cs
index 8a2c27c..20b191d 100644
--- a/cylsg/cylsg.Application/System/Services/ISystemService.cs
+++ b/cylsg/cylsg.Application/System/Services/ISystemService.cs
@@ -2,5 +2,5 @@
public interface ISystemService
{
- string GetDescription();
+ string GetDescription();
}
diff --git a/cylsg/cylsg.Application/System/Services/SystemService.cs b/cylsg/cylsg.Application/System/Services/SystemService.cs
index 81e7885..13bd938 100644
--- a/cylsg/cylsg.Application/System/Services/SystemService.cs
+++ b/cylsg/cylsg.Application/System/Services/SystemService.cs
@@ -4,6 +4,6 @@
{
public string GetDescription()
{
- return "璁� .NET 寮�鍙戞洿绠�鍗曪紝鏇撮�氱敤锛屾洿娴佽銆�";
+ return "宸濆嵃鎷涜仒";
}
}
diff --git a/cylsg/cylsg.Authorization/EzAuthorizationService.cs b/cylsg/cylsg.Authorization/EzAuthorizationService.cs
new file mode 100644
index 0000000..6bbd875
--- /dev/null
+++ b/cylsg/cylsg.Authorization/EzAuthorizationService.cs
@@ -0,0 +1,154 @@
+锘縰sing Furion.Authorization;
+using Furion.DataEncryption;
+using Furion;
+using Furion.DependencyInjection;
+using Microsoft.AspNetCore.Http;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using EzCoreNet.Redis;
+
+using SqlSugar.Extensions;
+
+using Furion.FriendlyException;
+
+namespace cylsg.Authorization
+{
+ /// <summary>
+ ///
+ /// </summary>
+ public class EzAuthorizationService : IEzAuthorizationService, IScoped
+ {
+ private IEzCoreNetRedisService _redisCacheSc;
+ private IHttpContextAccessor _Context;
+ public EzAuthorizationService(IEzCoreNetRedisService redisCacheSc, IHttpContextAccessor httpContext)
+ {
+ _redisCacheSc = redisCacheSc;
+ _Context = httpContext;
+ }
+ /// <summary>
+ /// Token
+ /// </summary>
+ /// <returns></returns>
+ public TokenInfo CreateToken<T>(T jwt) where T : EzJwtModel
+ {
+
+ IDictionary<string, object> propertyDictionary = new Dictionary<string, object>();
+
+ PropertyInfo[] properties = jwt.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
+
+ foreach (PropertyInfo property in properties)
+ {
+ string propertyName = property.Name;
+ object propertyValue = property.GetValue(jwt);
+
+ propertyDictionary.Add(propertyName.ToLower(), propertyValue);
+ }
+ var expires = DateTime.Now.AddSeconds(Convert.ToInt32(App.GetConfig<JWTSettingsOptions>("JWTSettings").ExpiredTime * 60 ?? 3600));
+ var token = JWTEncryption.Encrypt(propertyDictionary, App.GetConfig<JWTSettingsOptions>("JWTSettings").ExpiredTime ?? 3600);
+
+ DateTimeOffset dto = new DateTimeOffset(DateTime.Now);
+ var Expires = dto.ToUnixTimeSeconds();
+ IDictionary<string, object> REfpropertyDictionary = new Dictionary<string, object>();
+ REfpropertyDictionary.Add(new(
+ "RefTokenID", $"{jwt.ITCode}:{Expires}"
+ ));
+
+ var RefExpires = App.Configuration["JWTSettings:RefreshTokenExpires"].ObjToInt();
+
+ var refreshToken = JWTEncryption.Encrypt(REfpropertyDictionary, RefExpires);
+
+ //鍐欏叆鍒锋柊鍙疶oken鏃堕棿
+ _redisCacheSc.Add($"{jwt.ITCode}:{Expires}", jwt, RefExpires * 60);
+
+ return new TokenInfo
+ {
+ accessToken = token,
+ expires = expires,
+ refreshToken = refreshToken
+ };
+
+ }
+ /// <summary>
+ /// 鍒锋柊TOKEN
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="refToken"></param>
+ /// <returns></returns>
+ /// <exception cref="TAxiosException"></exception>
+ public async Task<TokenInfo?> RefreshToken<T>(string refToken) where T : EzJwtModel
+ {
+ // IDictionary<string, object> REfpropertyDictionary = new Dictionary<string, object>();
+
+ // var tokenInfo = JWTEncryption.ReadJwtToken("token");
+ var (isValid, tokenData, validationResult) = JWTEncryption.Validate(refToken);
+ if (!isValid)
+ new EZCoreException(" 绯荤粺閿欒锛岃閲嶆柊鐧诲綍", System.Net.HttpStatusCode.Unauthorized);
+ var user = tokenData.Claims;
+ if (user == null)
+ throw new EZCoreException("鍙傛暟涓㈠け锛岃閲嶆柊鐧诲綍", System.Net.HttpStatusCode.Unauthorized);
+
+ var key = user.Where(x => x.Type == "RefTokenID").Select(x => x.Value).FirstOrDefault();
+ //if (key == null)
+ // throw Oops.Oh("token宸茶繃鏈燂紝璇烽噸鏂扮櫥褰�", System.Net.HttpStatusCode.Unauthorized);
+ var jwtConfig = App.GetConfig<JWTSettingsOptions>("JWTSettings");
+ if (jwtConfig == null)
+ throw new EZCoreException(" 绯荤粺閿欒锛岃閲嶆柊鐧诲綍", System.Net.HttpStatusCode.Unauthorized);
+ var LoinData = _redisCacheSc.Get<T>(key);
+ if (LoinData == null)
+
+ throw new EZCoreException("token宸茶繃鏈燂紝璇烽噸鏂扮櫥褰�", System.Net.HttpStatusCode.Unauthorized); //Oops.Oh("token宸茶繃鏈燂紝璇烽噸鏂扮櫥褰�", System.Net.HttpStatusCode.Unauthorized);
+ var refreshTokenouttimes = _redisCacheSc.GetTtl(key);
+ if (refreshTokenouttimes <= 0)
+ {
+
+ throw new EZCoreException("token宸茶繃鏈燂紝璇烽噸鏂扮櫥褰�", System.Net.HttpStatusCode.Unauthorized);
+ }
+ return await Task.Run<TokenInfo?>(() =>
+ {
+
+
+
+ IDictionary<string, object> propertyDictionary = new Dictionary<string, object>();
+
+ PropertyInfo[] properties = LoinData.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
+
+ foreach (PropertyInfo property in properties)
+ {
+ string propertyName = property.Name;
+ object propertyValue = property.GetValue(LoinData);
+
+ propertyDictionary.Add(propertyName.ToLower(), propertyValue);
+ }
+
+
+ var expires = DateTime.Now.AddSeconds(Convert.ToInt32(jwtConfig.ExpiredTime * 60));
+
+ var token = JWTEncryption.Encrypt(propertyDictionary, jwtConfig.ExpiredTime);
+
+
+ IDictionary<string, object> refreshTokenClaims = new Dictionary<string, object>();
+
+
+ refreshTokenClaims.Add(new(
+ "RefTokenID", key
+ ));
+
+ var refreshToken = JWTEncryption.Encrypt(refreshTokenClaims, refreshTokenouttimes);
+
+ return new TokenInfo
+ {
+ accessToken = token,
+ expires = expires,
+ refreshToken = refreshToken
+ };
+ });
+
+
+
+ }
+ }
+}
diff --git a/cylsg/cylsg.Authorization/EzJwtModel.cs b/cylsg/cylsg.Authorization/EzJwtModel.cs
new file mode 100644
index 0000000..d76060f
--- /dev/null
+++ b/cylsg/cylsg.Authorization/EzJwtModel.cs
@@ -0,0 +1,38 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace cylsg.Authorization
+{
+ public class EzJwtModel
+ {
+ /// <summary>
+ /// 濮撳悕ID
+ /// </summary>
+ public int? UserID { get; set; }
+ /// <summary>
+ /// 鐢ㄦ埛濮撳悕
+ /// </summary>
+ public string? NickName { get; set; }
+
+ /// <summary>
+ /// 鐢ㄦ埛鐧诲綍鍚嶇О
+ /// </summary>
+ public string? ITCode { get; set; }
+ public UserLogInTypeKey UserTypeKey { get; set; }
+
+ }
+
+ /// <summary>
+ /// 鐢ㄦ埛鐧诲綍绫诲瀷
+ /// </summary>
+ public enum UserLogInTypeKey
+ {
+ /// <summary>
+ /// 鍛樺伐绠$悊鍛�
+ /// </summary>
+ Employees
+ }
+}
diff --git a/cylsg/cylsg.Authorization/IEzAuthorizationService.cs b/cylsg/cylsg.Authorization/IEzAuthorizationService.cs
new file mode 100644
index 0000000..19e9986
--- /dev/null
+++ b/cylsg/cylsg.Authorization/IEzAuthorizationService.cs
@@ -0,0 +1,40 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace cylsg.Authorization
+{
+ /// <summary>
+ /// Ez閴存潈鏈嶅姟
+ /// </summary>
+ public interface IEzAuthorizationService
+ {
+ TokenInfo CreateToken<T>(T jwt) where T : EzJwtModel;
+ public Task<TokenInfo?> RefreshToken<T>(string refToken) where T : EzJwtModel;
+ }
+
+
+
+
+ /// <summary>
+ /// toke璇︽儏
+ /// </summary>
+ public class TokenInfo
+ {
+
+ /// <summary>
+ /// 褰撳墠token
+ /// </summary>
+ public string accessToken { get; set; }
+ /// <summary>
+ /// 鍒锋柊Token
+ /// </summary>
+ public string refreshToken { get; set; }
+ /// <summary>
+ /// 褰撳墠token鍒版湡鏃堕棿
+ /// </summary>
+ public DateTime? expires { get; set; }
+ }
+}
diff --git a/cylsg/cylsg.Authorization/Startup.cs b/cylsg/cylsg.Authorization/Startup.cs
new file mode 100644
index 0000000..d38224a
--- /dev/null
+++ b/cylsg/cylsg.Authorization/Startup.cs
@@ -0,0 +1,21 @@
+锘縰sing Furion;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.DependencyInjection;
+using SqlSugar;
+
+namespace cylsg.Authorization
+{
+ public class Startup : AppStartup
+ {
+ public void ConfigureServices(IServiceCollection services)
+ {
+
+ }
+
+ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+ {
+
+ }
+ }
+}
diff --git a/cylsg/cylsg.Authorization/cylsg.Authorization.csproj b/cylsg/cylsg.Authorization/cylsg.Authorization.csproj
new file mode 100644
index 0000000..7250e20
--- /dev/null
+++ b/cylsg/cylsg.Authorization/cylsg.Authorization.csproj
@@ -0,0 +1,15 @@
+锘�<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>net8.0</TargetFramework>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\cylsg.Core\cylsg.Core.csproj" />
+ <ProjectReference Include="..\cylsg.Model\cylsg.Model.csproj" />
+ <ProjectReference Include="..\cylsg.redis\cylsg.redis.csproj" />
+ </ItemGroup>
+
+</Project>
diff --git a/cylsg/cylsg.Authorization/cylsgException.cs b/cylsg/cylsg.Authorization/cylsgException.cs
new file mode 100644
index 0000000..506cb67
--- /dev/null
+++ b/cylsg/cylsg.Authorization/cylsgException.cs
@@ -0,0 +1,34 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace cylsg.Authorization
+{
+ /// <summary>
+ /// 浣滀负ezcore 鐨勬墿鍏�
+ /// </summary>
+ public class EZCoreException : Exception
+ {
+ public EZCoreException(string message, HttpStatusCode? sCode = null) : base(message)
+ {
+ if (sCode != null)
+ StatusCode = sCode;
+ }
+ public EZCoreException(HttpStatusCode? sCode = null)
+ {
+
+ if (sCode != null)
+ StatusCode = sCode;
+ }
+ public EZCoreException(string message, Exception innerException, HttpStatusCode? sCode = null) : base(message, innerException)
+ {
+
+ if (sCode != null)
+ StatusCode = sCode;
+ }
+ public HttpStatusCode? StatusCode { get; set; } = HttpStatusCode.OK;
+ }
+}
diff --git a/cylsg/cylsg.Web.Core/Handlers/EzCoreRESTFulResultProvider.cs b/cylsg/cylsg.Web.Core/Handlers/EzCoreRESTFulResultProvider.cs
new file mode 100644
index 0000000..2bbe5fb
--- /dev/null
+++ b/cylsg/cylsg.Web.Core/Handlers/EzCoreRESTFulResultProvider.cs
@@ -0,0 +1,174 @@
+锘縰sing Furion.FriendlyException;
+using Furion.UnifyResult;
+using Furion;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc.Filters;
+using Microsoft.AspNetCore.Mvc;
+using System;
+
+using System.Threading.Tasks;
+using Furion.DataValidation;
+
+using cylsg.Authorization;
+
+
+namespace cylsg.Web.Core.Handlers
+{
+ /// <summary>
+ /// 缁熶竴杩斿洖缁撴灉
+ /// </summary>
+ [UnifyModel(typeof(EzCoreResultMode<>))]
+ internal class EzCoreRESTFulResultProvider : IUnifyResultProvider
+ {
+
+ /// <summary>
+ /// 寮傚父杩斿洖鍊�
+ /// </summary>
+ /// <param name="context"></param>
+ /// <param name="metadata"></param>
+ /// <returns></returns>
+ public IActionResult OnException(ExceptionContext context, ExceptionMetadata metadata)
+ {
+ //if (context is TAxiosException)
+ // return new JsonResult(new JsonResult(TAxiosFulResult((int)((TAxios.Utility.TAxiosException)context.Exception).StatusCode, Code: 0, data: metadata.Data, errors: metadata.Errors)
+ // , UnifyContext.GetSerializerSettings(context)));
+ var ex = context.Exception as EZCoreException;
+ if (ex != null)
+ {
+ //濡傛灉鏄紓甯哥壒娈婃姏鍑虹殑寮傚父锛岃繖閲岄渶瑕佸鐞嗙姸鎬佺爜
+ context.HttpContext.Response.StatusCode = (int)ex.StatusCode;
+
+ }
+
+ return new JsonResult(EzCoreFulResult(metadata.StatusCode, Code: 0, data: metadata.Data, errors: metadata.Errors)
+ , UnifyContext.GetSerializerSettings(context)); // 褰撳墠琛屼粎闄� Furion 4.6.6+ 浣跨敤
+ }
+
+ /// <summary>
+ /// 鎴愬姛杩斿洖鍊�
+ /// </summary>
+ /// <param name="context"></param>
+ /// <param name="data"></param>
+ /// <returns></returns>
+ public IActionResult OnSucceeded(ActionExecutedContext context, object data)
+ {
+
+ return new JsonResult(EzCoreFulResult(StatusCodes.Status200OK, 1, data)
+ , UnifyContext.GetSerializerSettings(context)); // 褰撳墠琛屼粎闄� Furion 4.6.6+ 浣跨敤
+ }
+
+ /// <summary>
+ /// 楠岃瘉澶辫触杩斿洖鍊�
+ /// </summary>
+ /// <param name="context"></param>
+ /// <param name="metadata"></param>
+ /// <returns></returns>
+ public IActionResult OnValidateFailed(ActionExecutingContext context, ValidationMetadata metadata)
+ {
+ //璁剧疆杩斿洖鐘舵�佺爜
+
+ return new JsonResult(EzCoreFulResult(metadata.StatusCode ?? StatusCodes.Status400BadRequest, Code: 0, data: metadata.Data, errors: metadata.ValidationResult)
+ , UnifyContext.GetSerializerSettings(context)); // 褰撳墠琛屼粎闄� Furion 4.6.6+ 浣跨敤
+ }
+
+ /// <summary>
+ /// 鐗瑰畾鐘舵�佺爜杩斿洖鍊� OnResponseStatusCodes
+ /// </summary>
+ /// <param name="context"></param>
+ /// <param name="statusCode"></param>
+ /// <param name="unifyResultSettings"></param>
+ /// <returns></returns>
+ public async Task OnResponseStatusCodes(HttpContext context, int statusCode, UnifyResultSettingsOptions unifyResultSettings)
+ {
+ // 璁剧疆鍝嶅簲鐘舵�佺爜
+ UnifyContext.SetResponseStatusCodes(context, statusCode, unifyResultSettings);
+
+ switch (statusCode)
+ {
+ // 澶勭悊 401 鐘舵�佺爜
+ case StatusCodes.Status401Unauthorized:
+ context.Response.StatusCode = statusCode;
+ await context.Response.WriteAsJsonAsync(EzCoreFulResult(statusCode, Code: 0, errors: "401 Unauthorized")
+ , App.GetOptions<JsonOptions>()?.JsonSerializerOptions);
+
+ break;
+ // 澶勭悊 403 鐘舵�佺爜 杞崲涓�401鐘舵�佺爜
+ case StatusCodes.Status403Forbidden:
+ context.Response.StatusCode = StatusCodes.Status401Unauthorized;
+ await context.Response.WriteAsJsonAsync(EzCoreFulResult(statusCode, Code: 0, errors: "403 Forbidden")
+ , App.GetOptions<JsonOptions>()?.JsonSerializerOptions);
+ break;
+
+ default: break;
+ }
+ }
+
+ /// <summary>
+ /// 杩斿洖 RESTful 椋庢牸缁撴灉闆�
+ /// </summary>
+ /// <param name="statusCode"></param>
+ /// <param name="Code">鎴愬姛鐘舵�佺爜</param>
+ /// <param name="data"></param>
+ /// <param name="errors"></param>
+ /// <returns></returns>
+ private static EzCoreResultMode<object> EzCoreFulResult(int statusCode, int Code = 1, object data = default, object errors = default)
+ {
+ return new EzCoreResultMode<object>
+ {
+ Code = Code,
+ StatusCode = statusCode,
+ Data = data,
+ Error = errors,
+ Extras = UnifyContext.Take(),
+ Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
+ };
+ }
+
+ public IActionResult OnAuthorizeException(DefaultHttpContext context, ExceptionMetadata metadata)
+ {
+ throw new NotImplementedException();
+ }
+ }
+ /// <summary>
+ /// 缁熶竴杩斿洖绫诲瀷妯″瀷瀹氫箟
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+
+ public class EzCoreResultMode<T>
+ {
+ /// <summary>
+ /// 鏍囧噯鐘舵�佺爜
+ /// </summary>
+ public int? StatusCode { get; set; }
+ /// <summary>
+ /// 鐘舵�佺爜
+ /// </summary>
+ public int? Code { get; set; }
+
+ /// <summary>
+ /// 鏁版嵁
+ /// </summary>
+ public T? Data { get; set; }
+
+
+
+ /// <summary>
+ /// 閿欒淇℃伅
+ /// </summary>
+ public object Error { get; set; }
+
+ /// <summary>
+ /// 闄勫姞鏁版嵁
+ /// </summary>
+ public object Extras { get; set; }
+
+ /// <summary>
+ /// 鏃堕棿鎴�
+ /// </summary>
+ public long? Timestamp { get; set; }
+ /// <summary>
+ /// 鍏朵粬娑堟伅
+ /// </summary>
+ public string Message { get; set; }
+ }
+}
diff --git a/cylsg/cylsg.Web.Core/Handlers/JwtHandler.cs b/cylsg/cylsg.Web.Core/Handlers/JwtHandler.cs
index 62ea9a7..82fba50 100644
--- a/cylsg/cylsg.Web.Core/Handlers/JwtHandler.cs
+++ b/cylsg/cylsg.Web.Core/Handlers/JwtHandler.cs
@@ -3,7 +3,7 @@
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
-namespace cylsg.Web.Core;
+namespace cylsg.Web.Core.Handlers;
public class JwtHandler : AppAuthorizeHandler
{
diff --git a/cylsg/cylsg.Web.Core/Startup.cs b/cylsg/cylsg.Web.Core/Startup.cs
index d0e2936..0737f0c 100644
--- a/cylsg/cylsg.Web.Core/Startup.cs
+++ b/cylsg/cylsg.Web.Core/Startup.cs
@@ -1,4 +1,5 @@
锘縰sing cylsg.Core;
+using cylsg.Web.Core.Handlers;
using Furion;
using Furion.VirtualFileServer;
using Microsoft.AspNetCore.Builder;
@@ -24,9 +25,9 @@
return DbContext.Instance;
}
);
-
- services.AddControllersWithViews()
- .AddInjectWithUnifyResult();
+
+ services.AddControllersWithViews()
+ .AddInjectWithUnifyResult<EzCoreRESTFulResultProvider>();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
diff --git a/cylsg/cylsg.Web.Core/cylsg.Web.Core.csproj b/cylsg/cylsg.Web.Core/cylsg.Web.Core.csproj
index e2fcc82..b558568 100644
--- a/cylsg/cylsg.Web.Core/cylsg.Web.Core.csproj
+++ b/cylsg/cylsg.Web.Core/cylsg.Web.Core.csproj
@@ -15,6 +15,7 @@
<ItemGroup>
<ProjectReference Include="..\cylsg.Application\cylsg.Application.csproj" />
+ <ProjectReference Include="..\cylsg.Authorization\cylsg.Authorization.csproj" />
</ItemGroup>
</Project>
diff --git a/cylsg/cylsg.Web.Core/cylsg.Web.Core.xml b/cylsg/cylsg.Web.Core/cylsg.Web.Core.xml
index b670981..b47494c 100644
--- a/cylsg/cylsg.Web.Core/cylsg.Web.Core.xml
+++ b/cylsg/cylsg.Web.Core/cylsg.Web.Core.xml
@@ -4,5 +4,94 @@
<name>cylsg.Web.Core</name>
</assembly>
<members>
+ <member name="T:cylsg.Web.Core.Handlers.EzCoreRESTFulResultProvider">
+ <summary>
+ 缁熶竴杩斿洖缁撴灉
+ </summary>
+ </member>
+ <member name="M:cylsg.Web.Core.Handlers.EzCoreRESTFulResultProvider.OnException(Microsoft.AspNetCore.Mvc.Filters.ExceptionContext,Furion.FriendlyException.ExceptionMetadata)">
+ <summary>
+ 寮傚父杩斿洖鍊�
+ </summary>
+ <param name="context"></param>
+ <param name="metadata"></param>
+ <returns></returns>
+ </member>
+ <member name="M:cylsg.Web.Core.Handlers.EzCoreRESTFulResultProvider.OnSucceeded(Microsoft.AspNetCore.Mvc.Filters.ActionExecutedContext,System.Object)">
+ <summary>
+ 鎴愬姛杩斿洖鍊�
+ </summary>
+ <param name="context"></param>
+ <param name="data"></param>
+ <returns></returns>
+ </member>
+ <member name="M:cylsg.Web.Core.Handlers.EzCoreRESTFulResultProvider.OnValidateFailed(Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext,Furion.DataValidation.ValidationMetadata)">
+ <summary>
+ 楠岃瘉澶辫触杩斿洖鍊�
+ </summary>
+ <param name="context"></param>
+ <param name="metadata"></param>
+ <returns></returns>
+ </member>
+ <member name="M:cylsg.Web.Core.Handlers.EzCoreRESTFulResultProvider.OnResponseStatusCodes(Microsoft.AspNetCore.Http.HttpContext,System.Int32,Furion.UnifyResult.UnifyResultSettingsOptions)">
+ <summary>
+ 鐗瑰畾鐘舵�佺爜杩斿洖鍊� OnResponseStatusCodes
+ </summary>
+ <param name="context"></param>
+ <param name="statusCode"></param>
+ <param name="unifyResultSettings"></param>
+ <returns></returns>
+ </member>
+ <member name="M:cylsg.Web.Core.Handlers.EzCoreRESTFulResultProvider.EzCoreFulResult(System.Int32,System.Int32,System.Object,System.Object)">
+ <summary>
+ 杩斿洖 RESTful 椋庢牸缁撴灉闆�
+ </summary>
+ <param name="statusCode"></param>
+ <param name="Code">鎴愬姛鐘舵�佺爜</param>
+ <param name="data"></param>
+ <param name="errors"></param>
+ <returns></returns>
+ </member>
+ <member name="T:cylsg.Web.Core.Handlers.EzCoreResultMode`1">
+ <summary>
+ 缁熶竴杩斿洖绫诲瀷妯″瀷瀹氫箟
+ </summary>
+ <typeparam name="T"></typeparam>
+ </member>
+ <member name="P:cylsg.Web.Core.Handlers.EzCoreResultMode`1.StatusCode">
+ <summary>
+ 鏍囧噯鐘舵�佺爜
+ </summary>
+ </member>
+ <member name="P:cylsg.Web.Core.Handlers.EzCoreResultMode`1.Code">
+ <summary>
+ 鐘舵�佺爜
+ </summary>
+ </member>
+ <member name="P:cylsg.Web.Core.Handlers.EzCoreResultMode`1.Data">
+ <summary>
+ 鏁版嵁
+ </summary>
+ </member>
+ <member name="P:cylsg.Web.Core.Handlers.EzCoreResultMode`1.Error">
+ <summary>
+ 閿欒淇℃伅
+ </summary>
+ </member>
+ <member name="P:cylsg.Web.Core.Handlers.EzCoreResultMode`1.Extras">
+ <summary>
+ 闄勫姞鏁版嵁
+ </summary>
+ </member>
+ <member name="P:cylsg.Web.Core.Handlers.EzCoreResultMode`1.Timestamp">
+ <summary>
+ 鏃堕棿鎴�
+ </summary>
+ </member>
+ <member name="P:cylsg.Web.Core.Handlers.EzCoreResultMode`1.Message">
+ <summary>
+ 鍏朵粬娑堟伅
+ </summary>
+ </member>
</members>
</doc>
diff --git a/cylsg/cylsg.Web.Entry/appsettings.json b/cylsg/cylsg.Web.Entry/appsettings.json
index 282b349..8f4963f 100644
--- a/cylsg/cylsg.Web.Entry/appsettings.json
+++ b/cylsg/cylsg.Web.Entry/appsettings.json
@@ -14,10 +14,27 @@
//"DbType": "Sqlite",
//"IsAutoCloseConnection": true
-
- "ConnectionString": "Server=MS-FSEUTNLCXFDB\\SQLEXPRESS;Database=CyLsgDb; MultipleActiveResultSets=true;pooling=true;min pool size=5;max pool size=32767;connect timeout=20;Encrypt=True;TrustServerCertificate=True;integrated security=True;",
- "DbType": "SqlServer", // "SqlServer" ,mysql,
- "IsAutoCloseConnection": true
+
+ "ConnectionString": "Server=MS-FSEUTNLCXFDB\\SQLEXPRESS;Database=CyLsgDb; MultipleActiveResultSets=true;pooling=true;min pool size=5;max pool size=32767;connect timeout=20;Encrypt=True;TrustServerCertificate=True;integrated security=True;",
+ "DbType": "SqlServer", // "SqlServer" ,mysql,
+ "IsAutoCloseConnection": true
}
- ]
+
+
+
+ ],
+
+ "JWTSettings": {
+ "ValidateIssuerSigningKey": true, // 鏄惁楠岃瘉瀵嗛挜锛宐ool 绫诲瀷锛岄粯璁rue
+ "IssuerSigningKey": "129(*dasd09213)*(*jKDl65656656532jiohi", // 瀵嗛挜锛宻tring 绫诲瀷锛屽繀椤绘槸澶嶆潅瀵嗛挜锛岄暱搴﹀ぇ浜�16
+ "ValidateIssuer": true, // 鏄惁楠岃瘉绛惧彂鏂癸紝bool 绫诲瀷锛岄粯璁rue
+ "ValidIssuer": "www.51zhengcai.com", // 绛惧彂鏂癸紝string 绫诲瀷
+ "ValidateAudience": true, // 鏄惁楠岃瘉绛炬敹鏂癸紝bool 绫诲瀷锛岄粯璁rue
+ "ValidAudience": "www.51zhengcai.com", // 绛炬敹鏂癸紝string 绫诲瀷
+ "ValidateLifetime": true, // 鏄惁楠岃瘉杩囨湡鏃堕棿锛宐ool 绫诲瀷锛岄粯璁rue锛屽缓璁畉rue
+ "ExpiredTime": 20, // 杩囨湡鏃堕棿锛宭ong 绫诲瀷锛屽崟浣嶅垎閽燂紝榛樿20鍒嗛挓
+ "ClockSkew": 5, // 杩囨湡鏃堕棿瀹归敊鍊硷紝long 绫诲瀷锛屽崟浣嶇锛岄粯璁� 5绉�
+ "Algorithm": "HS256", // 鍔犲瘑绠楁硶锛宻tring 绫诲瀷锛岄粯璁� HS256
+ "RefreshTokenExpires": 1440 //鍒嗛挓 1澶� 1440鍒嗛挓
+ }
}
\ No newline at end of file
diff --git a/cylsg/cylsg.redis/EzCoreNetRedisService.cs b/cylsg/cylsg.redis/EzCoreNetRedisService.cs
new file mode 100644
index 0000000..ba679b1
--- /dev/null
+++ b/cylsg/cylsg.redis/EzCoreNetRedisService.cs
@@ -0,0 +1,104 @@
+锘縰sing Furion;
+using Furion.DependencyInjection;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EzCoreNet.Redis
+{
+ public class EzCoreNetRedisService : IEzCoreNetRedisService,IScoped
+ {
+ public bool Add(string key, object value, int expireSeconds)
+ {
+ return RedisHelper.Set(key, value, expireSeconds);
+ }
+
+
+ public bool DelKey(string key)
+ {
+ RedisHelper.Del(key);
+ return true;
+ }
+
+ public T? Get<T>(string key)
+ {
+ return RedisHelper.Get<T>(key);
+ }
+
+ public long GetTtl(string key)
+ {
+
+ return RedisHelper.Ttl(key);
+ }
+
+ public bool SetTtl(string key, int ttl)
+ {
+ return RedisHelper.Expire(key, ttl);
+ }
+
+ /// <summary>
+ /// 璁剧疆涓�涓敭鍊�
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="key"></param>
+ /// <param name="value"></param>
+ /// <returns></returns>
+ public bool Add<T>(string key, T value, int expireSeconds = -1)
+ {
+ return RedisHelper.Set(key, value, expireSeconds);
+ }
+
+ public async Task<long> delegateAllKeyWith(string Prefix)
+ {
+ // 浣跨敤Scan妯″紡鍖归厤鎵�鏈夌鍚堝墠缂�鐨刱ey
+ var keys = GetAllKey(Prefix);
+
+ // 鎵归噺鍒犻櫎鎵惧埌鐨刱eys
+ if (keys != null && keys.Count() > 0)
+ {
+ return await RedisHelper.DelAsync(keys.ToArray());
+ }
+
+ return 0; // 濡傛灉娌℃湁鎵惧埌鍖归厤鐨刱ey锛岃繑鍥�0
+ }
+
+ public IEnumerable<string> GetAllKey(string Prefix)
+ {
+ return RedisHelper.Keys(Prefix + "*");
+ }
+
+ /// <summary>
+ /// 鍚庡幓涓�涓紦瀛橈紝濡傛灉娌℃湁锛屽垯浠庢暟鎹簱涓幏鍙栵紝
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="key"></param>
+ /// <param name="DataFormSql">璇诲彇鏂规硶</param>
+ /// <param name="dc"> 璇诲彇鐨勬暟鎹簱鏈嶅姟</param>
+ /// <param name="expireSeconds"></param>
+ /// <returns></returns>
+
+ public T? GetAndRefCacheKey<T>(string key, Func<ISqlSugarClient, T> DataFormSql, ISqlSugarClient? dc = null, int? expireSeconds = 3600)
+ {
+ var Data = RedisHelper.Get<T>(key);
+ if (Data == null && DataFormSql != null)
+ {
+ if (dc == null)
+ dc = App.GetService<ISqlSugarClient>();
+ Data = DataFormSql.Invoke(dc);
+
+ // Data = DataFormSql.BeginInvoke(dc,ar=> DataFormSql.EndInvoke(ar),null);
+ if (expireSeconds == null)
+ expireSeconds = -1;
+ if (Data != null)
+ RedisHelper.Set(key, Data, (int)expireSeconds);
+
+ }
+ return Data;
+ }
+
+
+ }
+}
diff --git a/cylsg/cylsg.redis/IEzCoreNetRedisService.cs b/cylsg/cylsg.redis/IEzCoreNetRedisService.cs
new file mode 100644
index 0000000..853b9d2
--- /dev/null
+++ b/cylsg/cylsg.redis/IEzCoreNetRedisService.cs
@@ -0,0 +1,80 @@
+锘縰sing SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EzCoreNet.Redis
+{
+ /// <summary>
+ /// ezcore 瀵箁edis 灏佽
+ /// </summary>
+ public interface IEzCoreNetRedisService
+ {
+ /// <summary>
+ /// 璁剧疆涓�涓敭鍊�
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="key"></param>
+ /// <param name="value"></param>
+ /// <param name="expireSeconds"></param>
+ /// <returns></returns>
+ bool Add(string key, object value, int expireSeconds);
+ /// <summary>
+ /// 鑾峰彇涓�涓敭鍊�
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="key"></param>
+ /// <returns></returns>
+ T? Get<T>(string key);
+ /// <summary>
+ /// 鑾峰彇閿�煎墿浣欒繃鏃堕棿 绉掔骇
+ /// </summary>
+ /// <param name="key"></param>
+ /// <returns></returns>
+ long GetTtl(string key);
+
+ /// <summary>
+ /// 鍒犻櫎閿��
+ /// </summary>
+ /// <param name="key"></param>
+ /// <returns></returns>
+ bool DelKey(string key);
+ /// <summary>
+ /// 缁檏ey璁剧疆 鏈夋晥鏃堕棿
+ /// </summary>
+ /// <param name="key"></param>
+ /// <param name="ttl"></param>
+ /// <returns></returns>
+ bool SetTtl(string key, int ttl);
+
+ /// <summary>
+ /// 璁剧疆涓�涓敭鍊�
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="key"></param>
+ /// <param name="value"></param>
+ /// <param name="expireSeconds"></param>
+ /// <returns></returns>
+ bool Add<T>(string key, T value, int expireSeconds);
+
+
+ /// <summary>
+ /// 鑾峰彇涓�涓紦瀛橈紝濡傛灉涓嶅瓨鍦紝鑰呮牴鎹瓺ataFormSql 鍦ㄦ暟鎹簱涓幏鍙栫紦瀛橈紝骞朵繚瀛榚xpireSeconds 鏃堕棿锛�
+ /// </summary>
+ /// <typeparam name="T"> 绫诲瀷</typeparam>
+ /// <param name="key">Key</param>
+ /// <param name="DataFormSql">璇诲彇鏁版嵁鍑芥暟</param>
+ /// <param name="expireSeconds">杩囨湡鏃堕棿锛屼负绌鸿〃绀烘案涓嶈繃鏈燂紝榛樿涓�3600</param>
+ /// <returns></returns>
+ T? GetAndRefCacheKey<T>(string key, Func<ISqlSugarClient, T> DataFormSql, ISqlSugarClient? dc = null, int? expireSeconds = 3600);
+
+ /// <summary>
+ /// 鍒犻櫎浠ュ紑澶寸殑鎵�鏈夌粍浠讹紝涓昏鐢ㄤ簬鎿嶄綔鐩綍
+ /// </summary>
+ /// <param name="Prefix"></param>
+ /// <returns></returns>
+ Task<long> delegateAllKeyWith(string Prefix);
+ }
+}
diff --git a/cylsg/cylsg.redis/RedisConfig.json b/cylsg/cylsg.redis/RedisConfig.json
new file mode 100644
index 0000000..f817c47
--- /dev/null
+++ b/cylsg/cylsg.redis/RedisConfig.json
@@ -0,0 +1,8 @@
+{
+ //璇蜂繚鎸乺edis涓烘甯稿彲鐢�
+ "RedisConfig": {
+ // 濡傛灉閲囩敤瀹瑰櫒鍖栭儴缃睸ervice 瑕佸啓鎴恟edis鐨勬湇鍔″悕锛屽惁鍒欏啓鍦板潃
+ "ConnectionString": "127.0.0.1:6379,password=,connectTimeout=30000,responseTimeout=30000,abortConnect=false,connectRetry=1,syncTimeout=10000,DefaultDatabase=1" //redis鏁版嵁搴撹繛鎺ュ瓧绗︿覆
+
+ }
+}
diff --git a/cylsg/cylsg.redis/Startup.cs b/cylsg/cylsg.redis/Startup.cs
new file mode 100644
index 0000000..f005e3a
--- /dev/null
+++ b/cylsg/cylsg.redis/Startup.cs
@@ -0,0 +1,53 @@
+锘縰sing cylsg.Core;
+using Furion;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Options;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EzCoreNet.Redis
+{
+ /// <summary>
+ /// 灏佽娉ㄥ唽鍑芥暟鍜岄厤缃嚱鏁�
+ /// </summary>
+ public static class startup
+ {
+ public static void AddEzCoreNetRedisService(this IServiceCollection services, Action<opentions>? redisOptions = null)
+ {
+
+ opentions op = new opentions();
+ if (redisOptions != null)
+ {
+ redisOptions.Invoke(op);
+ }
+ //鍙娇鐢ㄦ櫘閫氭ā寮忥紝鍏朵粬鍚庣画寮�鍙�
+ var cs = new CSRedis.CSRedisClient(op.Configuration);
+ //娉ㄥ叆閾炬帴
+ RedisHelper.Initialization(cs);
+
+ services.AddScoped<IEzCoreNetRedisService, EzCoreNetRedisService>();
+
+ }
+ }
+
+
+ public class RedisStartup : AppStartup
+ {
+ public void ConfigureServices(IServiceCollection services)
+ {
+ services.AddEzCoreNetRedisService(op=>
+ {
+ op.Configuration = App.Configuration["RedisConfig:ConnectionString"];
+ });
+
+
+ }
+
+ }
+}
diff --git a/cylsg/cylsg.redis/cylsg.redis.csproj b/cylsg/cylsg.redis/cylsg.redis.csproj
new file mode 100644
index 0000000..d71de94
--- /dev/null
+++ b/cylsg/cylsg.redis/cylsg.redis.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="CSRedisCore" Version="3.8.803" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\cylsg.Core\cylsg.Core.csproj" />
+ </ItemGroup>
+
+</Project>
diff --git a/cylsg/cylsg.redis/opentions.cs b/cylsg/cylsg.redis/opentions.cs
new file mode 100644
index 0000000..7dc3243
--- /dev/null
+++ b/cylsg/cylsg.redis/opentions.cs
@@ -0,0 +1,23 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EzCoreNet.Redis
+{
+ public class opentions
+ {
+ /// <summary>
+ /// 榛樿鏈満閾炬帴 鏁版嵁搴撲负0
+ /// </summary>
+ public opentions()
+ {
+ Configuration = "127.0.0.1:6379,password=,connectTimeout=30000,responseTimeout=30000,abortConnect=false,connectRetry=1,syncTimeout=10000,DefaultDatabase=1";
+ }
+ /// <summary>
+ /// 閾炬帴瀛楃涓�
+ /// </summary>
+ public string Configuration { get; set; }
+ }
+}
diff --git a/cylsg/cylsg.services/cylsg.services.csproj b/cylsg/cylsg.services/cylsg.services.csproj
new file mode 100644
index 0000000..192e1ed
--- /dev/null
+++ b/cylsg/cylsg.services/cylsg.services.csproj
@@ -0,0 +1,14 @@
+锘�<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>net8.0</TargetFramework>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\cylsg.Core\cylsg.Core.csproj" />
+ <ProjectReference Include="..\cylsg.Model\cylsg.Model.csproj" />
+ </ItemGroup>
+
+</Project>
diff --git a/cylsg/cylsg.sln b/cylsg/cylsg.sln
index 71542db..bb4f5ca 100644
--- a/cylsg/cylsg.sln
+++ b/cylsg/cylsg.sln
@@ -15,6 +15,14 @@
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cylsg.utility", "cylsg.utility\cylsg.utility.csproj", "{5ED2C481-2D74-43BC-ABAF-1455A052FAA4}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EzWechat", "EzWechat\EzWechat.csproj", "{709CC927-07D3-4400-BD57-838A44B4FBD4}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cylsg.services", "cylsg.services\cylsg.services.csproj", "{28CCF771-A760-4191-B299-4E53B5B23D91}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cylsg.redis", "cylsg.redis\cylsg.redis.csproj", "{15042E77-32D5-46DE-9CE5-24D093C63422}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cylsg.Authorization", "cylsg.Authorization\cylsg.Authorization.csproj", "{1197C9BB-C73D-42FB-A114-AFB0A7466615}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -45,6 +53,22 @@
{5ED2C481-2D74-43BC-ABAF-1455A052FAA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5ED2C481-2D74-43BC-ABAF-1455A052FAA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5ED2C481-2D74-43BC-ABAF-1455A052FAA4}.Release|Any CPU.Build.0 = Release|Any CPU
+ {709CC927-07D3-4400-BD57-838A44B4FBD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {709CC927-07D3-4400-BD57-838A44B4FBD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {709CC927-07D3-4400-BD57-838A44B4FBD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {709CC927-07D3-4400-BD57-838A44B4FBD4}.Release|Any CPU.Build.0 = Release|Any CPU
+ {28CCF771-A760-4191-B299-4E53B5B23D91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {28CCF771-A760-4191-B299-4E53B5B23D91}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {28CCF771-A760-4191-B299-4E53B5B23D91}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {28CCF771-A760-4191-B299-4E53B5B23D91}.Release|Any CPU.Build.0 = Release|Any CPU
+ {15042E77-32D5-46DE-9CE5-24D093C63422}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {15042E77-32D5-46DE-9CE5-24D093C63422}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {15042E77-32D5-46DE-9CE5-24D093C63422}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {15042E77-32D5-46DE-9CE5-24D093C63422}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1197C9BB-C73D-42FB-A114-AFB0A7466615}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1197C9BB-C73D-42FB-A114-AFB0A7466615}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1197C9BB-C73D-42FB-A114-AFB0A7466615}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1197C9BB-C73D-42FB-A114-AFB0A7466615}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
--
Gitblit v1.9.1