初始化项目
This commit is contained in:
1611
APIserver/Services/Api/OTApi.cs
Normal file
1611
APIserver/Services/Api/OTApi.cs
Normal file
File diff suppressed because it is too large
Load Diff
363
APIserver/Services/Manager/Logs.cs
Normal file
363
APIserver/Services/Manager/Logs.cs
Normal file
@@ -0,0 +1,363 @@
|
||||
using LogServer;
|
||||
using Newtonsoft.Json;
|
||||
using Services.Tool;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity.Validation;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
|
||||
namespace Services.Manager
|
||||
{
|
||||
/// <summary>
|
||||
/// 日志类
|
||||
/// </summary>
|
||||
public partial class Logs
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 锁1 路径/App_Data/Log/
|
||||
/// </summary>
|
||||
private static readonly object _lock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// 锁2 路径/App_Data/TimingPlan/
|
||||
/// </summary>
|
||||
private static readonly object _lock1 = new object();
|
||||
|
||||
/// <summary>
|
||||
/// 锁3 路径/App_Data/UDPlog/
|
||||
/// </summary>
|
||||
private static readonly object _lockUdp = new object();
|
||||
|
||||
public static void WriteErrorLog(Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (ex != null)
|
||||
{
|
||||
string content = "类型:错误代码\r\n";
|
||||
content += "时间:" + DateTime.Now.ToString() + "\r\n";
|
||||
content += "来源:" + ex.TargetSite.ReflectedType.ToString() + "." + ex.TargetSite.Name + "\r\n";
|
||||
content += "内容:" + ex.Message + "\r\n";
|
||||
|
||||
Page page = new Page();
|
||||
HttpServerUtility server = page.Server;
|
||||
string dir = server.MapPath("/App_Data/Log/");
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, System.Text.Encoding.UTF8); //创建日志文件
|
||||
FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
|
||||
|
||||
|
||||
|
||||
//}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteLog(string msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
|
||||
string content = "类型:调试日志\r\n";
|
||||
content += "时间:" + DateTime.Now.ToString() + "\r\n";
|
||||
content += "内容:" + msg + "\r\n";
|
||||
|
||||
Page page = new Page();
|
||||
HttpServerUtility server = page.Server;
|
||||
string dir = server.MapPath("/App_Data/Log/");
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, System.Text.Encoding.UTF8); //创建日志文件
|
||||
FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
//}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteErrorLog(string errsrc, Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
string errtxt = "";
|
||||
string exname = ex.GetType().ToString();
|
||||
if (exname == "System.Data.Entity.Validation.DbEntityValidationException")
|
||||
{
|
||||
foreach (var item in ((DbEntityValidationException)ex).EntityValidationErrors)
|
||||
{
|
||||
foreach (var err in item.ValidationErrors)
|
||||
{
|
||||
errtxt += "EntityValidationErrors >>>>>> “" + err.PropertyName + "”字段" + err.ErrorMessage + "\r\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
string content = (!string.IsNullOrEmpty(errsrc) ? "来自页面:" + errsrc : "") + "\r\n";
|
||||
content += "发生时间:" + DateTime.Now.ToString() + "\r\n";
|
||||
content += "异常对像:" + ex.TargetSite.ReflectedType.ToString() + "." + ex.TargetSite.Name + "\r\n";
|
||||
content += "错误追踪:" + ex.StackTrace + "\r\n";
|
||||
content += "错误提示:" + ex.Message + "\r\n" + errtxt;
|
||||
if (ex.InnerException != null && ex.InnerException.InnerException != null)
|
||||
content += ex.InnerException.InnerException.Message + "\r\n";
|
||||
//if (BaseConfigs.GetLogInDB == 1)
|
||||
//{
|
||||
//TSysLog log = new TSysLog();
|
||||
//log.Content = content;
|
||||
//log.Type = "系统日志";
|
||||
//log.CreateTime = DateTime.Now;
|
||||
//DataAccess.CreateSysLog().Add(log);
|
||||
//}
|
||||
//if (BaseConfigs.GetLogInFile == 1)
|
||||
//{
|
||||
Page page = new Page();
|
||||
HttpServerUtility server = page.Server;
|
||||
string dir = server.MapPath("/App_Data/Log/");
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, System.Text.Encoding.UTF8); //创建日志文件
|
||||
FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
//}
|
||||
|
||||
}
|
||||
catch (Exception )
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void WriteTimingPlanLog(string msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
|
||||
string content = "类型:调试日志 ";
|
||||
content += "时间:" + DateTime.Now.ToString() + " ";
|
||||
content += "内容:" + msg + "\r\n";
|
||||
|
||||
string dir = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/TimingPlan/";
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
lock (_lock1)
|
||||
{
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, Encoding.UTF8); //创建日志文件
|
||||
//FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
}
|
||||
public static void WriteUserinfo(dynamic msgs)
|
||||
{
|
||||
try
|
||||
{
|
||||
string msg = JsonConvert.SerializeObject(msgs);
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
|
||||
string content = "类型:调试日志 ";
|
||||
content += "时间:" + DateTime.Now.ToString() + " ";
|
||||
content += "内容:" + msg + "\r\n";
|
||||
|
||||
string dir = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/Userinfo/";
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
lock (_lock1)
|
||||
{
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, Encoding.UTF8); //创建日志文件
|
||||
//FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteErrorTimingPlanLog(string errsrc, Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ex != null)
|
||||
{
|
||||
string content = (!string.IsNullOrEmpty(errsrc) ? "来自作业线程:" + errsrc : "") + "\r\n";
|
||||
content += "发生时间:" + DateTime.Now.ToString() + "\r\n";
|
||||
content += "异常对像:" + ex.TargetSite.ReflectedType.ToString() + "." + ex.TargetSite.Name + "\r\n";
|
||||
content += "错误追踪:" + ex.StackTrace + "\r\n";
|
||||
content += "错误提示:" + ex.Message + "\r\n";
|
||||
if (ex.InnerException != null && ex.InnerException.InnerException != null)
|
||||
content += ex.InnerException.InnerException.Message + "\r\n";
|
||||
|
||||
string dir = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/TimingPlan/";
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
lock (_lock1)
|
||||
{
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, Encoding.UTF8); //创建日志文件
|
||||
FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exl)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
LogHelp.WriteExceptionLog(exl);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteTimingUDPLog(string msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
|
||||
string content = "类型:调试日志 ";
|
||||
content += "时间:" + DateTime.Now.ToString() + " ";
|
||||
content += "内容:" + msg + "\r\n";
|
||||
|
||||
string dir = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/UDPLog/";
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
lock (_lockUdp)
|
||||
{
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, Encoding.UTF8); //创建日志文件
|
||||
//FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteErrorTimingUDPLog(string errsrc, Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ex != null)
|
||||
{
|
||||
string content = (!string.IsNullOrEmpty(errsrc) ? "来自作业线程:" + errsrc : "") + "\r\n";
|
||||
content += "发生时间:" + DateTime.Now.ToString() + "\r\n";
|
||||
content += "异常对像:" + ex.TargetSite.ReflectedType.ToString() + "." + ex.TargetSite.Name + "\r\n";
|
||||
content += "错误追踪:" + ex.StackTrace + "\r\n";
|
||||
content += "错误提示:" + ex.Message + "\r\n";
|
||||
if (ex.InnerException != null && ex.InnerException.InnerException != null)
|
||||
content += ex.InnerException.InnerException.Message + "\r\n";
|
||||
|
||||
string dir = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/UDPLog/";
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
lock (_lockUdp)
|
||||
{
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, Encoding.UTF8); //创建日志文件
|
||||
FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exl)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(exl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class LogHelp
|
||||
{
|
||||
/// <summary>
|
||||
/// 写入日志
|
||||
/// </summary>
|
||||
/// <param name="ex">异常对象</param>
|
||||
/// <param name="operationer">操作人</param>
|
||||
/// <param name="actionName">功能站点名称</param>
|
||||
public static void WriteExceptionLog(Exception ex, string actionName = "", string operationer = "")
|
||||
{
|
||||
if (HttpContext.Current == null)
|
||||
{
|
||||
ExceptionLogHelper.Log(new ExceptionLogMessage() { ActionName = actionName, exception = ex, Header = "", Url = "线程", Operationer = "线程", IP = "" });
|
||||
}
|
||||
else
|
||||
{
|
||||
ExceptionLogHelper.Log(new ExceptionLogMessage() { ActionName = actionName, exception = ex, Header = HttpContext.Current.Request.Headers.ToString(), Url = HttpContext.Current.Request.Url.ToString(), Operationer = operationer, IP = IPHelper.GetIP() });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
APIserver/Services/Properties/AssemblyInfo.cs
Normal file
36
APIserver/Services/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("Services")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Services")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2023")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("c4906dbc-e27f-41a0-821c-bd5846c613ea")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
160
APIserver/Services/Services.csproj
Normal file
160
APIserver/Services/Services.csproj
Normal file
@@ -0,0 +1,160 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{C4906DBC-E27F-41A0-821C-BD5846C613EA}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Services</RootNamespace>
|
||||
<AssemblyName>Services</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="BouncyCastle.Crypto, Version=1.8.5.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
|
||||
<HintPath>..\packages\BouncyCastle.1.8.5\lib\BouncyCastle.Crypto.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Google.Protobuf, Version=3.19.4.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Google.Protobuf.3.19.4\lib\net45\Google.Protobuf.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="JWT, Version=8.0.0.0, Culture=neutral, PublicKeyToken=6f98bca0f40f2ecf, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\JWT.8.6.0\lib\net46\JWT.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="K4os.Compression.LZ4, Version=1.2.6.0, Culture=neutral, PublicKeyToken=2186fa9121ef231d, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\K4os.Compression.LZ4.1.2.6\lib\net46\K4os.Compression.LZ4.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="K4os.Compression.LZ4.Streams, Version=1.2.6.0, Culture=neutral, PublicKeyToken=2186fa9121ef231d, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\K4os.Compression.LZ4.Streams.1.2.6\lib\net46\K4os.Compression.LZ4.Streams.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="K4os.Hash.xxHash, Version=1.0.6.0, Culture=neutral, PublicKeyToken=32cd54395057cec3, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\K4os.Hash.xxHash.1.0.6\lib\net46\K4os.Hash.xxHash.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.6.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySql.Data, Version=8.0.29.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MySql.Data.8.0.29\lib\net452\MySql.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySqlConnector, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d33d3e53aa5f8c92, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MySqlConnector.2.1.10\lib\net471\MySqlConnector.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SqlSugar, Version=5.1.4.86, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SqlSugar.5.1.4.87\lib\SqlSugar.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ComponentModel" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Diagnostics.DiagnosticSource, Version=5.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.5.0.1\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Management" />
|
||||
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.Encodings.Web, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.Encodings.Web.6.0.0\lib\net461\System.Text.Encodings.Web.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.Json, Version=6.0.0.7, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.Json.6.0.7\lib\net461\System.Text.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Transactions" />
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Ubiety.Dns.Core, Version=2.2.1.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MySql.Data.8.0.29\lib\net452\Ubiety.Dns.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ZstdNet, Version=1.4.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MySql.Data.8.0.29\lib\net452\ZstdNet.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Api\OTApi.cs" />
|
||||
<Compile Include="Manager\Logs.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Tool\IPHelper.cs" />
|
||||
<Compile Include="Tool\TokenHelper.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LogServer\LogServer.csproj">
|
||||
<Project>{1fecf303-b32c-4e1c-975b-d0d4a983fedc}</Project>
|
||||
<Name>LogServer</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Models\Models.csproj">
|
||||
<Project>{cfbef2f8-4b58-4ee1-bcb1-91c9d071ca45}</Project>
|
||||
<Name>Models</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\UH_CENTER\UH_CENTER.csproj">
|
||||
<Project>{ec7f524d-d23a-4d46-be60-59fad0b480e9}</Project>
|
||||
<Name>UH_CENTER</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.props'))" />
|
||||
<Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" />
|
||||
</Project>
|
||||
85
APIserver/Services/Tool/IPHelper.cs
Normal file
85
APIserver/Services/Tool/IPHelper.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace Services.Tool
|
||||
{
|
||||
public class IPHelper
|
||||
{
|
||||
public static string GetIP()
|
||||
{
|
||||
if (HttpContext.Current == null)
|
||||
{
|
||||
throw new Exception("HttpContext.Current为null");
|
||||
}
|
||||
string ip = string.Empty;
|
||||
if (!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_VIA"]))
|
||||
ip = Convert.ToString(HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]);
|
||||
if (string.IsNullOrEmpty(ip))
|
||||
ip = Convert.ToString(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);
|
||||
return ip;
|
||||
}
|
||||
|
||||
/// <summary>获取客户端的IP,可以取到代理后的IP
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetClientIp()
|
||||
{
|
||||
string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
|
||||
if (!string.IsNullOrEmpty(result))
|
||||
{
|
||||
//可能有代理
|
||||
if (result.IndexOf(".", StringComparison.Ordinal) == -1)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
if (result.IndexOf(",", StringComparison.Ordinal) != -1)
|
||||
{
|
||||
//有“,”,估计多个代理。取第一个不是内网的IP。
|
||||
result = result.Replace(" ", "").Replace("'", "");
|
||||
string[] temparyip = result.Split(",;".ToCharArray());
|
||||
foreach (string t in temparyip)
|
||||
{
|
||||
if (IsIpAddress(t)
|
||||
&& t.Substring(0, 3) != "10."
|
||||
&& t.Substring(0, 7) != "192.168"
|
||||
&& t.Substring(0, 7) != "172.16.")
|
||||
{
|
||||
return t; //找到不是内网的地址
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (IsIpAddress(result)) //代理即是IP格式
|
||||
return result;
|
||||
else
|
||||
result = null; //代理中的内容 非IP,取IP
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(result))
|
||||
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
|
||||
if (string.IsNullOrEmpty(result))
|
||||
result = HttpContext.Current.Request.UserHostAddress;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>判断是否是IP地址格式 0.0.0.0
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="str">待判断的IP地址</param>
|
||||
/// <returns>true or false</returns>
|
||||
public static bool IsIpAddress(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str) || str.Length < 7 || str.Length > 15) return false;
|
||||
|
||||
const string regformat = @"^d{1,3}[.]d{1,3}[.]d{1,3}[.]d{1,3}$";
|
||||
|
||||
Regex regex = new Regex(regformat, RegexOptions.IgnoreCase);
|
||||
return regex.IsMatch(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
76
APIserver/Services/Tool/TokenHelper.cs
Normal file
76
APIserver/Services/Tool/TokenHelper.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using JWT;
|
||||
using JWT.Algorithms;
|
||||
using JWT.Serializers;
|
||||
using Newtonsoft.Json;
|
||||
using Services.Manager;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Services.Tool
|
||||
{
|
||||
/// <summary>
|
||||
/// Token辅助类
|
||||
/// 需要引用jwt包
|
||||
/// </summary>
|
||||
public class TokenHelper
|
||||
{
|
||||
//私钥
|
||||
static string Private_key = "CWLCJLWQZYY";
|
||||
//创建一个世界协调时间提供对象 utc时间协调时间
|
||||
static IDateTimeProvider provider = new UtcDateTimeProvider();
|
||||
//时间戳起点时间
|
||||
static DateTime timeEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
//序列化对象
|
||||
static JsonNetSerializer serializer = new JsonNetSerializer();
|
||||
//编码序列化对象
|
||||
static IBase64UrlEncoder encoder = new JwtBase64UrlEncoder();
|
||||
//编码算法
|
||||
static IJwtAlgorithm algorithm = new HMACSHA384Algorithm();
|
||||
//jwt编码
|
||||
static JwtEncoder jwtEncoder = new JwtEncoder(algorithm, serializer, encoder);
|
||||
//验证对象
|
||||
static IJwtValidator validator = new JwtValidator(serializer, provider);
|
||||
//jwt解码
|
||||
static JwtDecoder decoder = new JwtDecoder(serializer, validator, encoder, algorithm);
|
||||
/// <summary>
|
||||
/// 加密的数据键值对传入
|
||||
/// </summary>
|
||||
/// <param name="keys"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetToken(Dictionary<string, object> keys, float day)
|
||||
{
|
||||
//荷载,负载,最重要的信息,token中保存的信息 keys
|
||||
var now = provider.GetNow();
|
||||
//获取当前时间距离时间戳的差秒
|
||||
var epochSecons = Math.Round((now - timeEpoch).TotalSeconds);
|
||||
keys.Add("exp", (epochSecons + 3600) * 24 * day);//设置过期时间
|
||||
//jwt同一加密
|
||||
var token = jwtEncoder.Encode(keys, Private_key);
|
||||
return token;
|
||||
}
|
||||
public static string CheckToken(string token)
|
||||
{
|
||||
try
|
||||
{
|
||||
//解码 tonken 私钥 验证是否过期
|
||||
//过期时间验证 系统默认起始时间为1970,1,1,0,0,0 如果验证过期需要保证起始时间一致
|
||||
//要么手动验证过期,现在时间与起始时间的差值如果大于设置exp则过期
|
||||
return JsonConvert.DeserializeObject<Datainfo>(decoder.Decode(token, Private_key, verify: true)).data.ToString();//str数据转成Dictionary<string,object>类型即可
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.WriteLog("Error:" + ex);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
public class Datainfo
|
||||
{
|
||||
public dynamic data { get; set; }
|
||||
public dynamic exp { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
32
APIserver/Services/app.config
Normal file
32
APIserver/Services/app.config
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||
</configSections>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.29.0" newVersion="8.0.29.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<entityFramework>
|
||||
<providers>
|
||||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
|
||||
</providers>
|
||||
</entityFramework>
|
||||
</configuration>
|
||||
24
APIserver/Services/packages.config
Normal file
24
APIserver/Services/packages.config
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="BouncyCastle" version="1.8.5" targetFramework="net472" />
|
||||
<package id="EntityFramework" version="6.4.4" targetFramework="net472" />
|
||||
<package id="Google.Protobuf" version="3.19.4" targetFramework="net472" />
|
||||
<package id="JWT" version="8.6.0" targetFramework="net472" />
|
||||
<package id="K4os.Compression.LZ4" version="1.2.6" targetFramework="net472" />
|
||||
<package id="K4os.Compression.LZ4.Streams" version="1.2.6" targetFramework="net472" />
|
||||
<package id="K4os.Hash.xxHash" version="1.0.6" targetFramework="net472" />
|
||||
<package id="Microsoft.Bcl.AsyncInterfaces" version="6.0.0" targetFramework="net472" />
|
||||
<package id="MySql.Data" version="8.0.29" targetFramework="net472" />
|
||||
<package id="MySqlConnector" version="2.1.10" targetFramework="net472" />
|
||||
<package id="Newtonsoft.Json" version="13.0.2" targetFramework="net472" />
|
||||
<package id="SqlSugar" version="5.1.4.87" targetFramework="net472" />
|
||||
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
|
||||
<package id="System.Diagnostics.DiagnosticSource" version="5.0.1" targetFramework="net472" />
|
||||
<package id="System.Memory" version="4.5.4" targetFramework="net472" />
|
||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net472" />
|
||||
<package id="System.Text.Encodings.Web" version="6.0.0" targetFramework="net472" />
|
||||
<package id="System.Text.Json" version="6.0.7" targetFramework="net472" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user