From 6d9a0ede045129f6c57e51a7a3ff241e82ad3a71 Mon Sep 17 00:00:00 2001 From: hudingwen <765472804@qq.com> Date: Tue, 2 Aug 2022 21:53:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4dal=E5=86=97=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81,=E7=A7=91=E5=AD=A6=E4=B8=8A=E7=BD=91?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Blog.Core.Api/Blog.Core.Model.xml | 137 +++ Blog.Core.Api/Blog.Core.xml | 158 +++ Blog.Core.Api/Controllers/TrojanController.cs | 455 +++++++ Blog.Core.Api/appsettings.json | 11 +- .../Extensions/Extention.Expression.cs | 387 ++++++ Blog.Core.Common/Helper/ShaHelper.cs | 1096 +++++++++++++++++ .../AutofacModuleRegister.cs | 3 + Blog.Core.IServices/ITrojanUsersServices.cs | 14 + Blog.Core.Model/Models/TrojanCusServers.cs | 25 + Blog.Core.Model/Models/TrojanDetails.cs | 62 + Blog.Core.Model/Models/TrojanServers.cs | 30 + Blog.Core.Model/Models/TrojanUrlServers.cs | 25 + Blog.Core.Model/Models/TrojanUsers.cs | 38 + .../ViewModels/TrojanLimitFlowDto.cs | 23 + Blog.Core.Model/ViewModels/TrojanServerDto.cs | 14 + .../ViewModels/TrojanServerSpliceDto.cs | 28 + .../ViewModels/TrojanUseDetailDto.cs | 35 + Blog.Core.Services/AccessTrendLogServices.cs | 6 - Blog.Core.Services/AdvertisementServices.cs | 7 - Blog.Core.Services/BASE/BaseServices.cs | 4 + Blog.Core.Services/BlogArticleServices.cs | 1 - Blog.Core.Services/DepartmentServices.cs | 7 +- Blog.Core.Services/GuestbookServices.cs | 19 +- .../IDS4Db/ApplicationUserServices.cs | 7 - Blog.Core.Services/ModuleServices.cs | 7 - Blog.Core.Services/OperateLogServices.cs | 6 - Blog.Core.Services/PasswordLibServices.cs | 6 - Blog.Core.Services/PayServices.cs | 5 +- Blog.Core.Services/PermissionServices.cs | 7 - .../RoleModulePermissionServices.cs | 3 +- Blog.Core.Services/RoleServices.cs | 7 - Blog.Core.Services/TasksQzServices.cs | 6 - Blog.Core.Services/TopicDetailServices.cs | 7 - Blog.Core.Services/TopicServices.cs | 8 - Blog.Core.Services/TrojanUsersServices.cs | 18 + Blog.Core.Services/UserRoleServices.cs | 7 - Blog.Core.Services/WeChatCompanyServices.cs | 5 +- Blog.Core.Services/WeChatConfigServices.cs | 31 +- Blog.Core.Services/WeChatPushLogServices.cs | 12 +- Blog.Core.Services/WeChatSubServices.cs | 10 - Blog.Core.Services/sysUserInfoServices.cs | 6 +- 41 files changed, 2588 insertions(+), 155 deletions(-) create mode 100644 Blog.Core.Api/Controllers/TrojanController.cs create mode 100644 Blog.Core.Common/Extensions/Extention.Expression.cs create mode 100644 Blog.Core.Common/Helper/ShaHelper.cs create mode 100644 Blog.Core.IServices/ITrojanUsersServices.cs create mode 100644 Blog.Core.Model/Models/TrojanCusServers.cs create mode 100644 Blog.Core.Model/Models/TrojanDetails.cs create mode 100644 Blog.Core.Model/Models/TrojanServers.cs create mode 100644 Blog.Core.Model/Models/TrojanUrlServers.cs create mode 100644 Blog.Core.Model/Models/TrojanUsers.cs create mode 100644 Blog.Core.Model/ViewModels/TrojanLimitFlowDto.cs create mode 100644 Blog.Core.Model/ViewModels/TrojanServerDto.cs create mode 100644 Blog.Core.Model/ViewModels/TrojanServerSpliceDto.cs create mode 100644 Blog.Core.Model/ViewModels/TrojanUseDetailDto.cs create mode 100644 Blog.Core.Services/TrojanUsersServices.cs diff --git a/Blog.Core.Api/Blog.Core.Model.xml b/Blog.Core.Api/Blog.Core.Model.xml index 8437e22..e75b50d 100644 --- a/Blog.Core.Api/Blog.Core.Model.xml +++ b/Blog.Core.Api/Blog.Core.Model.xml @@ -922,6 +922,76 @@ Tibug 博文 + + + users自定义服务器 + + + + + 用户流量每月汇总表 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Trojan服务器 + + + + + users自定义URL服务器 + + + + + Trojan用户 + + + + + 历史流量记录 + + 用户跟角色关联表 @@ -2347,6 +2417,73 @@ + + + 限制流量dto + 作者:胡丁文 + 时间:2020-4-27 16:57:07 + + + + + 用户 + + + + + 流量(-1为无限,单位为最小单位byte) + + + + + Trojan服务器拼接服务器和订阅地址 + + + + + 普通订阅连接 + + + + + clash订阅连接 + + + + + 备用clash订阅连接 + + + + + Trojan用户流量统计分组 + + + + + 用户ID + + + + + 月度 + + + + + 上传流量 + + + + + 下载流量 + + + + + 下载流量 + + 微信接口消息DTO diff --git a/Blog.Core.Api/Blog.Core.xml b/Blog.Core.Api/Blog.Core.xml index f5df626..e26c917 100644 --- a/Blog.Core.Api/Blog.Core.xml +++ b/Blog.Core.Api/Blog.Core.xml @@ -639,6 +639,164 @@ + + + 获取Trojan用户 + + + + + + + 获取Trojan用户 + + + + + + + 获取Trojan用户-下拉列表用 + + + + + + 添加Trojan用户 + + + + + + + 更新Trojan用户 + + + + + + + 删除用户 + + + + + + + 重置流量 + + + + + + + 限制流量 + + + + + + + 重置链接密码 + + + + + + + 获取Trojan服务器 + + + + + + 获取拼接后的Trojan服务器 + + passwordshow + + + + + 删除Trojan服务器 + + + + + + + 更新Trojan服务器 + + + + + + + 添加Trojan服务器 + + + + + + + 获取Cus服务器 + + + + + + 删除Cus服务器 + + + + + + + 更新Cus服务器 + + + + + + + 添加Cus服务器 + + + + + + + 获取Url服务器 + + + + + + 删除Url服务器 + + + + + + + 更新Url服务器 + + + + + + + 添加Url服务器 + + + + + + + 获取订阅数据 + + 链接密码 + 是否使用base64加密 + + 用户管理 diff --git a/Blog.Core.Api/Controllers/TrojanController.cs b/Blog.Core.Api/Controllers/TrojanController.cs new file mode 100644 index 0000000..5d800cb --- /dev/null +++ b/Blog.Core.Api/Controllers/TrojanController.cs @@ -0,0 +1,455 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Blog.Core.Common; +using Blog.Core.Common.Extensions; +using Blog.Core.Common.Helper; +using Blog.Core.Common.HttpContextUser; +using Blog.Core.IServices; +using Blog.Core.IServices.BASE; +using Blog.Core.Model; +using Blog.Core.Model.Models; +using Blog.Core.Model.ViewModels; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Blog.Core.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + [Authorize(Permissions.Name)] + public class TrojanController : ControllerBase + { + private ITrojanUsersServices _trojanUsersServices; + public IBaseServices _baseServicesServers; + public IBaseServices _baseServicesDetails; + public IBaseServices _baseServicesCusServers; + public IBaseServices _baseServicesUrlServers; + private IUser _user; + public TrojanController(ITrojanUsersServices trojanUsersServices,IUser user + , IBaseServices baseServicesServers + , IBaseServices baseServicesDetails + , IBaseServices baseServicesCusServers + , IBaseServices baseServicesUrlServers) + { + _baseServicesDetails = baseServicesDetails; + _baseServicesServers = baseServicesServers; + _trojanUsersServices = trojanUsersServices; + _baseServicesCusServers = baseServicesCusServers; + _baseServicesUrlServers = baseServicesUrlServers; + _user = user; + } + /// + /// 获取Trojan用户 + /// + /// + /// + [HttpGet] + public async Task>> GetUser([FromQuery]PaginationModel pagination) + { + return await GetAllUser(pagination); + } + /// + /// 获取Trojan用户 + /// + /// + /// + [HttpGet] + public async Task>> GetAllUser([FromQuery]PaginationModel pagination) + { + var data = await _trojanUsersServices.QueryPage(pagination); + if (data.data.Count > 0) + { + var ids = data.data.Select(t => t.id).ToList(); + var where = LinqHelper.True(); + where = where.And(t => ids.Contains(t.userId)).And(t => t.calDate < DateTime.Now).And(t => t.calDate > DateTime.Now.AddMonths(-12)); + var userDetails = await _baseServicesDetails.Query(where); + foreach (var trojanUser in data.data) + { + + var ls = from t in userDetails + where t.userId == trojanUser.id + group t by new { moth = t.calDate.ToString("yyyy-MM"), id = t.userId } into g + orderby g.Key.moth descending + select new TrojanUseDetailDto { userId = g.Key.id, moth = g.Key.moth, up = g.Sum(t => Convert.ToDecimal(t.upload)), down = g.Sum(t => Convert.ToDecimal(t.download)) }; + var lsData = ls.ToList(); + trojanUser.useList = lsData; + } + } + return MessageModel>.Success("获取成功", data); + } + + /// + /// 获取Trojan用户-下拉列表用 + /// + /// + [HttpGet] + public async Task> GetAllTrojanUser() + { + var data = await _trojanUsersServices.QueryTable("select id,username from users"); + return MessageModel.Success("获取成功", data); + } + /// + /// 添加Trojan用户 + /// + /// + /// + [HttpPost] + public async Task> AddUser([FromBody]TrojanUsers user) + { + var find = await _trojanUsersServices.Query(t => t.username == user.username); + if(find!=null && find.Count>0) return MessageModel.Fail("用户名已存在"); + var pass = StringHelper.GetGUID(); + var passEcrypt = ShaHelper.Sha224(pass); + //user.quota = 0; + user.upload = 0; + user.download = 0; + user.password = passEcrypt; + user.passwordshow = pass; + var data = await _trojanUsersServices.Add(user); + return MessageModel.Success("添加成功", data); + } + /// + /// 更新Trojan用户 + /// + /// + /// + [HttpPut] + public async Task> UpdateUser([FromBody]TrojanUsers user) + { + var find = await _trojanUsersServices.QueryById(user.id); + if (find == null) return MessageModel.Fail("用户名不存在"); + find.username = user.username; + var data = await _trojanUsersServices.Update(find, new List { "username" }); + return MessageModel.Success("更新成功", data); + } + + /// + /// 删除用户 + /// + /// + /// + [HttpPut] + public async Task> DelUser([FromBody]int[] users) + { + var data = await _trojanUsersServices.Query(t => users.Contains(t.id)); + var list = data.Select(t => t.id.ToString()).ToArray(); + await _trojanUsersServices.DeleteByIds(list); + return MessageModel.Success("删除成功"); + } + /// + /// 重置流量 + /// + /// + /// + [HttpPut] + public async Task> ResetFlow([FromBody]int[] users) + { + var data = await _trojanUsersServices.Query(t => users.Contains(t.id)); + foreach (var item in data) + { + item.upload = 0; + item.download = 0; + await _trojanUsersServices.Update(item, new List { "upload", "download" }); + } + return MessageModel.Success("重置流量成功"); + } + /// + /// 限制流量 + /// + /// + /// + [HttpPut] + public async Task> LimitFlow([FromBody] TrojanLimitFlowDto limit) + { + var data = await _trojanUsersServices.Query(t => limit.users.Contains(t.id)); + foreach (var item in data) + { + item.quota = limit.quota; + await _trojanUsersServices.Update(item, new List { "quota" }); + } + return MessageModel.Success("限制流量成功"); + } + /// + /// 重置链接密码 + /// + /// + /// + [HttpPut] + public async Task> ResetPass([FromBody]int[] users) + { + var data = await _trojanUsersServices.Query(t => users.Contains(t.id)); + var pass = StringHelper.GetGUID(); + var passEcrypt = ShaHelper.Sha224(pass); + foreach (var item in data) + { + item.password = passEcrypt; + item.passwordshow = pass; + await _trojanUsersServices.Update(item, new List { "password" , "passwordshow" }); + } + return MessageModel.Success("重置链接密码成功"); + } + /// + /// 获取Trojan服务器 + /// + /// + [HttpGet] + public async Task>> GetServers() + { + var data = await _baseServicesServers.Query(); + data = data.OrderBy(t => t.servername).ToList(); + return MessageModel>.Success("获取成功", data); + } + /// + /// 获取拼接后的Trojan服务器 + /// + /// passwordshow + /// + [HttpGet] + public async Task> GetSpliceServers(string id) + { + var data = await _baseServicesServers.Query(); + data = data.OrderBy(t => t.servername).ToList(); + var res = new TrojanServerSpliceDto(); + res.normalApi = Appsettings.app(new string[] { "trojan", "normalApi" }).ObjToString(); + res.clashApi = Appsettings.app(new string[] { "trojan", "clashApi" }).ObjToString(); + res.clashApiBackup = Appsettings.app(new string[] { "trojan", "clashApiBackup" }).ObjToString(); + foreach (var item in data) + { + var serverSplice = GetSplice(item, id); + res.list.Add(new TrojanServerDto { name = item.servername, value = serverSplice }); + } + return MessageModel.Success("获取成功", res); ; + + } + /// + /// 删除Trojan服务器 + /// + /// + /// + [HttpPut] + public async Task>> DelServers([FromBody]int[] servers) + { + var data = await _baseServicesServers.DeleteByIds(servers.Select(t=>t.ToString()).ToArray()); + if (data) + return MessageModel>.Success("删除成功"); + else + return MessageModel>.Fail("删除失败"); + } + /// + /// 更新Trojan服务器 + /// + /// + /// + [HttpPut] + public async Task>> UpdateServers(TrojanServers server) + { + var data = await _baseServicesServers.Update(server); + return MessageModel>.Success("更新成功"); + } + /// + /// 添加Trojan服务器 + /// + /// + /// + [HttpPost] + public async Task>> AddServers(TrojanServers server) + { + var data = await _baseServicesServers.Add(server); + return MessageModel>.Success("添加成功"); + } + + /// + /// 获取Cus服务器 + /// + /// + [HttpGet] + public async Task>> GetCusServers() + { + var data = await _baseServicesCusServers.Query(); + data = data.OrderBy(t => t.servername).ToList(); + return MessageModel>.Success("获取成功", data); + } + /// + /// 删除Cus服务器 + /// + /// + /// + [HttpPut] + public async Task>> DelCusServers([FromBody] int[] servers) + { + var data = await _baseServicesCusServers.DeleteByIds(servers.Select(t => t.ToString()).ToArray()); + if (data) + return MessageModel>.Success("删除成功"); + else + return MessageModel>.Fail("删除失败"); + } + /// + /// 更新Cus服务器 + /// + /// + /// + [HttpPut] + public async Task>> UpdateCusServers(TrojanCusServers server) + { + var data = await _baseServicesCusServers.Update(server); + return MessageModel>.Success("更新成功"); + } + /// + /// 添加Cus服务器 + /// + /// + /// + [HttpPost] + public async Task>> AddCusServers(TrojanCusServers server) + { + var data = await _baseServicesCusServers.Add(server); + return MessageModel>.Success("添加成功"); + } + + + /// + /// 获取Url服务器 + /// + /// + [HttpGet] + public async Task>> GetUrlServers() + { + var data = await _baseServicesUrlServers.Query(); + data = data.OrderBy(t => t.servername).ToList(); + return MessageModel>.Success("获取成功", data); + } + /// + /// 删除Url服务器 + /// + /// + /// + [HttpPut] + public async Task>> DelUrlServers([FromBody] int[] servers) + { + var data = await _baseServicesUrlServers.DeleteByIds(servers.Select(t => t.ToString()).ToArray()); + if (data) + return MessageModel>.Success("删除成功"); + else + return MessageModel>.Fail("删除失败"); + } + /// + /// 更新Url服务器 + /// + /// + /// + [HttpPut] + public async Task>> UpdateUrlServers(TrojanUrlServers server) + { + var data = await _baseServicesUrlServers.Update(server); + return MessageModel>.Success("更新成功"); + } + /// + /// 添加Url服务器 + /// + /// + /// + [HttpPost] + public async Task>> AddUrlServers(TrojanUrlServers server) + { + var data = await _baseServicesUrlServers.Add(server); + return MessageModel>.Success("添加成功"); + } + private string GetSplice(TrojanServers item,string passwordshow) + { + if ("0".Equals(item.servertype)) + return $"trojan://{passwordshow}@{item.serveraddress}:{item.serverport}?allowinsecure=0&tfo=0&peer={(string.IsNullOrEmpty(item.serverpeer) ? item.serverpeer : item.serveraddress)}#{item.servername}"; + else if ("1".Equals(item.servertype)) + return $"trojan://{passwordshow}@{item.serveraddress}:{item.serverport}?wspath={item.serverpath}&ws=1&peer={(string.IsNullOrEmpty(item.serverpeer) ? item.serverpeer : item.serveraddress)}#{item.servername}"; + else + return $"servertype:({item.servertype})错误"; + } + private List GetSplice(List items, string passwordshow) + { + List ls = new List(); + foreach (var item in items) + { + ls.Add(GetSplice(item, passwordshow)); + } + return ls; + } + /// + /// 获取订阅数据 + /// + /// 链接密码 + /// 是否使用base64加密 + /// + [HttpGet] + [AllowAnonymous] + public async Task RSS(string id,bool isUseBase64=true) + { + StringBuilder sb = new StringBuilder(); + try + { + var user = (await _trojanUsersServices.Query(t => t.passwordshow == id)).FirstOrDefault(); + if (user == null) throw new Exception("用户不存在"); + var data = await _baseServicesServers.Query(t => (t.userid == user.id || t.userid <= 0) && t.serverenable); + if (data != null) + { + data = data.OrderBy(t => t.servername).ToList(); + foreach (var item in data) + { + sb.AppendLine(GetSplice(item, user.passwordshow)); + } + } + var cusData = await _baseServicesCusServers.Query(t=> (t.userid == user.id || t.userid <=0) && t.serverenable); + if (cusData != null) + { + cusData = cusData.OrderBy(t => t.servername).ToList(); + foreach (var item in cusData) + { + sb.AppendLine(item.serveraddress); + } + } + var urlData = await _baseServicesUrlServers.Query(t => (t.userid == user.id || t.userid <= 0) && t.serverenable); + if (urlData != null) + { + urlData = urlData.OrderBy(t => t.servername).ToList(); + foreach (var item in urlData) + { + try + { + var urlStrObj = await HttpHelper.GetAsync(item.serveraddress); + var lines = ""; + try + { + lines = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(urlStrObj)); + } + catch (Exception) + { + lines = urlStrObj; + } + finally + { + sb.AppendLine(lines); + } + } + catch (Exception ex) + { + sb.AppendLine($"trojan://xxxxxx@xxxxxx.xx:443?allowinsecure=0&tfo=0#{ex.Message}"); + } + } + } + } + catch (Exception ex) + { + sb.AppendLine($"trojan://xxxxxx@xxxxxx.xx:443?allowinsecure=0&tfo=0#{ex.Message}"); + } + if (isUseBase64) + { + return Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sb.ToString())); + } + else{ + return sb.ToString(); + } + } + } +} \ No newline at end of file diff --git a/Blog.Core.Api/appsettings.json b/Blog.Core.Api/appsettings.json index 58da11e..301e1b2 100644 --- a/Blog.Core.Api/appsettings.json +++ b/Blog.Core.Api/appsettings.json @@ -82,7 +82,7 @@ // *** 多库操作,把 MutiDBEnabled 设为true,其他的从库Enabled也为true **; // 具体配置看视频:https://www.bilibili.com/video/BV1BJ411B7mn?p=6 - "MainDB": "WMBLOG_SQLITE", //当前项目的主库,所对应的连接字符串的Enabled必须为true + "MainDB": "WMBLOG_MYSQL_2", //当前项目的主库,所对应的连接字符串的Enabled必须为true "MutiDBEnabled": false, //是否开启多库模式 "CQRSEnabled": false, //是否开启读写分离模式,必须是单库模式,且数据库类型一致,比如都是SqlServer "DBS": [ @@ -131,7 +131,7 @@ "DBType": 0, "Enabled": true, "HitRate": 20, - "Connection": "server=.;Database=blogcore001;Uid=root;Pwd=123456;Port=3096;Allow User Variables=True;" + "Connection": "server=localhost;Database=blogcore001;Uid=root;Pwd=root;Port=3306;Allow User Variables=True;" }, { "ConnId": "WMBLOG_ORACLE", @@ -171,7 +171,7 @@ "EnableAllIPs": false, //当为true时,开放所有IP均可访问。 // 支持多个域名端口,注意端口号后不要带/斜杆:比如localhost:8000/,是错的 // 注意,http://127.0.0.1:1818 和 http://localhost:1818 是不一样的 - "IPs": "http://127.0.0.1:2364,http://localhost:2364" + "IPs": "http://127.0.0.1:2364,http://localhost:2364,http://127.0.0.1:6688,http://localhost:6688" }, "AppConfigAlert": { "Enabled": true @@ -291,5 +291,10 @@ "FiedValue": "Blog.Core.Api" } ] + }, + "trojan": {//科学上网订阅 + "normalApi": "http://localhost:9291/api/Trojan/RSS?id=", + "clashApi": "https://your-sub-service/sub?target=clash&insert=false&url=", + "clashApiBackup": "https://pub-api-1.bianyuan.xyz/sub?target=clash&insert=false&url=" } } diff --git a/Blog.Core.Common/Extensions/Extention.Expression.cs b/Blog.Core.Common/Extensions/Extention.Expression.cs new file mode 100644 index 0000000..9b746bd --- /dev/null +++ b/Blog.Core.Common/Extensions/Extention.Expression.cs @@ -0,0 +1,387 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; + +namespace Blog.Core.Common.Extensions +{ + public static partial class Extention + { + #region 拓展BuildExtendSelectExpre方法 + + /// + /// 组合继承属性选择表达式树,无拓展参数 + /// TResult将继承TBase的所有属性 + /// + /// 原数据类型 + /// 返回类型 + /// 拓展表达式 + /// + public static Expression> BuildExtendSelectExpre(this Expression> expression) where TResult : TBase + { + return GetExtendSelectExpre>(expression); + } + + /// + /// 组合继承属性选择表达式树,1个拓展参数 + /// TResult将继承TBase的所有属性 + /// + /// 原数据类型 + /// 拓展类型1 + /// 返回类型 + /// 拓展表达式 + /// + public static Expression> BuildExtendSelectExpre(this Expression> expression) where TResult : TBase + { + return GetExtendSelectExpre>(expression); + } + + /// + /// 组合继承属性选择表达式树,2个拓展参数 + /// TResult将继承TBase的所有属性 + /// + /// 原数据类型 + /// 拓展类型1 + /// 拓展类型2 + /// 返回类型 + /// 拓展表达式 + /// + public static Expression> BuildExtendSelectExpre(this Expression> expression) where TResult : TBase + { + return GetExtendSelectExpre>(expression); + } + + /// + /// 组合继承属性选择表达式树,3个拓展参数 + /// TResult将继承TBase的所有属性 + /// + /// 原数据类型 + /// 拓展类型1 + /// 拓展类型2 + /// 拓展类型3 + /// 返回类型 + /// 拓展表达式 + /// + public static Expression> BuildExtendSelectExpre(this Expression> expression) where TResult : TBase + { + return GetExtendSelectExpre>(expression); + } + + /// + /// 组合继承属性选择表达式树,4个拓展参数 + /// TResult将继承TBase的所有属性 + /// + /// 原数据类型 + /// 拓展类型1 + /// 拓展类型2 + /// 拓展类型3 + /// 拓展类型4 + /// 返回类型 + /// 拓展表达式 + /// + public static Expression> BuildExtendSelectExpre(this Expression> expression) where TResult : TBase + { + return GetExtendSelectExpre>(expression); + } + + /// + /// 组合继承属性选择表达式树,5个拓展参数 + /// TResult将继承TBase的所有属性 + /// + /// 原数据类型 + /// 拓展类型1 + /// 拓展类型2 + /// 拓展类型3 + /// 拓展类型4 + /// 拓展类型5 + /// 返回类型 + /// 拓展表达式 + /// + public static Expression> BuildExtendSelectExpre(this Expression> expression) where TResult : TBase + { + return GetExtendSelectExpre>(expression); + } + + /// + /// 组合继承属性选择表达式树,6个拓展参数 + /// TResult将继承TBase的所有属性 + /// + /// 原数据类型 + /// 拓展类型1 + /// 拓展类型2 + /// 拓展类型3 + /// 拓展类型4 + /// 拓展类型5 + /// 拓展类型6 + /// 返回类型 + /// 拓展表达式 + /// + public static Expression> BuildExtendSelectExpre(this Expression> expression) where TResult : TBase + { + return GetExtendSelectExpre>(expression); + } + + /// + /// 组合继承属性选择表达式树,7个拓展参数 + /// TResult将继承TBase的所有属性 + /// + /// 原数据类型 + /// 拓展类型1 + /// 拓展类型2 + /// 拓展类型3 + /// 拓展类型4 + /// 拓展类型5 + /// 拓展类型6 + /// 拓展类型7 + /// 返回类型 + /// 拓展表达式 + /// + public static Expression> BuildExtendSelectExpre(this Expression> expression) where TResult : TBase + { + return GetExtendSelectExpre>(expression); + } + + /// + /// 组合继承属性选择表达式树,8个拓展参数 + /// TResult将继承TBase的所有属性 + /// + /// 原数据类型 + /// 拓展类型1 + /// 拓展类型2 + /// 拓展类型3 + /// 拓展类型4 + /// 拓展类型5 + /// 拓展类型6 + /// 拓展类型7 + /// 拓展类型8 + /// 返回类型 + /// 拓展表达式 + /// + public static Expression> BuildExtendSelectExpre(this Expression> expression) where TResult : TBase + { + return GetExtendSelectExpre>(expression); + } + + /// + /// 组合继承属性选择表达式树,9个拓展参数 + /// TResult将继承TBase的所有属性 + /// + /// 原数据类型 + /// 拓展类型1 + /// 拓展类型2 + /// 拓展类型3 + /// 拓展类型4 + /// 拓展类型5 + /// 拓展类型6 + /// 拓展类型7 + /// 拓展类型8 + /// 拓展类型9 + /// 返回类型 + /// 拓展表达式 + /// + public static Expression> BuildExtendSelectExpre(this Expression> expression) where TResult : TBase + { + return GetExtendSelectExpre>(expression); + } + + #endregion + + #region 拓展And和Or方法 + + /// + /// 连接表达式与运算 + /// + /// 参数 + /// 原表达式 + /// 新的表达式 + /// + public static Expression> And(this Expression> one, Expression> another) + { + //创建新参数 + var newParameter = Expression.Parameter(typeof(T), "parameter"); + + var parameterReplacer = new ParameterReplaceVisitor(newParameter); + var left = parameterReplacer.Visit(one.Body); + var right = parameterReplacer.Visit(another.Body); + var body = Expression.And(left, right); + + return Expression.Lambda>(body, newParameter); + } + + /// + /// 连接表达式或运算 + /// + /// 参数 + /// 原表达式 + /// 新表达式 + /// + public static Expression> Or(this Expression> one, Expression> another) + { + //创建新参数 + var newParameter = Expression.Parameter(typeof(T), "parameter"); + + var parameterReplacer = new ParameterReplaceVisitor(newParameter); + var left = parameterReplacer.Visit(one.Body); + var right = parameterReplacer.Visit(another.Body); + var body = Expression.Or(left, right); + + return Expression.Lambda>(body, newParameter); + } + + #endregion + + #region 拓展Expression的Invoke方法 + + public static TResult Invoke(this Expression> expression) + { + return expression.Compile().Invoke(); + } + + public static TResult Invoke(this Expression> expression, T1 arg1) + { + return expression.Compile().Invoke(arg1); + } + + public static TResult Invoke(this Expression> expression, T1 arg1, T2 arg2) + { + return expression.Compile().Invoke(arg1, arg2); + } + + public static TResult Invoke(this Expression> expression, T1 arg1, T2 arg2, T3 arg3) + { + return expression.Compile().Invoke(arg1, arg2, arg3); + } + + public static TResult Invoke(this Expression> expression, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + return expression.Compile().Invoke(arg1, arg2, arg3, arg4); + } + + public static TResult Invoke(this Expression> expression, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + return expression.Compile().Invoke(arg1, arg2, arg3, arg4, arg5); + } + + public static TResult Invoke(this Expression> expression, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) + { + return expression.Compile().Invoke(arg1, arg2, arg3, arg4, arg5, arg6); + } + + public static TResult Invoke(this Expression> expression, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) + { + return expression.Compile().Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7); + } + + public static TResult Invoke(this Expression> expression, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) + { + return expression.Compile().Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + } + + public static TResult Invoke(this Expression> expression, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) + { + return expression.Compile().Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); + } + + public static TResult Invoke(this Expression> expression, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) + { + return expression.Compile().Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); + } + + #endregion + + /// + /// 获取表达式中的固定值 + /// + /// 表达式 + /// + public static object GetConstantValue(this Expression expression) + { + var visitor = new GetConstantValueVisitor(); + visitor.Visit(expression); + return visitor.ConstantValue; + } + + public static object GetMemberValue(this Expression expression) + { + var visitor = new GetMemberValueVisitor(); + visitor.Visit(expression); + return visitor.Value; + } + + #region 私有成员 + + private static Expression GetExtendSelectExpre(Expression expression) + { + NewExpression newBody = Expression.New(typeof(TResult)); + MemberInitExpression oldExpression = (MemberInitExpression)expression.Body; + + ParameterExpression[] oldParamters = expression.Parameters.ToArray(); + List existsProperties = new List(); + foreach (var aBinding in oldExpression.Bindings) + { + existsProperties.Add(aBinding.Member.Name); + } + + List newBindings = new List(); + + var ls = typeof(TResult).GetProperties().Where(x => !existsProperties.Contains(x.Name)); + foreach (var aProperty in ls) + { + if (typeof(TBase).GetMembers().Any(x => x.Name == aProperty.Name)) + { + MemberInfo newMember = typeof(TBase).GetMember(aProperty.Name)[0]; + MemberBinding newMemberBinding = Expression.Bind(newMember, Expression.Property(oldParamters[0], aProperty.Name)); + newBindings.Add(newMemberBinding); + } + } + newBindings.AddRange(oldExpression.Bindings); + + var body = Expression.MemberInit(newBody, newBindings.ToArray()); + var resExpression = Expression.Lambda(body, oldParamters); + + return resExpression; + } + + #endregion + } + + /// + /// 继承ExpressionVisitor类,实现参数替换统一 + /// + class ParameterReplaceVisitor : ExpressionVisitor + { + public ParameterReplaceVisitor(ParameterExpression paramExpr) + { + _parameter = paramExpr; + } + + //新的表达式参数 + private ParameterExpression _parameter { get; set; } + + protected override Expression VisitParameter(ParameterExpression p) + { + if (p.Type == _parameter.Type) + return _parameter; + else + return p; + } + } + + class GetConstantValueVisitor : ExpressionVisitor + { + public object ConstantValue { get; set; } + protected override Expression VisitConstant(ConstantExpression node) + { + ConstantValue = node.Value; + + return base.VisitConstant(node); + } + } + + class GetMemberValueVisitor : ExpressionVisitor + { + public object Value { get; set; } + + } +} diff --git a/Blog.Core.Common/Helper/ShaHelper.cs b/Blog.Core.Common/Helper/ShaHelper.cs new file mode 100644 index 0000000..7a91257 --- /dev/null +++ b/Blog.Core.Common/Helper/ShaHelper.cs @@ -0,0 +1,1096 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +// This is an implementation of +// http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf + + + + + +namespace Blog.Core.Common.Helper +{ + using Word32 = System.UInt32; + using Word64 = System.UInt64; + + + public static class ShaHelper + { + // Constants K + static Word32[] K1; + static Word32[] K256; + static Word64[] K512; + + // Initial hash values H0 + static Word32[] H0Sha1; + static Word32[] H0Sha224; + static Word32[] H0Sha256; + static Word64[] H0Sha384; + static Word64[] H0Sha512; + static Word64[] H0Sha512_224; + static Word64[] H0Sha512_256; + + + static ShaHelper() + { + DefineK1(); + DefineK256(); + DefineK512(); + + DefineH0Sha1(); + DefineH0Sha224(); + DefineH0Sha256(); + DefineH0Sha384(); + DefineH0Sha512(); + DefineH0Sha512_224(); + DefineH0Sha512_256(); + } + + + #region Public Functions + + public static byte[] Sha1(byte[] plaintext) + { + DefineH0Sha1(); + return Sha1Algorithm(plaintext); + } + + public static string Sha1(string plaintext) + { + return ShaUtilities.ByteArrayToHexString(Sha1(ShaUtilities.StringToByteArray(plaintext))); + } + + public static byte[] Sha224(byte[] plaintext) + { + DefineH0Sha224(); + return Sha256Algorithm(plaintext, H0Sha224, 224); + } + + public static string Sha224(string plaintext) + { + return ShaUtilities.ByteArrayToHexString(Sha224(ShaUtilities.StringToByteArray(plaintext))); + } + + public static byte[] Sha256(byte[] plaintext) + { + DefineH0Sha256(); + return Sha256Algorithm(plaintext, H0Sha256, 256); + } + + public static string Sha256(string plaintext) + { + return ShaUtilities.ByteArrayToHexString(Sha256(ShaUtilities.StringToByteArray(plaintext))); + } + + public static byte[] Sha512(byte[] plaintext) + { + DefineH0Sha512(); + return Sha512Algorithm(plaintext, H0Sha512, 512); + } + + public static string Sha512(string plaintext) + { + return ShaUtilities.ByteArrayToHexString(Sha512(ShaUtilities.StringToByteArray(plaintext))); + } + + public static byte[] Sha384(byte[] plaintext) + { + DefineH0Sha384(); + return Sha512Algorithm(plaintext, H0Sha384, 384); + } + + public static string Sha384(string plaintext) + { + return ShaUtilities.ByteArrayToHexString(Sha384(ShaUtilities.StringToByteArray(plaintext))); + } + + public static byte[] Sha512_224(byte[] plaintext) + { + DefineH0Sha512_224(); + return Sha512Algorithm(plaintext, H0Sha512_224, 224); + } + + public static string Sha512_224(string plaintext) + { + return ShaUtilities.ByteArrayToHexString(Sha512_224(ShaUtilities.StringToByteArray(plaintext))); + } + + public static byte[] Sha512_256(byte[] plaintext) + { + DefineH0Sha512_256(); + return Sha512Algorithm(plaintext, H0Sha512_256, 256); + } + + public static string Sha512_256(string plaintext) + { + return ShaUtilities.ByteArrayToHexString(Sha512_256(ShaUtilities.StringToByteArray(plaintext))); + } + + #endregion + + + + + + #region Hash Algorithms + + static Word32[] CreateMessageScheduleSha1(Block512 block) + { + // The message schedule. + Word32[] W = new Word32[80]; + + // Prepare the message schedule W. + // The first 16 words in W are the same as the words of the block. + // The remaining 80-16 = 64 words in W are functions of the previously defined words. + for (int t = 0; t < 80; t++) + { + if (t < 16) + { + W[t] = block.words[t]; + } + else + { + W[t] = RotL(1, W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]); + } + } + + return W; + } + + static Word32[] CreateMessageScheduleSha256(Block512 block) + { + // The message schedule. + Word32[] W = new Word32[64]; + + // Prepare the message schedule W. + // The first 16 words in W are the same as the words of the block. + // The remaining 64-16 = 48 words in W are functions of the previously defined words. + for (int t = 0; t < 64; t++) + { + if (t < 16) + { + W[t] = block.words[t]; + } + else + { + W[t] = sigma1_256(W[t - 2]) + W[t - 7] + sigma0_256(W[t - 15]) + W[t - 16]; + } + } + + return W; + } + + static Word64[] CreateMessageScheduleSha512(Block1024 block) + { + // The message schedule. + Word64[] W = new Word64[80]; + + // Prepare the message schedule W. + // The first 16 words in W are the same as the words of the block. + // The remaining 80-16 =64 words in W are functions of the previously defined words. + for (int t = 0; t < 80; t++) + { + if (t < 16) + { + W[t] = block.words[t]; + } + else + { + W[t] = sigma1_512(W[t - 2]) + W[t - 7] + sigma0_512(W[t - 15]) + W[t - 16]; + } + } + + return W; + } + + static byte[] Sha1Algorithm(byte[] plaintext) + { + Block512[] blocks = ConvertPaddedTextToBlock512Array(PadPlainText512(plaintext)); + + // Define the hash variable and set its initial values. + Word32[] H = new Word32[5]; + H0Sha1.CopyTo(H, 0); + + for (int i = 0; i < blocks.Length; i++) + { + Word32[] W = CreateMessageScheduleSha1(blocks[i]); + + // Set the working variables a,...,e to the current hash values. + Word32 a = H[0]; + Word32 b = H[1]; + Word32 c = H[2]; + Word32 d = H[3]; + Word32 e = H[4]; + + for (int t = 0; t < 80; t++) + { + Word32 T = RotL(5, a) + f(t, b, c, d) + e + K1[t] + W[t]; + e = d; + d = c; + c = RotL(30, b); + b = a; + a = T; + } + + // Update the current value of the hash H after processing block i. + H[0] += a; + H[1] += b; + H[2] += c; + H[3] += d; + H[4] += e; + } + + // Concatenating the final 5 hash words H[0],...,H[4] gives the digest. + // Since each H[i] is 4 bytes, the digest is 5 * 4 = 20 bytes = 160 bits. + return ShaUtilities.Word32ArrayToByteArray(H); + } + + static byte[] Sha256Algorithm(byte[] plaintext, Word32[] H0, int numberBits) + { + Block512[] blocks = ConvertPaddedTextToBlock512Array(PadPlainText512(plaintext)); + + // Define the hash variables and set their initial values. + Word32[] H = H0; + + for (int i = 0; i < blocks.Length; i++) + { + Word32[] W = CreateMessageScheduleSha256(blocks[i]); + + // Set the working variables a,...,h to the current hash values. + Word32 a = H[0]; + Word32 b = H[1]; + Word32 c = H[2]; + Word32 d = H[3]; + Word32 e = H[4]; + Word32 f = H[5]; + Word32 g = H[6]; + Word32 h = H[7]; + + for (int t = 0; t < 64; t++) + { + Word32 T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[t] + W[t]; + Word32 T2 = Sigma0_256(a) + Maj(a, b, c); + h = g; + g = f; + f = e; + e = d + T1; + d = c; + c = b; + b = a; + a = T1 + T2; + } + + // Update the current value of the hash H after processing block i. + H[0] += a; + H[1] += b; + H[2] += c; + H[3] += d; + H[4] += e; + H[5] += f; + H[6] += g; + H[7] += h; + } + + // Concatenate all the Word32 Hash Values + byte[] hash = ShaUtilities.Word32ArrayToByteArray(H); + + // The number of bytes in the final output hash + int numberBytes = numberBits / 8; + byte[] truncatedHash = new byte[numberBytes]; + Array.Copy(hash, truncatedHash, numberBytes); + + return truncatedHash; + } + + static byte[] Sha512Algorithm(byte[] plaintext, Word64[] H0, int numberBits) + { + Block1024[] blocks = ConvertPaddedMessageToBlock1024Array(PadPlainText1024(plaintext)); + + // Define the hash variable and set its initial values. + Word64[] H = H0; + + for (int i = 0; i < blocks.Length; i++) + { + Word64[] W = CreateMessageScheduleSha512(blocks[i]); + + // Set the working variables a,...,h to the current hash values. + Word64 a = H[0]; + Word64 b = H[1]; + Word64 c = H[2]; + Word64 d = H[3]; + Word64 e = H[4]; + Word64 f = H[5]; + Word64 g = H[6]; + Word64 h = H[7]; + + for (int t = 0; t < 80; t++) + { + Word64 T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[t] + W[t]; + Word64 T2 = Sigma0_512(a) + Maj(a, b, c); + h = g; + g = f; + f = e; + e = d + T1; + d = c; + c = b; + b = a; + a = T1 + T2; + } + + // Update the current value of the hash H after processing block i. + H[0] += a; + H[1] += b; + H[2] += c; + H[3] += d; + H[4] += e; + H[5] += f; + H[6] += g; + H[7] += h; + } + + // Concatenate all the Word64 Hash Values + byte[] hash = ShaUtilities.Word64ArrayToByteArray(H); + + // The number of bytes in the final output hash + int numberBytes = numberBits / 8; + byte[] truncatedHash = new byte[numberBytes]; + Array.Copy(hash, truncatedHash, numberBytes); + + return truncatedHash; + } + + #endregion + + + #region Plaintext preprocessing functions + + static byte[] PadPlainText512(byte[] plaintext) + { + // After padding the total bits of the output will be divisible by 512. + int numberBits = plaintext.Length * 8; + int t = (numberBits + 8 + 64) / 512; + + // Note that 512 * (t + 1) is the least multiple of 512 greater than (numberBits + 8 + 64) + // Therefore the number of zero bits we need to add is + int k = 512 * (t + 1) - (numberBits + 8 + 64); + + // Since numberBits % 8 = 0, we know k % 8 = 0. So n = k / 8 is the number of zero bytes to add. + int n = k / 8; + + List paddedtext = plaintext.ToList(); + + // Start the padding by concatenating 1000_0000 = 0x80 = 128 + paddedtext.Add(0x80); + + // Next add n zero bytes + for (int i = 0; i < n; i++) + { + paddedtext.Add(0); + } + + // Now add 8 bytes (64 bits) to represent the length of the message in bits + byte[] B = BitConverter.GetBytes((ulong)numberBits); + Array.Reverse(B); + + for (int i = 0; i < B.Length; i++) + { + paddedtext.Add(B[i]); + } + + return paddedtext.ToArray(); + } + + static byte[] PadPlainText1024(byte[] plaintext) + { + // After padding the total bits of the output will be divisible by 1024. + int numberBits = plaintext.Length * 8; + int t = (numberBits + 8 + 128) / 1024; + + // Note that 1024 * (t + 1) is the least multiple of 1024 greater than (numberBits + 8 + 128) + // Therefore the number of zero bits we need to add is + int k = 1024 * (t + 1) - (numberBits + 8 + 128); + + // Since numberBits % 8 = 0, we know k % 8 = 0. So n = k / 8 is the number of zero bytes to add. + int n = k / 8; + + List paddedtext = plaintext.ToList(); + + // Start the padding by concatenating 1000_0000 = 0x80 = 128 + paddedtext.Add(0x80); + + // Next add n zero bytes + for (int i = 0; i < n; i++) + { + paddedtext.Add(0); + } + + // Now add 16 bytes (128 bits) to represent the length of the message in bits. + // C# does not have 128 bit integer. + // For now just add 8 zero bytes and then 8 bytes to represent the int + for (int i = 0; i < 8; i++) + { + paddedtext.Add(0); + } + + byte[] B = BitConverter.GetBytes((ulong)numberBits); + Array.Reverse(B); + + for (int i = 0; i < B.Length; i++) + { + paddedtext.Add(B[i]); + } + + return paddedtext.ToArray(); + } + + static Block512[] ConvertPaddedTextToBlock512Array(byte[] paddedtext) + { + // We are assuming M has been padded, so the number of bits in M is divisible by 512 + int numberBlocks = (paddedtext.Length * 8) / 512; // same as: paddedtext.Length / 64 + Block512[] blocks = new Block512[numberBlocks]; + + for (int i = 0; i < numberBlocks; i++) + { + // First extract the relavant subarray from paddedtext + byte[] B = new byte[64]; // 64 * 8 = 512 + + for (int j = 0; j < 64; j++) + { + B[j] = paddedtext[i * 64 + j]; + } + + Word32[] words = ShaUtilities.ByteArrayToWord32Array(B); + blocks[i] = new Block512(words); + } + + return blocks; + } + + static Block1024[] ConvertPaddedMessageToBlock1024Array(byte[] M) + { + // We are assuming M is padded, so the number of bits in M is divisible by 1024 + int numberBlocks = (M.Length * 8) / 1024; // same as: M.Length / 128 + Block1024[] blocks = new Block1024[numberBlocks]; + + for (int i = 0; i < numberBlocks; i++) + { + // First extract the relavant subarray from M + byte[] B = new byte[128]; // 128 * 8 = 1024 + + for (int j = 0; j < 128; j++) + { + B[j] = M[i * 128 + j]; + } + + Word64[] words = ShaUtilities.ByteArrayToWord64Array(B); + blocks[i] = new Block1024(words); + } + + return blocks; + } + + + #endregion + + + + #region Functions used in the hashing process. + + // Most of these functions have a Word32 version and a Word64 version. + // Sometimes they are the same (Ch, Maj,..) but sometimes different (Sigma0_256, Sigma0_512). + // We do not need a RotL or Parity function for Word64 since they are only used in Sha-1. + + static Word32 ShR(int n, Word32 x) + { + // should have 0 <= n < 32 + return (x >> n); + } + + static Word64 ShR(int n, Word64 x) + { + // should have 0 <= n < 64 + return (x >> n); + } + + static Word32 RotR(int n, Word32 x) + { + // should have 0 <= n < 32 + return (x >> n) | (x << 32 - n); + } + + static Word64 RotR(int n, Word64 x) + { + // should have 0 <= n < 64 + return (x >> n) | (x << 64 - n); + } + + static Word32 RotL(int n, Word32 x) + { + // should have 0 <= n < 32 + return (x << n) | (x >> 32 - n); + } + + static Word32 Ch(Word32 x, Word32 y, Word32 z) + { + return (x & y) ^ (~x & z); + } + + static Word64 Ch(Word64 x, Word64 y, Word64 z) + { + return (x & y) ^ (~x & z); + } + + static Word32 Maj(Word32 x, Word32 y, Word32 z) + { + return (x & y) ^ (x & z) ^ (y & z); + } + + static Word64 Maj(Word64 x, Word64 y, Word64 z) + { + return (x & y) ^ (x & z) ^ (y & z); + } + + static Word32 Parity(Word32 x, Word32 y, Word32 z) + { + return x ^ y ^ z; + } + + static Word32 f(int t, Word32 x, Word32 y, Word32 z) + { + // This function is used in Sha-1 + // should have 0 <= t <= 79 + + if (t >= 0 && t <= 19) + { + return Ch(x, y, z); + } + else if (t >= 20 && t <= 39) + { + return Parity(x, y, z); + } + else if (t >= 40 && t <= 59) + { + return Maj(x, y, z); + } + else if (t >= 60 && t <= 79) + { + return Parity(x, y, z); + } + else + { + throw new ArgumentException("ERROR: t is out of bounds"); + } + } + + static Word32 Sigma0_256(Word32 x) + { + return RotR(2, x) ^ RotR(13, x) ^ RotR(22, x); + } + + static Word32 Sigma1_256(Word32 x) + { + return RotR(6, x) ^ RotR(11, x) ^ RotR(25, x); + } + + static Word32 sigma0_256(Word32 x) + { + return RotR(7, x) ^ RotR(18, x) ^ ShR(3, x); + } + + static Word32 sigma1_256(Word32 x) + { + return RotR(17, x) ^ RotR(19, x) ^ ShR(10, x); + } + + static Word64 Sigma0_512(Word64 x) + { + return RotR(28, x) ^ RotR(34, x) ^ RotR(39, x); + } + + static Word64 Sigma1_512(Word64 x) + { + return RotR(14, x) ^ RotR(18, x) ^ RotR(41, x); + } + + static Word64 sigma0_512(Word64 x) + { + return RotR(1, x) ^ RotR(8, x) ^ ShR(7, x); + } + + static Word64 sigma1_512(Word64 x) + { + return RotR(19, x) ^ RotR(61, x) ^ ShR(6, x); + } + + #endregion + + + + #region Functions to define the constants K and the initial hashes H0. + + static void DefineK1() + { + // The eighty 32-bit words in the array K1 are used in Sha-1. + + K1 = new Word32[80]; + + for (int i = 0; i < 80; i++) + { + if (i <= 19) + { + K1[i] = 0x5a827999; + } + else if (i <= 39) + { + K1[i] = 0x6ed9eba1; + } + else if (i <= 59) + { + K1[i] = 0x8f1bbcdc; + } + else + { + K1[i] = 0xca62c1d6; + } + } + } + + static void DefineK256() + { + // The sixty four 32-bit words in the array K256 are used in Sha-224 and Sha-256. + // They are obtained by taking the first 32 bits of the fractional + // parts of the cube roots of the first sixty four primes. + // ------------------------------------------------------- + // NOTE: To find the first 32 bits of the fractional part of the cube root of an integer n: + // double x = Math.Pow(n, 1d / 3); + // x = x - Math.Floor(x); + // x = x * Math.Pow(2, 32); + // return (uint)x; + + K256 = new Word32[] + { + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 + }; + } + + static void DefineK512() + { + // The eighty 64-bit words in the array K512 are used in Sha-384, Sha-512, Sha-512/224, Sha-512/256. + // They are obtained by taking the first 64 bits of the fractional + // parts of the cube roots of the first eighty primes. + + K512 = new Word64[] + { + 0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc, + 0x3956c25bf348b538, 0x59f111f1b605d019, 0x923f82a4af194f9b, 0xab1c5ed5da6d8118, + 0xd807aa98a3030242, 0x12835b0145706fbe, 0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2, + 0x72be5d74f27b896f, 0x80deb1fe3b1696b1, 0x9bdc06a725c71235, 0xc19bf174cf692694, + 0xe49b69c19ef14ad2, 0xefbe4786384f25e3, 0x0fc19dc68b8cd5b5, 0x240ca1cc77ac9c65, + 0x2de92c6f592b0275, 0x4a7484aa6ea6e483, 0x5cb0a9dcbd41fbd4, 0x76f988da831153b5, + 0x983e5152ee66dfab, 0xa831c66d2db43210, 0xb00327c898fb213f, 0xbf597fc7beef0ee4, + 0xc6e00bf33da88fc2, 0xd5a79147930aa725, 0x06ca6351e003826f, 0x142929670a0e6e70, + 0x27b70a8546d22ffc, 0x2e1b21385c26c926, 0x4d2c6dfc5ac42aed, 0x53380d139d95b3df, + 0x650a73548baf63de, 0x766a0abb3c77b2a8, 0x81c2c92e47edaee6, 0x92722c851482353b, + 0xa2bfe8a14cf10364, 0xa81a664bbc423001, 0xc24b8b70d0f89791, 0xc76c51a30654be30, + 0xd192e819d6ef5218, 0xd69906245565a910, 0xf40e35855771202a, 0x106aa07032bbd1b8, + 0x19a4c116b8d2d0c8, 0x1e376c085141ab53, 0x2748774cdf8eeb99, 0x34b0bcb5e19b48a8, + 0x391c0cb3c5c95a63, 0x4ed8aa4ae3418acb, 0x5b9cca4f7763e373, 0x682e6ff3d6b2b8a3, + 0x748f82ee5defb2fc, 0x78a5636f43172f60, 0x84c87814a1f0ab72, 0x8cc702081a6439ec, + 0x90befffa23631e28, 0xa4506cebde82bde9, 0xbef9a3f7b2c67915, 0xc67178f2e372532b, + 0xca273eceea26619c, 0xd186b8c721c0c207, 0xeada7dd6cde0eb1e, 0xf57d4f7fee6ed178, + 0x06f067aa72176fba, 0x0a637dc5a2c898a6, 0x113f9804bef90dae, 0x1b710b35131c471b, + 0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc, 0x431d67c49c100d4c, + 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817 + }; + } + + static void DefineH0Sha1() + { + H0Sha1 = new Word32[] + { + 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 + }; + } + + static void DefineH0Sha224() + { + H0Sha224 = new Word32[] + { + 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, + 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 + }; + + } + + static void DefineH0Sha256() + { + // These eight 32-bit words are obtained by taking the first 32 bits of the + // fractional parts of the square roots of the first 8 prime numbers. + + H0Sha256 = new Word32[] + { + 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, + 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 + }; + } + + static void DefineH0Sha384() + { + // These eight 64-bit words are obtained by taking the first 64 bits of the + // fractional parts of the square roots of the ninth through sixteenth prime numbers. + + H0Sha384 = new Word64[] + { + 0xcbbb9d5dc1059ed8, 0x629a292a367cd507, 0x9159015a3070dd17, 0x152fecd8f70e5939, + 0x67332667ffc00b31, 0x8eb44a8768581511, 0xdb0c2e0d64f98fa7, 0x47b5481dbefa4fa4 + }; + } + + static void DefineH0Sha512() + { + // These eight 64-bit words are obtained by taking the first 64 bits of the + // fractional parts of the square roots of the first eight prime numbers. + + H0Sha512 = new Word64[] + { + 0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1, + 0x510e527fade682d1, 0x9b05688c2b3e6c1f, 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179 + }; + } + + static void DefineH0Sha512_224() + { + // These eight 64-bit words are obtained from GenerateInitialHashSha512t(224) + + H0Sha512_224 = new Word64[] + { + 0x8c3d37c819544da2, 0x73e1996689dcd4d6, 0x1dfab7ae32ff9c82, 0x679dd514582f9fcf, + 0x0f6d2b697bd44da8, 0x77e36f7304c48942, 0x3f9d85a86a1d36c8, 0x1112e6ad91d692a1 + }; + } + + static void DefineH0Sha512_256() + { + // These eight 64-bit words are obtained from GenerateInitialHashSha512t(256) + + H0Sha512_256 = new Word64[] + { + 0x22312194fc2bf72c, 0x9f555fa3c84c64c2, 0x2393b86b6f53b151, 0x963877195940eabd, + 0x96283ee2a88effe3, 0xbe5e1e2553863992, 0x2b0199fc2c85b8aa, 0x0eb72ddc81c52ca2 + }; + } + + /* + static Word64[] GenerateInitialHashSha512t(int t) + { + // t = number of bits. + // We assume t is postive, divisible by 8 and is strictly less than 512. + // Also assume numberBits != 384 (WHY does 384 get its own initial hash?) + + Word64[] H0 = new Word64[8]; + + for (int i = 0; i < 8; i++) + { + H0[i] = H0Sha512[i] ^ 0xa5a5a5a5a5a5a5a5; + } + + byte[] B = ShaUtil.StringToByteArray("SHA-512/" + t.ToString()); // so arbitary! + + return ShaUtil.ByteArrayToWord64Array(Sha512(B)); ; + } + */ + + #endregion + + } + + + // Helper Classes + + class Block512 + { + // A Block512 consists of an array of 16 elements of type Word32. + public Word32[] words; + + public Block512(Word32[] words) + { + if (words.Length == 16) + { + this.words = words; + } + else + { + Console.WriteLine("ERROR: A block must be 16 words"); + this.words = null; + } + } + } + + + class Block1024 + { + // A Block1024 consists of an array of 16 elements of type Word64. + public Word64[] words; + + public Block1024(Word64[] words) + { + if (words.Length == 16) + { + this.words = words; + } + else + { + Console.WriteLine("ERROR: A block must be 16 words"); + this.words = null; + } + } + } + + + static class ShaUtilities + { + #region Functions to convert between byte arrays and Word32 arrays, and Word64 arrays. + + public static bool ByteArraysEqual(byte[] B1, byte[] B2) + { + if ((B1 == null) && (B2 == null)) + return true; + + if ((B1 == null) || (B2 == null)) + return false; + + if (B1.Length != B2.Length) + return false; + + for (int i = 0; i < B1.Length; i++) + { + if (B1[i] != B2[i]) + return false; + } + + return true; + } + + public static byte[] StringToByteArray(string plaintext) + { + char[] c = plaintext.ToCharArray(); + int numberBytes = plaintext.Length; + byte[] b = new byte[numberBytes]; + + for (int i = 0; i < numberBytes; i++) + { + b[i] = Convert.ToByte(c[i]); + } + + return b; + } + + // Returns an array of 4 bytes. + public static byte[] Word32ToByteArray(Word32 x) + { + byte[] b = BitConverter.GetBytes(x); + Array.Reverse(b); + return b; + } + + // Returns an array of 8 bytes. + public static byte[] Word64ToByteArray(Word64 x) + { + byte[] b = BitConverter.GetBytes(x); + Array.Reverse(b); + return b; + } + + public static byte[] Word32ArrayToByteArray(Word32[] words) + { + List b = new List(); + + for (int i = 0; i < words.Length; i++) + { + b.AddRange(Word32ToByteArray(words[i])); + } + + return b.ToArray(); + } + + public static byte[] Word32ArrayToByteArray(Word32[] words, int startIndex, int numberWords) + { + // This overload is useful in Sha224 + // assume 0 <= startIndex < words.Length and startIndex + numberWords <= words.Length + + List b = new List(); + + for (int i = startIndex; i < startIndex + numberWords; i++) + { + b.AddRange(Word32ToByteArray(words[i])); + } + + return b.ToArray(); + } + + public static byte[] Word64ArrayToByteArray(Word64[] words) + { + List b = new List(); + + for (int i = 0; i < words.Length; i++) + { + b.AddRange(Word64ToByteArray(words[i])); + } + + return b.ToArray(); + } + + public static Word32 ByteArrayToWord32(byte[] B, int startIndex) + { + // We assume: 0 <= startIndex < B. Length, and startIndex + 4 <= B.Length + + Word32 c = 256; + Word32 output = 0; + + for (int i = startIndex; i < startIndex + 4; i++) + { + output = output * c + (Word32)B[i]; + } + + return output; + } + + public static Word64 ByteArrayToWord64(byte[] B, int startIndex) + { + // We assume: 0 <= startIndex < B. Length, and startIndex + 8 <= B.Length + Word64 c = 256; + Word64 output = 0; + + for (int i = startIndex; i < startIndex + 8; i++) + { + output = output * c + B[i]; + } + + return output; + } + + public static Word32[] ByteArrayToWord32Array(byte[] B) + { + // We assume B is not null, is not empty and number elements is divisible by 4 + int numberBytes = B.Length; + int n = numberBytes / 4; // 4 bytes for each Word32 + Word32[] word32Array = new Word32[n]; + + for (int i = 0; i < n; i++) + { + word32Array[i] = ByteArrayToWord32(B, 4 * i); + } + + return word32Array; + } + + + public static Word64[] ByteArrayToWord64Array(byte[] B) + { + // We assume B is not null, is not empty and number elements is divisible by 8 + int numberWords = B.Length / 8; // 8 bytes for each Word32 + Word64[] word64Array = new Word64[numberWords]; + + for (int i = 0; i < numberWords; i++) + { + word64Array[i] = ByteArrayToWord64(B, 8 * i); + } + + return word64Array; + } + + #endregion + + + #region To string methods + + public static string ByteToBinaryString(byte b) + { + string binaryString = Convert.ToString(b, 2).PadLeft(8, '0'); + return binaryString.Substring(0, 4) + "_" + binaryString.Substring(4, 4); + } + + public static string ByteArrayToBinaryString(byte[] x) + { + string binaryString = ""; + + for (int i = 0; i < x.Length; i++) + { + binaryString += ByteToBinaryString(x[i]); + + if (i < x.Length - 1) + { + binaryString += " "; + } + } + + return binaryString; + } + + public static string ByteToHexString(byte b) + { + return Convert.ToString(b, 16).PadLeft(2, '0'); + } + + public static string ByteArrayToHexString(byte[] a) + { + string hexString = ""; + + for (int i = 0; i < a.Length; i++) + { + hexString += ByteToHexString(a[i]); + } + + return hexString; + } + + public static string Word32ToBinaryString(Word32 x) + { + return ByteArrayToBinaryString(Word32ToByteArray(x)); + } + + public static string Word32ToHexString(Word32 x) + { + return ByteArrayToHexString(Word32ToByteArray(x)); + } + + public static string Word64ToHexString(Word64 x) + { + return ByteArrayToHexString(Word64ToByteArray(x)); + } + + public static string ByteArrayToString(byte[] X) + { + if (X == null) + { + Console.WriteLine("ERROR: The byte array is null"); + return null; + } + + string s = ""; + + for (int i = 0; i < X.Length; i++) + { + s += (char)X[i]; + } + + return s; + } + + #endregion + } + +} + + + + + diff --git a/Blog.Core.Extensions/ServiceExtensions/AutofacModuleRegister.cs b/Blog.Core.Extensions/ServiceExtensions/AutofacModuleRegister.cs index 5cd4ba6..e276c25 100644 --- a/Blog.Core.Extensions/ServiceExtensions/AutofacModuleRegister.cs +++ b/Blog.Core.Extensions/ServiceExtensions/AutofacModuleRegister.cs @@ -3,8 +3,10 @@ using Autofac.Extras.DynamicProxy; using Blog.Core.AOP; using Blog.Core.Common; using Blog.Core.IRepository.Base; +using Blog.Core.IServices.BASE; using Blog.Core.Model; using Blog.Core.Repository.Base; +using Blog.Core.Services.BASE; using log4net; using System; using System.Collections.Generic; @@ -60,6 +62,7 @@ namespace Blog.Core.Extensions } builder.RegisterGeneric(typeof(BaseRepository<>)).As(typeof(IBaseRepository<>)).InstancePerDependency();//注册仓储 + builder.RegisterGeneric(typeof(BaseServices<>)).As(typeof(IBaseServices<>)).InstancePerDependency();//注册服务 // 获取 Service.dll 程序集服务,并注册 var assemblysServices = Assembly.LoadFrom(servicesDllFile); diff --git a/Blog.Core.IServices/ITrojanUsersServices.cs b/Blog.Core.IServices/ITrojanUsersServices.cs new file mode 100644 index 0000000..92bac1d --- /dev/null +++ b/Blog.Core.IServices/ITrojanUsersServices.cs @@ -0,0 +1,14 @@ +using Blog.Core.IServices.BASE; +using Blog.Core.Model.Models; + +namespace Blog.Core.IServices +{ + /// + /// TrojanUsersServices + /// + public interface ITrojanUsersServices : IBaseServices + { + + } +} + diff --git a/Blog.Core.Model/Models/TrojanCusServers.cs b/Blog.Core.Model/Models/TrojanCusServers.cs new file mode 100644 index 0000000..74f030a --- /dev/null +++ b/Blog.Core.Model/Models/TrojanCusServers.cs @@ -0,0 +1,25 @@ + +using System; +using System.Linq; +using System.Text; +using SqlSugar; + +namespace Blog.Core.Model.Models +{ + /// + ///users自定义服务器 + /// + [SugarTable("users_cus", "WMBLOG_MYSQL_2")] + public partial class TrojanCusServers + { + + [SugarColumn(IsNullable = false, IsPrimaryKey = true, IsIdentity = true)] + public int id { set; get; } + public int userid { get; set; } + public string servername { set; get; } + public string serveraddress { set; get; } + [SugarColumn(IsNullable = true)] + public string serverremark { get; set; } + public bool serverenable { get; set; } + } +} diff --git a/Blog.Core.Model/Models/TrojanDetails.cs b/Blog.Core.Model/Models/TrojanDetails.cs new file mode 100644 index 0000000..03a0577 --- /dev/null +++ b/Blog.Core.Model/Models/TrojanDetails.cs @@ -0,0 +1,62 @@ + +//模板自动生成(请勿修改) +//作者:胡丁文 +using System; +using System.Linq; +using System.Text; +using SqlSugar; + +namespace Blog.Core.Model.Models +{ + /// + ///用户流量每月汇总表 + /// + [SugarTable("users_detail", "WMBLOG_MYSQL_2")] + public partial class TrojanDetails + { + + /// + /// + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int id { get; set; } + + /// + /// + /// + public int userId { get; set; } + + /// + /// + /// + public DateTime calDate { get; set; } + + /// + /// + /// + public ulong download { get; set; } + + /// + /// + /// + public ulong upload { get; set; } + + /// + /// + /// + [SugarColumn(IsNullable = true)] + public int? CreateId { get; set; } + + /// + /// + /// + [SugarColumn(IsNullable = true)] + public string CreateBy { get; set; } + + /// + /// + /// + [SugarColumn(IsNullable = true)] + public DateTime? CreateTime { get; set; } + } +} diff --git a/Blog.Core.Model/Models/TrojanServers.cs b/Blog.Core.Model/Models/TrojanServers.cs new file mode 100644 index 0000000..20cb3c9 --- /dev/null +++ b/Blog.Core.Model/Models/TrojanServers.cs @@ -0,0 +1,30 @@ + +using System; +using System.Linq; +using System.Text; +using SqlSugar; + +namespace Blog.Core.Model.Models +{ + /// + ///Trojan服务器 + /// + [SugarTable("servers", "WMBLOG_MYSQL_2")] + public partial class TrojanServers + { + + [SugarColumn(IsNullable = false, IsPrimaryKey = true, IsIdentity = true)] + public int id { set; get; } + public int userid { get; set; } + public string servername { set; get; } + public string serveraddress { set; get; } + public int serverport { get; set; } + [SugarColumn(IsNullable = true)] + public string serverremark { get; set; } + public bool serverenable { get; set; } + public string serverpeer { get; set; } + [SugarColumn(IsNullable = true)] + public string serverpath { get; set; } + public string servertype { get; set; } + } +} diff --git a/Blog.Core.Model/Models/TrojanUrlServers.cs b/Blog.Core.Model/Models/TrojanUrlServers.cs new file mode 100644 index 0000000..a537887 --- /dev/null +++ b/Blog.Core.Model/Models/TrojanUrlServers.cs @@ -0,0 +1,25 @@ + +using System; +using System.Linq; +using System.Text; +using SqlSugar; + +namespace Blog.Core.Model.Models +{ + /// + ///users自定义URL服务器 + /// + [SugarTable("users_url", "WMBLOG_MYSQL_2")] + public partial class TrojanUrlServers + { + + [SugarColumn(IsNullable = false, IsPrimaryKey = true, IsIdentity = true)] + public int id { set; get; } + public int userid { get; set; } + public string servername { set; get; } + public string serveraddress { set; get; } + [SugarColumn(IsNullable = true)] + public string serverremark { get; set; } + public bool serverenable { get; set; } + } +} diff --git a/Blog.Core.Model/Models/TrojanUsers.cs b/Blog.Core.Model/Models/TrojanUsers.cs new file mode 100644 index 0000000..78ea70e --- /dev/null +++ b/Blog.Core.Model/Models/TrojanUsers.cs @@ -0,0 +1,38 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Blog.Core.Model.ViewModels; +using SqlSugar; + +namespace Blog.Core.Model.Models +{ + /// + ///Trojan用户 + /// + [SugarTable("users", "WMBLOG_MYSQL_2")] + public partial class TrojanUsers + { + + [SugarColumn(IsNullable = false, IsPrimaryKey = true, IsIdentity = true)] + public int id { set; get; } + public string username { set; get; } + public string password { set; get; } + public Int64 quota { set; get; } + public UInt64 download { set; get; } + public UInt64 upload { set; get; } + public string passwordshow { set; get; } + [SugarColumn(IsNullable = true)] + public int CreateId { get; set; } + [SugarColumn(IsNullable = true)] + public string CreateBy { get; set; } + [SugarColumn(IsNullable = true)] + public DateTime? CreateTime { get; set; } + /// + /// 历史流量记录 + /// + [SugarColumn(IsIgnore = true)] + public List useList { get; set; } + } +} diff --git a/Blog.Core.Model/ViewModels/TrojanLimitFlowDto.cs b/Blog.Core.Model/ViewModels/TrojanLimitFlowDto.cs new file mode 100644 index 0000000..c0efd34 --- /dev/null +++ b/Blog.Core.Model/ViewModels/TrojanLimitFlowDto.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Blog.Core.Model.ViewModels +{ + /// + /// 限制流量dto + /// 作者:胡丁文 + /// 时间:2020-4-27 16:57:07 + /// + public class TrojanLimitFlowDto + { + /// + /// 用户 + /// + public int[] users { get; set; } + /// + /// 流量(-1为无限,单位为最小单位byte) + /// + public Int64 quota { get; set; } + } +} diff --git a/Blog.Core.Model/ViewModels/TrojanServerDto.cs b/Blog.Core.Model/ViewModels/TrojanServerDto.cs new file mode 100644 index 0000000..89cb87e --- /dev/null +++ b/Blog.Core.Model/ViewModels/TrojanServerDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Blog.Core.Model.ViewModels +{ + public class TrojanServerDto + { + public string name { get; set; } + public string value { get; set; } + } +} diff --git a/Blog.Core.Model/ViewModels/TrojanServerSpliceDto.cs b/Blog.Core.Model/ViewModels/TrojanServerSpliceDto.cs new file mode 100644 index 0000000..e83adfd --- /dev/null +++ b/Blog.Core.Model/ViewModels/TrojanServerSpliceDto.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Blog.Core.Model.ViewModels +{ + /// + /// Trojan服务器拼接服务器和订阅地址 + /// + public class TrojanServerSpliceDto + { + /// + /// 普通订阅连接 + /// + public string normalApi { get; set; } + /// + /// clash订阅连接 + /// + public string clashApi { get; set; } + /// + /// 备用clash订阅连接 + /// + public string clashApiBackup { get; set; } + public List list { get; set; } = new List(); + } +} diff --git a/Blog.Core.Model/ViewModels/TrojanUseDetailDto.cs b/Blog.Core.Model/ViewModels/TrojanUseDetailDto.cs new file mode 100644 index 0000000..7746b10 --- /dev/null +++ b/Blog.Core.Model/ViewModels/TrojanUseDetailDto.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Blog.Core.Model.ViewModels +{ + /// + /// Trojan用户流量统计分组 + /// + public class TrojanUseDetailDto + { + /// + /// 用户ID + /// + public int userId { get; set; } + /// + /// 月度 + /// + public string moth { get; set; } + /// + /// 上传流量 + /// + public decimal up { get; set; } + /// + /// 下载流量 + /// + public decimal down { get; set; } + /// + /// 下载流量 + /// + public decimal total { get { return up + down; } } + } +} diff --git a/Blog.Core.Services/AccessTrendLogServices.cs b/Blog.Core.Services/AccessTrendLogServices.cs index 38c643f..ee9ee37 100644 --- a/Blog.Core.Services/AccessTrendLogServices.cs +++ b/Blog.Core.Services/AccessTrendLogServices.cs @@ -7,12 +7,6 @@ namespace Blog.Core.Services { public partial class AccessTrendLogServices : BaseServices, IAccessTrendLogServices { - IBaseRepository _dal; - public AccessTrendLogServices(IBaseRepository dal) - { - this._dal = dal; - base.BaseDal = dal; - } } } diff --git a/Blog.Core.Services/AdvertisementServices.cs b/Blog.Core.Services/AdvertisementServices.cs index 6f2cec8..c95f414 100644 --- a/Blog.Core.Services/AdvertisementServices.cs +++ b/Blog.Core.Services/AdvertisementServices.cs @@ -7,13 +7,6 @@ namespace Blog.Core.Services { public class AdvertisementServices : BaseServices, IAdvertisementServices { - IBaseRepository _dal; - public AdvertisementServices(IBaseRepository dal) - { - this._dal = dal; - base.BaseDal = dal; - } - public void ReturnExp() { diff --git a/Blog.Core.Services/BASE/BaseServices.cs b/Blog.Core.Services/BASE/BaseServices.cs index 5db1efe..ec685be 100644 --- a/Blog.Core.Services/BASE/BaseServices.cs +++ b/Blog.Core.Services/BASE/BaseServices.cs @@ -13,6 +13,10 @@ namespace Blog.Core.Services.BASE { public class BaseServices : IBaseServices where TEntity : class, new() { + public BaseServices(IBaseRepository BaseDal = null) + { + this.BaseDal = BaseDal; + } //public IBaseRepository baseDal = new BaseRepository(); public IBaseRepository BaseDal { get; set; }//通过在子类的构造函数中注入,这里是基类,不用构造函数 diff --git a/Blog.Core.Services/BlogArticleServices.cs b/Blog.Core.Services/BlogArticleServices.cs index f04de9a..eeff04e 100644 --- a/Blog.Core.Services/BlogArticleServices.cs +++ b/Blog.Core.Services/BlogArticleServices.cs @@ -13,7 +13,6 @@ namespace Blog.Core.Services { public class BlogArticleServices : BaseServices, IBlogArticleServices { - public IBaseRepository _dal { get; set; } IMapper _mapper; public BlogArticleServices(IMapper mapper) { diff --git a/Blog.Core.Services/DepartmentServices.cs b/Blog.Core.Services/DepartmentServices.cs index a6f1eed..954d0ca 100644 --- a/Blog.Core.Services/DepartmentServices.cs +++ b/Blog.Core.Services/DepartmentServices.cs @@ -10,11 +10,6 @@ namespace Blog.Core.Services /// public class DepartmentServices : BaseServices, IDepartmentServices { - private readonly IBaseRepository _dal; - public DepartmentServices(IBaseRepository dal) - { - this._dal = dal; - base.BaseDal = dal; - } + } } \ No newline at end of file diff --git a/Blog.Core.Services/GuestbookServices.cs b/Blog.Core.Services/GuestbookServices.cs index 8da0e7f..f759a54 100644 --- a/Blog.Core.Services/GuestbookServices.cs +++ b/Blog.Core.Services/GuestbookServices.cs @@ -12,13 +12,10 @@ namespace Blog.Core.Services { public class GuestbookServices : BaseServices, IGuestbookServices { - private readonly IBaseRepository _dal; private readonly IUnitOfWork _unitOfWork; private readonly IBaseRepository _passwordLibRepository; - public GuestbookServices(IUnitOfWork unitOfWork, IBaseRepository dal, IBaseRepository passwordLibRepository) + public GuestbookServices(IUnitOfWork unitOfWork, IBaseRepository passwordLibRepository) { - this._dal = dal; - base.BaseDal = dal; _unitOfWork = unitOfWork; _passwordLibRepository = passwordLibRepository; } @@ -47,7 +44,7 @@ namespace Blog.Core.Services //...... Console.WriteLine($""); - var guestbooks = await _dal.Query(); + var guestbooks = await BaseDal.Query(); Console.WriteLine($"first time : the count of guestbooks is :{guestbooks.Count}"); int ex = 0; @@ -55,7 +52,7 @@ namespace Blog.Core.Services int throwEx = 1 / ex; Console.WriteLine($"insert a data into the table Guestbook now."); - var insertGuestbook = await _dal.Add(new Guestbook() + var insertGuestbook = await BaseDal.Add(new Guestbook() { username = "bbb", blogId = 1, @@ -63,7 +60,7 @@ namespace Blog.Core.Services isshow = true }); - guestbooks = await _dal.Query(); + guestbooks = await BaseDal.Query(); Console.WriteLine($"second time : the count of guestbooks is :{guestbooks.Count}"); @@ -81,7 +78,7 @@ namespace Blog.Core.Services var passwords = await _passwordLibRepository.Query(); Console.WriteLine($"third time : the count of passwords is :{passwords.Count}"); - var guestbooks = await _dal.Query(); + var guestbooks = await BaseDal.Query(); Console.WriteLine($"third time : the count of guestbooks is :{guestbooks.Count}"); return new MessageModel() @@ -114,7 +111,7 @@ namespace Blog.Core.Services //...... Console.WriteLine($""); - var guestbooks = await _dal.Query(); + var guestbooks = await BaseDal.Query(); Console.WriteLine($"first time : the count of guestbooks is :{guestbooks.Count}"); int ex = 0; @@ -122,7 +119,7 @@ namespace Blog.Core.Services int throwEx = 1 / ex; Console.WriteLine($"insert a data into the table Guestbook now."); - var insertGuestbook = await _dal.Add(new Guestbook() + var insertGuestbook = await BaseDal.Add(new Guestbook() { username = "bbb", blogId = 1, @@ -130,7 +127,7 @@ namespace Blog.Core.Services isshow = true }); - guestbooks = await _dal.Query(); + guestbooks = await BaseDal.Query(); Console.WriteLine($"second time : the count of guestbooks is :{guestbooks.Count}"); return true; diff --git a/Blog.Core.Services/IDS4Db/ApplicationUserServices.cs b/Blog.Core.Services/IDS4Db/ApplicationUserServices.cs index 6e39c4a..1cda7d3 100644 --- a/Blog.Core.Services/IDS4Db/ApplicationUserServices.cs +++ b/Blog.Core.Services/IDS4Db/ApplicationUserServices.cs @@ -7,12 +7,5 @@ namespace Blog.Core.IServices public class ApplicationUserServices : BaseServices, IApplicationUserServices { - IBaseRepository _dal; - public ApplicationUserServices(IBaseRepository dal) - { - this._dal = dal; - base.BaseDal = dal; - } - } } \ No newline at end of file diff --git a/Blog.Core.Services/ModuleServices.cs b/Blog.Core.Services/ModuleServices.cs index a27c2ba..c27a63e 100644 --- a/Blog.Core.Services/ModuleServices.cs +++ b/Blog.Core.Services/ModuleServices.cs @@ -11,12 +11,5 @@ namespace Blog.Core.Services public class ModuleServices : BaseServices, IModuleServices { - IBaseRepository _dal; - public ModuleServices(IBaseRepository dal) - { - this._dal = dal; - base.BaseDal = dal; - } - } } diff --git a/Blog.Core.Services/OperateLogServices.cs b/Blog.Core.Services/OperateLogServices.cs index 8715b0d..6527ba9 100644 --- a/Blog.Core.Services/OperateLogServices.cs +++ b/Blog.Core.Services/OperateLogServices.cs @@ -7,12 +7,6 @@ namespace Blog.Core.Services { public partial class OperateLogServices : BaseServices, IOperateLogServices { - IBaseRepository _dal; - public OperateLogServices(IBaseRepository dal) - { - this._dal = dal; - base.BaseDal = dal; - } } } diff --git a/Blog.Core.Services/PasswordLibServices.cs b/Blog.Core.Services/PasswordLibServices.cs index 8aad027..2d2cdb6 100644 --- a/Blog.Core.Services/PasswordLibServices.cs +++ b/Blog.Core.Services/PasswordLibServices.cs @@ -7,12 +7,6 @@ namespace Blog.Core.Services { public partial class PasswordLibServices : BaseServices, IPasswordLibServices { - IBaseRepository _dal; - public PasswordLibServices(IBaseRepository dal) - { - this._dal = dal; - base.BaseDal = dal; - } } } diff --git a/Blog.Core.Services/PayServices.cs b/Blog.Core.Services/PayServices.cs index 2a4c42c..b257d08 100644 --- a/Blog.Core.Services/PayServices.cs +++ b/Blog.Core.Services/PayServices.cs @@ -20,13 +20,10 @@ namespace Blog.Core.Services { public partial class PayServices : BaseServices>, IPayServices { - IBaseRepository> _dal; IHttpContextAccessor _httpContextAccessor; ILogger _logger; - public PayServices(IBaseRepository> dal, ILogger logger, IHttpContextAccessor httpContextAccessor) + public PayServices(ILogger logger, IHttpContextAccessor httpContextAccessor) { - this._dal = dal; - base.BaseDal = dal; _logger = logger; _httpContextAccessor = httpContextAccessor; } diff --git a/Blog.Core.Services/PermissionServices.cs b/Blog.Core.Services/PermissionServices.cs index 2282a38..6c64954 100644 --- a/Blog.Core.Services/PermissionServices.cs +++ b/Blog.Core.Services/PermissionServices.cs @@ -11,12 +11,5 @@ namespace Blog.Core.Services public class PermissionServices : BaseServices, IPermissionServices { - IBaseRepository _dal; - public PermissionServices(IBaseRepository dal) - { - this._dal = dal; - base.BaseDal = dal; - } - } } diff --git a/Blog.Core.Services/RoleModulePermissionServices.cs b/Blog.Core.Services/RoleModulePermissionServices.cs index 04c9b0f..c0248e1 100644 --- a/Blog.Core.Services/RoleModulePermissionServices.cs +++ b/Blog.Core.Services/RoleModulePermissionServices.cs @@ -21,14 +21,13 @@ namespace Blog.Core.Services // 将多个仓储接口注入 public RoleModulePermissionServices( - IRoleModulePermissionRepository dal, + IRoleModulePermissionRepository dal, IBaseRepository moduleRepository, IBaseRepository roleRepository) { this._dal = dal; this._moduleRepository = moduleRepository; this._roleRepository = roleRepository; - base.BaseDal = dal; } /// diff --git a/Blog.Core.Services/RoleServices.cs b/Blog.Core.Services/RoleServices.cs index 93b0c80..50861f7 100644 --- a/Blog.Core.Services/RoleServices.cs +++ b/Blog.Core.Services/RoleServices.cs @@ -13,13 +13,6 @@ namespace Blog.Core.Services /// public class RoleServices : BaseServices, IRoleServices { - - IBaseRepository _dal; - public RoleServices(IBaseRepository dal) - { - this._dal = dal; - base.BaseDal = dal; - } /// /// /// diff --git a/Blog.Core.Services/TasksQzServices.cs b/Blog.Core.Services/TasksQzServices.cs index 14c515e..68560a2 100644 --- a/Blog.Core.Services/TasksQzServices.cs +++ b/Blog.Core.Services/TasksQzServices.cs @@ -7,12 +7,6 @@ namespace Blog.Core.Services { public partial class TasksQzServices : BaseServices, ITasksQzServices { - IBaseRepository _dal; - public TasksQzServices(IBaseRepository dal) - { - this._dal = dal; - base.BaseDal = dal; - } } } diff --git a/Blog.Core.Services/TopicDetailServices.cs b/Blog.Core.Services/TopicDetailServices.cs index 6f8667c..49fb534 100644 --- a/Blog.Core.Services/TopicDetailServices.cs +++ b/Blog.Core.Services/TopicDetailServices.cs @@ -10,13 +10,6 @@ namespace Blog.Core.Services { public class TopicDetailServices : BaseServices, ITopicDetailServices { - IBaseRepository _dal; - public TopicDetailServices(IBaseRepository dal) - { - this._dal = dal; - base.BaseDal = dal; - } - /// /// 获取开Bug数据(缓存) /// diff --git a/Blog.Core.Services/TopicServices.cs b/Blog.Core.Services/TopicServices.cs index 697c946..7d1b3f0 100644 --- a/Blog.Core.Services/TopicServices.cs +++ b/Blog.Core.Services/TopicServices.cs @@ -10,14 +10,6 @@ namespace Blog.Core.Services { public class TopicServices: BaseServices, ITopicServices { - - IBaseRepository _dal; - public TopicServices(IBaseRepository dal) - { - this._dal = dal; - base.BaseDal = dal; - } - /// /// 获取开Bug专题分类(缓存) /// diff --git a/Blog.Core.Services/TrojanUsersServices.cs b/Blog.Core.Services/TrojanUsersServices.cs new file mode 100644 index 0000000..f42f51d --- /dev/null +++ b/Blog.Core.Services/TrojanUsersServices.cs @@ -0,0 +1,18 @@ +using Blog.Core.Common; +using Blog.Core.IRepository.Base; +using Blog.Core.IServices; +using Blog.Core.Model.Models; +using Blog.Core.Services.BASE; +using System.Linq; +using System.Threading.Tasks; + +namespace Blog.Core.Services +{ + /// + /// TrojanUsersServices + /// + public class TrojanUsersServices : BaseServices, ITrojanUsersServices + { + + } +} diff --git a/Blog.Core.Services/UserRoleServices.cs b/Blog.Core.Services/UserRoleServices.cs index df73d2b..38f524d 100644 --- a/Blog.Core.Services/UserRoleServices.cs +++ b/Blog.Core.Services/UserRoleServices.cs @@ -13,13 +13,6 @@ namespace Blog.Core.Services /// public class UserRoleServices : BaseServices, IUserRoleServices { - - IBaseRepository _dal; - public UserRoleServices(IBaseRepository dal) - { - this._dal = dal; - base.BaseDal = dal; - } /// /// /// diff --git a/Blog.Core.Services/WeChatCompanyServices.cs b/Blog.Core.Services/WeChatCompanyServices.cs index c44ff0c..864c408 100644 --- a/Blog.Core.Services/WeChatCompanyServices.cs +++ b/Blog.Core.Services/WeChatCompanyServices.cs @@ -19,13 +19,10 @@ namespace Blog.Core.Services /// public class WeChatCompanyServices : BaseServices, IWeChatCompanyServices { - readonly IBaseRepository _dal; readonly IUnitOfWork _unitOfWork; readonly ILogger _logger; - public WeChatCompanyServices(IBaseRepository dal,IUnitOfWork unitOfWork, ILogger logger) + public WeChatCompanyServices(IUnitOfWork unitOfWork, ILogger logger) { - this._dal = dal; - base.BaseDal = dal; this._unitOfWork = unitOfWork; this._logger = logger; } diff --git a/Blog.Core.Services/WeChatConfigServices.cs b/Blog.Core.Services/WeChatConfigServices.cs index a268a31..612a15d 100644 --- a/Blog.Core.Services/WeChatConfigServices.cs +++ b/Blog.Core.Services/WeChatConfigServices.cs @@ -19,13 +19,10 @@ namespace Blog.Core.Services /// public class WeChatConfigServices : BaseServices, IWeChatConfigServices { - readonly IBaseRepository _dal; readonly IUnitOfWork _unitOfWork; readonly ILogger _logger; - public WeChatConfigServices(IBaseRepository dal,IUnitOfWork unitOfWork, ILogger logger) + public WeChatConfigServices(IUnitOfWork unitOfWork, ILogger logger) { - this._dal = dal; - base.BaseDal = dal; this._unitOfWork = unitOfWork; this._logger = logger; } @@ -237,13 +234,13 @@ namespace Blog.Core.Services QRticket = data.ticket }; data.id = info.userID; - await this._dal.Db.Insertable(weChatQR).ExecuteCommandAsync(); + await this.BaseDal.Db.Insertable(weChatQR).ExecuteCommandAsync(); reData.usersData= data; return MessageModel.Success("获取二维码成功", reData); } public async Task> PushCardMsg(WeChatCardMsgDataDto msg,string ip) { - var bindUser = await _dal.Db.Queryable().Where(t => t.SubFromPublicAccount == msg.info.id && t.CompanyID == msg.info.companyCode && t.IsUnBind == false && msg.info.userID.Contains(t.SubJobID)).SingleAsync(); + var bindUser = await BaseDal.Db.Queryable().Where(t => t.SubFromPublicAccount == msg.info.id && t.CompanyID == msg.info.companyCode && t.IsUnBind == false && msg.info.userID.Contains(t.SubJobID)).SingleAsync(); if (bindUser == null) return MessageModel.Fail("用户不存在或者已经解绑!"); var res = await GetToken(msg?.info?.id); @@ -316,7 +313,7 @@ namespace Blog.Core.Services PushLogTemplateID = msg.cardMsg.template_id, PushLogIP = ip }; - await _dal.Db.Insertable(pushLog).ExecuteCommandAsync(); + await BaseDal.Db.Insertable(pushLog).ExecuteCommandAsync(); } catch (Exception ex) { @@ -355,7 +352,7 @@ namespace Blog.Core.Services if (msg.selectOperate.Equals("one")) { //发送单个 - var usrs = _dal.Db.Queryable().Where(t => t.SubFromPublicAccount.Equals(msg.selectWeChat) && t.CompanyID.Equals(msg.selectCompany) && t.SubJobID.Equals(msg.selectUser)).ToList(); + var usrs = BaseDal.Db.Queryable().Where(t => t.SubFromPublicAccount.Equals(msg.selectWeChat) && t.CompanyID.Equals(msg.selectCompany) && t.SubJobID.Equals(msg.selectUser)).ToList(); foreach (var item in usrs) { msg.selectUser = item.SubUserOpenID; @@ -370,7 +367,7 @@ namespace Blog.Core.Services else { //发送所有 - var usrs = _dal.Db.Queryable().Where(t => t.SubFromPublicAccount.Equals(msg.selectWeChat) && t.CompanyID.Equals(msg.selectCompany)).ToList(); + var usrs = BaseDal.Db.Queryable().Where(t => t.SubFromPublicAccount.Equals(msg.selectWeChat) && t.CompanyID.Equals(msg.selectCompany)).ToList(); foreach (var item in usrs) { msg.selectUser = item.SubUserOpenID; @@ -531,7 +528,7 @@ namespace Blog.Core.Services } public async Task> GetBindUserInfo(WeChatUserInfo info) { - var bindUser = await _dal.Db.Queryable().Where(t => t.SubFromPublicAccount == info.id && t.CompanyID == info.companyCode && info.userID.Equals(t.SubJobID) && t.IsUnBind == false ).FirstAsync(); + var bindUser = await BaseDal.Db.Queryable().Where(t => t.SubFromPublicAccount == info.id && t.CompanyID == info.companyCode && info.userID.Equals(t.SubJobID) && t.IsUnBind == false ).FirstAsync(); if (bindUser == null) return MessageModel.Fail("用户不存在或者已经解绑!"); var res = await GetToken(info.id); if(!res.success) return MessageModel.Fail(res.msg); @@ -552,14 +549,14 @@ namespace Blog.Core.Services } public async Task> UnBind(WeChatUserInfo info) { - var bindUser = await _dal.Db.Queryable().Where(t => t.SubFromPublicAccount == info.id && t.CompanyID == info.companyCode && info.userID.Equals(t.SubJobID) && t.IsUnBind == false ).FirstAsync(); + var bindUser = await BaseDal.Db.Queryable().Where(t => t.SubFromPublicAccount == info.id && t.CompanyID == info.companyCode && info.userID.Equals(t.SubJobID) && t.IsUnBind == false ).FirstAsync(); if (bindUser == null) return MessageModel.Fail("用户不存在或者已经解绑!"); WeChatResponseUserInfo reData = new WeChatResponseUserInfo(); reData.companyCode = info.companyCode; reData.id = info.id; bindUser.IsUnBind = true; bindUser.SubUserRefTime = DateTime.Now; - await _dal.Db.Updateable(bindUser).UpdateColumns(t=> new{ t.IsUnBind,t.SubUserRefTime}).ExecuteCommandAsync(); + await BaseDal.Db.Updateable(bindUser).UpdateColumns(t=> new{ t.IsUnBind,t.SubUserRefTime}).ExecuteCommandAsync(); return MessageModel.Success("用户解绑成功", reData); } @@ -796,12 +793,12 @@ namespace Blog.Core.Services private async Task QRBind(WeChatXMLDto weChat) { - var ticket = await _dal.Db.Queryable().InSingleAsync(weChat.Ticket); + var ticket = await BaseDal.Db.Queryable().InSingleAsync(weChat.Ticket); if (ticket == null) throw new Exception("ticket未找到"); if (ticket.QRisUsed) throw new Exception("ticket已被使用"); if (!ticket.QRpublicAccount.Equals(weChat.publicAccount)) throw new Exception($"公众号错误 need:{ticket.QRpublicAccount} but:{weChat.publicAccount}"); - var bindUser = await _dal.Db.Queryable().Where(t => t.SubFromPublicAccount == ticket.QRpublicAccount && t.CompanyID == ticket.QRbindCompanyID && t.SubJobID == ticket.QRbindJobID).SingleAsync(); + var bindUser = await BaseDal.Db.Queryable().Where(t => t.SubFromPublicAccount == ticket.QRpublicAccount && t.CompanyID == ticket.QRbindCompanyID && t.SubJobID == ticket.QRbindJobID).SingleAsync(); bool isNewBind; if (bindUser == null ) { @@ -835,11 +832,11 @@ namespace Blog.Core.Services try { _unitOfWork.BeginTran(); - await _dal.Db.Updateable(ticket).ExecuteCommandAsync(); + await BaseDal.Db.Updateable(ticket).ExecuteCommandAsync(); if (isNewBind) - await _dal.Db.Insertable(bindUser).ExecuteCommandAsync(); + await BaseDal.Db.Insertable(bindUser).ExecuteCommandAsync(); else - await _dal.Db.Updateable(bindUser).ExecuteCommandAsync(); + await BaseDal.Db.Updateable(bindUser).ExecuteCommandAsync(); _unitOfWork.CommitTran(); } catch diff --git a/Blog.Core.Services/WeChatPushLogServices.cs b/Blog.Core.Services/WeChatPushLogServices.cs index 8ca342f..3e1ca52 100644 --- a/Blog.Core.Services/WeChatPushLogServices.cs +++ b/Blog.Core.Services/WeChatPushLogServices.cs @@ -19,16 +19,6 @@ namespace Blog.Core.Services /// public class WeChatPushLogServices : BaseServices, IWeChatPushLogServices { - readonly IBaseRepository _dal; - readonly IUnitOfWork _unitOfWork; - readonly ILogger _logger; - public WeChatPushLogServices(IBaseRepository dal,IUnitOfWork unitOfWork, ILogger logger) - { - this._dal = dal; - base.BaseDal = dal; - this._unitOfWork = unitOfWork; - this._logger = logger; - } - + } } \ No newline at end of file diff --git a/Blog.Core.Services/WeChatSubServices.cs b/Blog.Core.Services/WeChatSubServices.cs index dfd9840..2b0d7ed 100644 --- a/Blog.Core.Services/WeChatSubServices.cs +++ b/Blog.Core.Services/WeChatSubServices.cs @@ -19,16 +19,6 @@ namespace Blog.Core.Services /// public class WeChatSubServices : BaseServices, IWeChatSubServices { - readonly IBaseRepository _dal; - readonly IUnitOfWork _unitOfWork; - readonly ILogger _logger; - public WeChatSubServices(IBaseRepository dal,IUnitOfWork unitOfWork, ILogger logger) - { - this._dal = dal; - base.BaseDal = dal; - this._unitOfWork = unitOfWork; - this._logger = logger; - } } } \ No newline at end of file diff --git a/Blog.Core.Services/sysUserInfoServices.cs b/Blog.Core.Services/sysUserInfoServices.cs index f536cf7..282ae73 100644 --- a/Blog.Core.Services/sysUserInfoServices.cs +++ b/Blog.Core.Services/sysUserInfoServices.cs @@ -12,16 +12,12 @@ namespace Blog.Core.FrameWork.Services /// public class SysUserInfoServices : BaseServices, ISysUserInfoServices { - - private readonly IBaseRepository _dal; private readonly IBaseRepository _userRoleRepository; private readonly IBaseRepository _roleRepository; - public SysUserInfoServices(IBaseRepository dal, IBaseRepository userRoleRepository, IBaseRepository roleRepository) + public SysUserInfoServices(IBaseRepository userRoleRepository, IBaseRepository roleRepository) { - this._dal = dal; _userRoleRepository = userRoleRepository; _roleRepository = roleRepository; - base.BaseDal = dal; } /// ///