diff --git a/Service/Led/LedClient.cs b/Service/Led/LedClient.cs new file mode 100644 index 0000000..1f7de86 --- /dev/null +++ b/Service/Led/LedClient.cs @@ -0,0 +1,129 @@ +using System.Net.Sockets; +using log4net; + +namespace Service.Led; + +public class LedClient +{ + #region msg + + public static Dictionary Dictionary = new Dictionary() + { + { + "houtui", + new byte[] + { + 0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, + 0x00, 0x0C, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x34, 0xBA, 0xF3, 0xCD, 0xCB, 0x00, 0x00, + 0x0D, 0x0A + } + }, + { + "qianjin", + new byte[] + { + 0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, + 0x00, 0x0C, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x37, 0xC7, 0xB0, 0xBD, 0xF8, 0x00, 0x00, + 0x0D, 0x0A + } + }, + { + "xiangzuo", + new byte[] + { + 0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, + 0x00, 0x0C, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x31, 0xCF, 0xF2, 0xD7, 0xF3, 0x00, 0x00, + 0x0D, 0x0A + } + }, + { + "xiangyou", + new byte[] + { + 0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, + 0x00, 0x0C, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x31, 0xCF, 0xF2, 0xD3, 0xD2, 0x00, 0x00, + 0x0D, 0x0A + } + }, + { + "tingzhunle", + new byte[] + { + 0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, + 0x00, 0x0E, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3B, 0x31, 0xCD, 0xA3, 0xD7, 0xBC, 0xC1, 0xCB, + 0x00, 0x00, 0x0D, 0x0A + } + }, + { + "wuche", + new byte[] + { + 0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, + 0x00, 0x0C, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x36, 0xCE, 0xDE, 0xB3, 0xB5, 0x00, 0x00, + 0x0D, 0x0A + } + }, + { + "zuoqian", + new byte[] + { + 0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, + 0x00, 0x10, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x31, 0xCF, 0xF2, 0xD7, 0xF3, 0xC7, 0xB0, + 0xB7, 0xBD, 0x00, 0x00, 0x0D, 0x0A + } + }, + { + "youqian", + new byte[] + { + 0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, + 0x00, 0x10, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x31, 0xCF, 0xF2, 0xD3, 0xD2, 0xC7, 0xB0, + 0xB7, 0xBD, 0x00, 0x00, 0x0D, 0x0A + } + }, + { + "zuohou", + new byte[] + { + 0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, + 0x00, 0x10, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x31, 0xCF, 0xF2, 0xD7, 0xF3, 0xBA, 0xF3, + 0xB7, 0xBD, 0x00, 0x00, 0x0D, 0x0A + } + } + }; + + #endregion + + private static readonly ILog Log = LogManager.GetLogger(typeof(LedClient)); + private static TcpClient? _tcpClient; + + public static bool Init(string ip, int port) + { + Log.Info($"begin connect {ip}:{port}"); + _tcpClient = new TcpClient(); + _tcpClient.Connect(ip, port); + Log.Info($"end connect {ip}:{port} {_tcpClient.Connected}"); + return _tcpClient.Connected; + } + + public static bool InnerSend(byte[] bytes) + { + if (_tcpClient?.Connected ?? true) + { + _tcpClient.GetStream().Write(bytes, 0, bytes.Length); + } + + return false; + } + + public static bool SendMsgByKey(string key) + { + Log.Info($"send by {key}"); + if (Dictionary.TryGetValue(key, out var bytes)) + { + return InnerSend(bytes); + } + + return false; + } +} diff --git a/WebStarter/Controllers/LedController.cs b/WebStarter/Controllers/LedController.cs new file mode 100644 index 0000000..20afd65 --- /dev/null +++ b/WebStarter/Controllers/LedController.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Mvc; +using Service.Led; + +namespace WebStarter.Controllers; + +/// +/// led测试工具 +/// +[ApiController] +[Route("api/[controller]")] +public class LedController +{ + /// + /// 发送led提示 + /// + /// houtui,qianjin,xiangzuo + /// + [HttpGet("SendBy/{key}")] + public bool SendByKey(string key) + { + return LedClient.SendMsgByKey(key); + } +} diff --git a/WebStarter/Program.cs b/WebStarter/Program.cs index 762462d..6f9cdf3 100644 --- a/WebStarter/Program.cs +++ b/WebStarter/Program.cs @@ -1,10 +1,8 @@ using System.Text; using Autofac; using Autofac.Extensions.DependencyInjection; -using Common.Util; using Entity.Dto.Resp; using HybirdFrameworkCore.Autofac; -using HybirdFrameworkCore.AutoTask; using HybirdFrameworkCore.Configuration; using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Redis; @@ -13,11 +11,7 @@ using Mapster; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.IdentityModel.Tokens; using Service.Charger.Client; -using Service.Cloud.Client; -using Service.Execute; -using Service.Padar.Client; -using Service.Plc.Client; -using Service.Ups; +using Service.Led; using SqlSugar; using SqlSugar.IOC; @@ -162,6 +156,12 @@ AppInfo.Container = app.Services.GetAutofacRoot(); //PadarMgr.InitClient(); +if (AppSettingsHelper.GetBool("led", "enable")) +{ + LedClient.Init(AppSettingsHelper.GetContent("led", "ip"), Convert.ToInt32(AppSettingsHelper.GetContent("led", "port"))); +} + + //现场调试plc连接 AppInfo.Container = app.Services.GetAutofacRoot(); ClientMgr.InitClient(); @@ -171,4 +171,4 @@ ClientMgr.InitClient(); //TaskInit.Init(); -app.Run(); \ No newline at end of file +app.Run(); diff --git a/WebStarter/appsettings.dev.json b/WebStarter/appsettings.dev.json index de69972..599d1ad 100644 --- a/WebStarter/appsettings.dev.json +++ b/WebStarter/appsettings.dev.json @@ -23,12 +23,18 @@ "AllowedHosts": "*", ",": null, "Cryptogram": { - "StrongPassword": "false", // 是否开启密码强度验证 - "PasswordStrengthValidation": "(?=^.{6,16}$)(?=.*\\d)(?=.*\\W+)(?=.*[A-Z])(?=.*[a-z])(?!.*\\n).*$", // 密码强度验证正则表达式,必须须包含大小写字母、数字和特殊字符的组合,长度在6-16之间 - "PasswordStrengthValidationMsg": "密码必须包含大小写字母、数字和特殊字符的组合,长度在6-16之间", // 密码强度验证消息提示 - "CryptoType": "SM2", // 密码加密算法:MD5、SM2、SM4 - "PublicKey": "0484C7466D950E120E5ECE5DD85D0C90EAA85081A3A2BD7C57AE6DC822EFCCBD66620C67B0103FC8DD280E36C3B282977B722AAEC3C56518EDCEBAFB72C5A05312", // 公钥 - "PrivateKey": "8EDB615B1D48B8BE188FC0F18EC08A41DF50EA731FA28BF409E6552809E3A111" // 私钥 + "StrongPassword": "false", + // 是否开启密码强度验证 + "PasswordStrengthValidation": "(?=^.{6,16}$)(?=.*\\d)(?=.*\\W+)(?=.*[A-Z])(?=.*[a-z])(?!.*\\n).*$", + // 密码强度验证正则表达式,必须须包含大小写字母、数字和特殊字符的组合,长度在6-16之间 + "PasswordStrengthValidationMsg": "密码必须包含大小写字母、数字和特殊字符的组合,长度在6-16之间", + // 密码强度验证消息提示 + "CryptoType": "SM2", + // 密码加密算法:MD5、SM2、SM4 + "PublicKey": "0484C7466D950E120E5ECE5DD85D0C90EAA85081A3A2BD7C57AE6DC822EFCCBD66620C67B0103FC8DD280E36C3B282977B722AAEC3C56518EDCEBAFB72C5A05312", + // 公钥 + "PrivateKey": "8EDB615B1D48B8BE188FC0F18EC08A41DF50EA731FA28BF409E6552809E3A111" + // 私钥 }, //Login "TokenOptions": { @@ -38,34 +44,62 @@ "Issuer": "jwtIssuer" }, "Upload": { - "Path": "Upload/{yyyy}/{MM}/{dd}", // 文件上传目录 - "MaxSize": 20480, // 文件最大限制KB:1024*20 - "ContentType": [ "image/jpg", "image/png", "image/jpeg", "image/gif", "image/bmp", "text/plain", "application/pdf", "application/msword", "application/vnd.ms-excel", "application/vnd.ms-powerpoint", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "video/mp4" ], - "EnableMd5": false // 启用文件MDF5验证-防止重复上传 + "Path": "Upload/{yyyy}/{MM}/{dd}", + // 文件上传目录 + "MaxSize": 20480, + // 文件最大限制KB:1024*20 + "ContentType": [ + "image/jpg", + "image/png", + "image/jpeg", + "image/gif", + "image/bmp", + "text/plain", + "application/pdf", + "application/msword", + "application/vnd.ms-excel", + "application/vnd.ms-powerpoint", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "video/mp4" + ], + "EnableMd5": false + // 启用文件MDF5验证-防止重复上传 }, //SysLogin "JWTSettings": { - "ValidateIssuerSigningKey": true, // 是否验证密钥,bool 类型,默认true - "IssuerSigningKey": "3c1cbc3f546eda35168c3aa3cb91780fbe703f0996c6d123ea96dc85c70bbc0a", // 密钥,string 类型,必须是复杂密钥,长度大于16 - "ValidateIssuer": true, // 是否验证签发方,bool 类型,默认true - "ValidIssuer": "Admin.NET", // 签发方,string 类型 - "ValidateAudience": true, // 是否验证签收方,bool 类型,默认true - "ValidAudience": "Admin.NET", // 签收方,string 类型 - "ValidateLifetime": true, // 是否验证过期时间,bool 类型,默认true,建议true + "ValidateIssuerSigningKey": true, + // 是否验证密钥,bool 类型,默认true + "IssuerSigningKey": "3c1cbc3f546eda35168c3aa3cb91780fbe703f0996c6d123ea96dc85c70bbc0a", + // 密钥,string 类型,必须是复杂密钥,长度大于16 + "ValidateIssuer": true, + // 是否验证签发方,bool 类型,默认true + "ValidIssuer": "Admin.NET", + // 签发方,string 类型 + "ValidateAudience": true, + // 是否验证签收方,bool 类型,默认true + "ValidAudience": "Admin.NET", + // 签收方,string 类型 + "ValidateLifetime": true, + // 是否验证过期时间,bool 类型,默认true,建议true //"ExpiredTime": 20, // 过期时间,long 类型,单位分钟,默认20分钟,最大支持 13 年 - "ClockSkew": 5, // 过期时间容错值,long 类型,单位秒,默认5秒 - "Algorithm": "HS256", // 加密算法,string 类型,默认 HS256 - "RequireExpirationTime": true // 验证过期时间,设置 false 将永不过期 + "ClockSkew": 5, + // 过期时间容错值,long 类型,单位秒,默认5秒 + "Algorithm": "HS256", + // 加密算法,string 类型,默认 HS256 + "RequireExpirationTime": true + // 验证过期时间,设置 false 将永不过期 }, - - "SnowId": { - "WorkerId": 1, // 机器码 全局唯一 - "WorkerIdBitLength": 6, // 机器码位长 默认值6,取值范围 [1, 19] - "SeqBitLength": 6, // 序列数位长 默认值6,取值范围 [3, 21](建议不小于4,值越大性能越高、Id位数也更长) - "WorkerPrefix": "adminnet_" // 缓存前缀 + "WorkerId": 1, + // 机器码 全局唯一 + "WorkerIdBitLength": 6, + // 机器码位长 默认值6,取值范围 [1, 19] + "SeqBitLength": 6, + // 序列数位长 默认值6,取值范围 [3, 21](建议不小于4,值越大性能越高、Id位数也更长) + "WorkerPrefix": "adminnet_" + // 缓存前缀 }, - "HttpContextRequest": { "Scheme": "" }, @@ -87,5 +121,10 @@ }, "task": { "enable": false + }, + "led": { + "enable": false, + "ip": "127.0.0.1", + "port": 10021 } -} \ No newline at end of file +} diff --git a/WebStarter/appsettings.prod.json b/WebStarter/appsettings.prod.json index d6398d1..2531f8a 100644 --- a/WebStarter/appsettings.prod.json +++ b/WebStarter/appsettings.prod.json @@ -121,5 +121,10 @@ }, "task": { "enable": true + }, + "led": { + "enable": false, + "ip": "127.0.0.1", + "port": 10021 } }