baseline: 小军 WMS 二开代码原始快照(含 SynOABusiness.cs Debugger.Break)

This commit is contained in:
Gaussian committed 2026-11-06 18:38:38 +08:00
commit c2b0e7be0d
6522 files changed
+3530643

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
using Opsoft.NetCore.O3App.Domain.Models;
namespace Opsoft.NetCore.O3App.WebApi
{
public interface IAuthenticateService
{
bool IsAuthenticated(LoginRequest request, out string token);
}
}
+12
View File
@@ -0,0 +1,12 @@
using Newtonsoft.Json.Linq;
using Opsoft.Data.Model;
using Opsoft.NetCore.O3App.Domain.Models;
namespace Opsoft.NetCore.O3App.WebApi
{
public interface IUserService
{
bool IsValid(LoginRequest req);
JObject GetUser(string userId, string dbAias);
}
}
+933
View File
@@ -0,0 +1,933 @@
using Opsoft.Data;
using System;
using System.Collections.Generic;
using System.IO;
using System.Management;
using System.Security.Cryptography;
using System.Text;
using System.Xml;
namespace Opsoft.NetCore.O3App.WebApi
{
/// <summary>
///
/// </summary>
internal static class SecurityManage
{
private static string _lkey = "$ta|RT~#";
private static string strKeyList = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
// 取得设备硬盘的卷标号
private static string GetDiskVolumeSerialNumber()
{
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"d:\"");
disk.Get();
return disk.GetPropertyValue("VolumeSerialNumber").ToString();
}
//获得CPU的序列号
private static string getCpu(bool isServer)
{
string strCpu = string.Empty;
string strPC = string.Empty;
try
{
if (isServer)
{
ManagementClass myCpu = new ManagementClass("win32_Processor");
ManagementObjectCollection myCpuConnection = myCpu.GetInstances();
foreach (ManagementObject myObject in myCpuConnection)
{
strPC = myObject.ToString();
strCpu = myObject.Properties["Processorid"].Value.ToString();
break;
}
}
else
{
strCpu = getPCSystem();
}
}
catch
{
strCpu = strPC + GetIP();
}
return strCpu;
}
private static string getPCSystem()
{
try
{
return Environment.MachineName + GetIP() + GetMacAddress();
}
catch
{
return "unknow";
}
}
public static string GetDiskID()
{
try
{
//获取硬盘ID
String HDid = "";
ManagementClass mc = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
HDid = (string)mo.Properties["Model"].Value;
}
moc = null;
mc = null;
return HDid;
}
catch
{
return "unknow";
}
finally
{
}
}
public static string GetIP()
{
try
{
//获取IP地址
string st = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"])
{
Array ar;
ar = (Array)mo.Properties["IpAddress"].Value;
st = ar.GetValue(0).ToString();
break;
}
}
moc = null;
mc = null;
return st;
}
catch
{
return "unknow";
}
finally
{
}
}
public static string GetMacAddress()
{
try
{
//获取网卡硬件地址
string mac = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"])
{
mac = mo["MacAddress"].ToString();
break;
}
}
moc = null;
mc = null;
return mac;
}
catch
{
return "unknow";
}
finally
{
}
}
/// <summary>
/// 得到客户序列号
/// </summary>
/// <returns></returns>
public static string GetCustomerKey()
{
bool isServer = GetServerMode() == 1;//获取服务器模式
string TempKey = getCpu(isServer);//获得Cpu序列号
string LastKey = "";
int[] strid = new int[TempKey.Length * 2];//
for (int i = 0; i < TempKey.Length; i++)//把字符赋给数组
{
strid[i] = (((int)TempKey[i]) + i) % strKeyList.Length;
}
for (int i = TempKey.Length - 1; i >= 0; i--)//把字符赋给数组
{
strid[TempKey.Length + i - 1] = (((int)TempKey[i]) + i) % strKeyList.Length;
}
for (int i = 0; i < strid.Length; i++)//从数组随机抽取24个字符组成新的字符生成机器码
{
LastKey += strKeyList[strid[i]].ToString();
}
return LastKey.Substring(0, 6) + "-" + LastKey.Substring(6, 6) + "-" + LastKey.Substring(12, 6) + "-" + LastKey.Substring(18, 6);
}
/// <summary>
/// 得到客户序列号
/// </summary>
/// <returns></returns>
public static string GetLocalCustomerKey(string ProID)
{
string wLicenseInfo = "";
ManagerLicenseInfo myInfo = new ManagerLicenseInfo();
wLicenseInfo = myInfo.GetMacID();
wLicenseInfo = DecryptDES(wLicenseInfo, _lkey);
return wLicenseInfo;
}
// 默认密钥向量
private static byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
/// <summary>
/// DES加密字符串
/// </summary>
/// <param name="encryptString">待加密的字符串</param>
/// <param name="encryptKey">加密密钥,8位</param>
/// <returns>成功返回加密后的字符串,失敗返回源串</returns>
public static string EncryptDES(string encryptString, string encryptKey)
{
try
{
byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
byte[] rgbIV = Keys;
byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
cStream.Write(inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock();
return Convert.ToBase64String(mStream.ToArray());
}
catch
{
return encryptString;
}
}
/// <summary>
/// DES解密字符串
/// </summary>
/// <param name="decryptString">待解密的字符串</param>
/// <param name="decryptKey">解密密鑰,8位</param>
/// <returns>成功返回解密后的字符串,失敗返回源串</returns>
public static string DecryptDES(string decryptString, string decryptKey)
{
try
{
byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey);
byte[] rgbIV = Keys;
byte[] inputByteArray = Convert.FromBase64String(decryptString);
DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider();
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
cStream.Write(inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock();
return Encoding.UTF8.GetString(mStream.ToArray());
}
catch
{
return decryptString;
}
}
/// <summary>
///
/// </summary>
/// <param name="strLicense"></param>
/// <returns></returns>
public static LicenseInfo GetLicenseInfo(string strLicense)
{
string strMAC = GetCustomerKey().Replace("-", "");
return GetLicenseInfo(strLicense, strMAC, "");
}
/// <summary>
///
/// </summary>
/// <param name="strLicense"></param>
/// <returns></returns>
public static LicenseInfo GetLicenseInfo(string strLicense, string strMAC)
{
return GetLicenseInfo(strLicense, strMAC, "");
}
/// <summary>
///
/// </summary>
/// <param name="strLicense"></param>
/// <param name="strMAC"></param>
/// <returns></returns>
public static LicenseInfo GetLicenseInfo(string strLicense, string strMAC, string wCustomerName)
{
if (string.IsNullOrEmpty(strMAC))
{
strMAC = GetCustomerKey().Replace("-", "");
}
string LastString = "";
LicenseInfo myInfo = new LicenseInfo();
StringBuilder mySB = new StringBuilder();
strLicense = SecurityManage.DecryptDES(strLicense, _lkey);
mySB.Append(strLicense);
try
{
myInfo.CustomerName = string.IsNullOrEmpty(wCustomerName) ? "" : SecurityManage.DecryptDES(wCustomerName, _lkey);
int iLen = strLicense.Length - 1;
LastString = "";
for (int i = 4; i >= 0; i--)
{
int ii = ((int)strMAC[i]) % iLen;
LastString = mySB[ii].ToString() + LastString;
mySB.Remove(ii, 1);
iLen--;
}
try
{
if (string.IsNullOrEmpty(LastString))
myInfo.MaxUsers = 0;
else
myInfo.MaxUsers = Convert.ToInt16(LastString);
}
catch (System.Exception)
{
myInfo.MaxUsers = 0;
}
LastString = "";
for (int i = 7; i >= 0; i--)
{
int ii = ((int)strMAC[i]) % iLen;
LastString = GetKeyChar(mySB[ii].ToString()) + LastString;
mySB.Remove(ii, 1);
iLen--;
}
myInfo.LicenseDays = new DateTime(int.Parse(LastString.Substring(0, 4)), int.Parse(LastString.Substring(4, 2)), int.Parse(LastString.Substring(6, 2)));
LastString = "";
for (int i = 3; i >= 0; i--)
{
int ii = ((int)strMAC[i]) % iLen;
LastString = GetKeyChar(mySB[ii].ToString()) + LastString;
mySB.Remove(ii, 1);
iLen--;
}
//myInfo.ProductVer = "V" + int.Parse(LastString.Substring(0, 2)).ToString() + "." + int.Parse(LastString.Substring(2, 2)).ToString();
//
LastString = "";
for (int i = 7; i >= 0; i--)
{
int ii = ((int)strMAC[i]) % iLen;
LastString = GetKeyChar(mySB[ii].ToString()) + LastString;
mySB.Remove(ii, 1);
iLen--;
}
myInfo.SerialDate = new DateTime(int.Parse(LastString.Substring(0, 4)), int.Parse(LastString.Substring(4, 2)), int.Parse(LastString.Substring(6, 2)));
LastString = "";
for (int i = strMAC.Length - 1; i >= 0; i--)
{
int ii = ((int)strMAC[i]) % iLen;
LastString = mySB[ii].ToString() + LastString;
mySB.Remove(ii, 1);
iLen--;
}
if (LastString == strMAC)
{
myInfo.SerialNumber = LastString = LastString.Substring(0, 6) + "-" + LastString.Substring(6, 6) + "-" + LastString.Substring(12, 6) + "-" + LastString.Substring(18, 6);
}
else
{
myInfo.SerialNumber = "";
}
for (int i = 2; i >= 0; i--)
{
int ii = ((int)strMAC[i]) % iLen;
LastString = mySB[ii].ToString() + LastString;
mySB.Remove(ii, 1);
iLen--;
}
myInfo.SoftMode = LastString;
//myInfo.ProductID = LastString;
//myInfo.ProductName = GetProductID(LastString);
}
catch (System.Exception)
{
myInfo.SerialNumber = "";
}
return myInfo;
}
private static string GetKeyChar(string key)
{
int iKey = (int)key[0];
string _Seed = "0";
if (iKey >= (int)'A' && iKey <= (int)'B')
{
return "0";
}
if (iKey >= (int)'C' && iKey <= (int)'D')
{
return "1";
}
if (iKey >= (int)'E' && iKey <= (int)'F')
{
return "2";
}
if (iKey >= (int)'G' && iKey <= (int)'I')
{
return "3";
}
if (iKey >= (int)'J' && iKey <= (int)'L')
{
return "4";
}
if (iKey >= (int)'M' && iKey <= (int)'O')
{
return "5";
}
if (iKey >= (int)'P' && iKey <= (int)'R')
{
return "6";
}
if (iKey >= (int)'S' && iKey <= (int)'U')
{
return "7";
}
if (iKey >= (int)'V' && iKey <= (int)'X')
{
return "8";
}
if (iKey >= (int)'Y' && iKey <= (int)'Z')
{
return "9";
}
return _Seed;
}
/// <summary>
///
/// </summary>
/// <param name="wMacID"></param>
/// <returns></returns>
public static List<LicenseInfo> GetLocalSystemLicenseInfo(string wMacID)
{
// 改写成文件形式,不再写入注册表
if (string.IsNullOrEmpty(wMacID))
wMacID = SecurityManage.GetCustomerKey();
string mMacID = wMacID.Replace("-", "");
List<LicenseInfo> myList = new List<LicenseInfo>();
ManagerLicenseInfo myInfo = new ManagerLicenseInfo();
List<tagLicenseString> infoList = myInfo.GetLocalSystemLicenseInfo();
foreach (tagLicenseString strInfo in infoList)
{
string wLicenseInfo = DecryptDES(strInfo.LiInfo, _lkey);
string wCU = strInfo.CuInfo;
LicenseInfo subInfo = GetLicenseInfo(wLicenseInfo, mMacID, wCU);
if (subInfo.SerialNumber == wMacID)
{
myList.Add(subInfo);
}
}
return myList;
}
/// <summary>
///
/// </summary>
/// <param name="wLicenseInfo"></param>
/// <param name="wMacID"></param>
/// <param name="wCustomerName">没有加密的客户识别码</param>
/// <param name="wMode">没有加密的客户识别码</param>
public static void WriteLicenseInfo(string wLicenseInfo, string wMacID, string wCustomerName, string wMode)
{
wMacID = SecurityManage.EncryptDES(wMacID, _lkey);
ManagerLicenseInfo myInfo = new ManagerLicenseInfo();
myInfo.WriteLicenseInfo(wLicenseInfo, wMacID, wCustomerName, wMode);
}
/// <summary>
/// 查询服务器注册模式
/// </summary>
/// <returns></returns>
public static int GetServerMode()
{
ManagerLicenseInfo myInfo = new ManagerLicenseInfo();
return myInfo.GetServerMode();
}
/// <summary>
/// 更新服务器注册模式
/// <param name="wMode">服务器注册模式</param>
public static string WriteServerMode(string wMode)
{
ManagerLicenseInfo myInfo = new ManagerLicenseInfo();
myInfo.WriteModeInfo(wMode);
string key = GetCustomerKey();
return key;
}
}
/// <summary>
///
/// </summary>
internal static class LicenseFunction
{
/// <summary>
/// 得到版本号
/// </summary>
/// <param name="Ver1">主版本号</param>
/// <param name="Ver2">次版本号</param>
/// <returns></returns>
public static string GetVer(int Ver1, int Ver2)
{
string strVer1 = Ver1.ToString().PadLeft(2, '0');
string strVer2 = Ver2.ToString().PadLeft(2, '0');
string rtnCode = "";
rtnCode += GetKeyChar(strVer1.Substring(0, 1));
rtnCode += GetKeyChar(strVer1.Substring(1, 1));
rtnCode += GetKeyChar(strVer2.Substring(0, 1));
rtnCode += GetKeyChar(strVer2.Substring(1, 1));
return rtnCode;
}
/// <summary>
/// 得到使用期限
/// </summary>
/// <param name="wKey"></param>
/// <param name="wPDate"></param>
/// <returns></returns>
public static string GetDays(string wKey, DateTime wPDate)
{
DateTime wToday = DateTime.Today;
switch (wKey)
{
case "A":
// 1 年
wPDate = wToday.AddYears(1);
break;
case "B":
// 2 年
wPDate = wToday.AddYears(2);
break;
case "C":
// 3 年
wPDate = wToday.AddYears(3);
break;
case "E":
break;
case "F":
//无期限 + 100年
wPDate = new DateTime(2099, 12, 31);
break;
}
return wPDate.Year.ToString().PadLeft(4, '0') + wPDate.Month.ToString().PadLeft(2, '0') + wPDate.Day.ToString().PadLeft(2, '0');
}
private static string GetKeyChar(string key)
{
int _Seed = 65;
switch (key)
{
case "0":
_Seed = GetSeed((int)'A', (int)'B');
break;
case "1":
_Seed = GetSeed((int)'C', (int)'D');
break;
case "2":
_Seed = GetSeed((int)'E', (int)'F');
break;
case "3":
_Seed = GetSeed((int)'G', (int)'I');
break;
case "4":
_Seed = GetSeed((int)'J', (int)'L');
break;
case "5":
_Seed = GetSeed((int)'M', (int)'O');
break;
case "6":
_Seed = GetSeed((int)'P', (int)'R');
break;
case "7":
_Seed = GetSeed((int)'S', (int)'U');
break;
case "8":
_Seed = GetSeed((int)'V', (int)'X');
break;
case "9":
_Seed = GetSeed((int)'Y', (int)'Z');
break;
}
return ((char)_Seed).ToString();
}
private static int GetSeed(int fromN, int toN)
{
DateTime dt = new DateTime();
dt = DateTime.Now;
Random rnd = new Random(dt.Millisecond);
return rnd.Next(fromN, toN);
}
/// <summary>
/// 产生注册码
/// </summary>
/// <param name="Days">使用限限</param>
/// <param name="MacKey">机器码</param>
/// <returns></returns>
public static string GetProductKey(string ProID, string Days, string MacKey, int MaxUsers)
{
string Ver = GetVer(7, 0);
//string Ver = LicenseFunction.GetVer(7,0);
string strMAC = MacKey.Replace("-", ""); //分开机器码
string ProductKey = Guid.NewGuid().ToString().ToUpper();
StringBuilder mySB = new StringBuilder();
mySB.Append(ProductKey);
int iLen = ProductKey.Length; //总长度
for (int i = 0; i < ProID.Length; i++)
{
int ii = ((int)strMAC[i]) % iLen;
mySB.Insert(ii, ProID[i]);
iLen++;
}
for (int i = 0; i < strMAC.Length; i++)
{
int ii = ((int)strMAC[i]) % iLen;
mySB.Insert(ii, strMAC[i]);
iLen++;
}
string wToDay = DateTime.Now.Year.ToString().PadLeft(4, '0') + DateTime.Now.Month.ToString().PadLeft(2, '0') + DateTime.Now.Day.ToString().PadLeft(2, '0');
for (int i = 0; i < wToDay.Length; i++)
{
int ii = ((int)strMAC[i]) % iLen;
mySB.Insert(ii, GetKeyChar(wToDay[i].ToString()));
iLen++;
}
for (int i = 0; i < Ver.Length; i++)
{
int ii = ((int)strMAC[i]) % iLen;
mySB.Insert(ii, Ver[i]);
iLen++;
}
for (int i = 0; i < Days.Length; i++)
{
int ii = ((int)strMAC[i]) % iLen;
mySB.Insert(ii, GetKeyChar(Days[i].ToString()));
iLen++;
}
string strMaxUsers = MaxUsers.ToString().PadLeft(5, '0').Left(5);
for (int i = 0; i < strMaxUsers.Length; i++)
{
int ii = ((int)strMAC[i]) % iLen;
mySB.Insert(ii, strMaxUsers[i]);
iLen++;
}
return mySB.ToString();
}
}
/// <summary>
///
/// </summary>
internal class ManagerLicenseInfo : XmlDocument
{
/// <summary>
/// XML 文件路径
/// </summary>
private string tXMLPath
{
get
{
return Path.Combine(DBConnectionInfo.DBFilename);
}
}
/// <summary>
///
/// </summary>
public ManagerLicenseInfo()
{
Init(this.tXMLPath);
}
private void Init(string FileNameAll)
{
if (!File.Exists(FileNameAll))
{
//如果文件不存,先创建文件
XmlDocument myFile = new XmlDocument();
myFile.LoadXml(
"<?xml version=\"1.0\" encoding=\"utf-8\"?> \r\n" +
"<DBManage> " + "\r\n" +
"<DBGroup></DBGroup>" + "\r\n" +
"<DBInfo></DBInfo>" + "\r\n" +
"<UserInfo >" + "\r\n" +
"<User ID='" + SymmetricMethod.Decrypt("admin") + "' Pwd='" + SymmetricMethod.Decrypt("admin") + "' />" + "\r\n" +
"</UserInfo>" + "\r\n" +
"<LicenseList>" + "\r\n" +
"</LicenseList>" + "\r\n" +
"<MacCodeInfo></MacCodeInfo>" + "\r\n" +
"<ServerMode></ServerMode>" + "\r\n" +
"</DBManage>");
myFile.Save(FileNameAll);
}
this.Load(FileNameAll);
}
/// <summary>
/// 写入LicenseInfo
/// </summary>
/// <param name="wLicenseInfo"></param>
/// <param name="ProID"></param>
/// <param name="wMacID"></param>
public void WriteLicenseInfo(string wLicenseInfo, string wMacID, string wCustomerName, string wMode)
{
WriteMode(wMode);
WriteMacID(wMacID);
WriteLicense(wLicenseInfo, wCustomerName);
this.Save(tXMLPath);
}
/// <summary>
/// 写入Mode
/// <param name="wMode"></param>
public void WriteModeInfo(string wMode)
{
WriteMode(wMode);
this.Save(tXMLPath);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public List<tagLicenseString> GetLocalSystemLicenseInfo()
{
List<tagLicenseString> myList = new List<tagLicenseString>();
XmlNode rootNode = this.FindNode("DBManage/LicenseList");
if (rootNode != null)
{
if (rootNode.HasChildNodes)
{
for (int i = 0; i < rootNode.ChildNodes.Count; i++)
{
XmlAttribute subA = rootNode.ChildNodes[i].Attributes["CustomerName"];
string wCU = "";
if (subA != null)
{
wCU = subA.InnerXml;
}
tagLicenseString mSub = new tagLicenseString() { LiInfo = rootNode.ChildNodes[i].InnerXml, CuInfo = wCU };
myList.Add(mSub);
}
}
}
return myList;
}
private void WriteMode(string mode)
{
XmlNode xmlMode = this.FindNode("DBManage/ServerMode");
if (xmlMode == null)
{
XmlNode Root = FindNode("DBManage");
this.CreateNode(Root, "ServerMode", mode);
}
else
{
xmlMode.InnerXml = mode;
}
}
private void WriteMacID(string wMacID)
{
XmlNode xmlMacID = this.FindNode("DBManage/MacCodeInfo");
if (xmlMacID == null)
{
XmlNode Root = FindNode("DBManage");
this.CreateNode(Root, "MacCodeInfo", wMacID);
}
else
{
xmlMacID.InnerXml = wMacID;
}
}
private void WriteLicense(string wLicenseInfo, string wCustomerName)
{
string ProID = "WE";
XmlNode xmlLicenseList = this.FindNode("DBManage/LicenseList");
if (xmlLicenseList == null)
{
XmlNode Root = FindNode("DBManage");
xmlLicenseList = this.CreateNode(Root, "LicenseList", "");
}
XmlNode xmlProID = this.FindNode("DBManage/LicenseList/" + ProID);
if (xmlProID == null)
{
XmlNode Root = FindNode("DBManage/LicenseList");
XmlNode subNote = this.CreateNode(Root, ProID, wLicenseInfo);
XmlAttribute subAttribute = this.CreateAttribute("CustomerName");
subAttribute.InnerXml = wCustomerName;
subNote.Attributes.Append(subAttribute);
}
else
{
xmlProID.InnerXml = wLicenseInfo;
XmlAttribute subAttribute = xmlProID.Attributes["CustomerName"];
if (subAttribute == null)
{
subAttribute = this.CreateAttribute("CustomerName");
subAttribute.InnerXml = wCustomerName;
xmlProID.Attributes.Append(subAttribute);
}
else
{
subAttribute.InnerXml = wCustomerName;
}
}
}
/// <summary>
/// 得到授权模式
/// </summary>
/// <returns></returns>
public int GetServerMode()
{
XmlNode xmlMode = this.FindNode("DBManage/ServerMode");
if (xmlMode == null)
{
return 1;
}
else
{
if (xmlMode.InnerXml.ToStringEx().Equals("2"))
{
return 2;
}
else
{
return 1;
}
}
}
/// <summary>
/// 得到机器码
/// </summary>
/// <returns></returns>
public string GetMacID()
{
XmlNode xmlMacID = this.FindNode("DBManage/MacCodeInfo");
if (xmlMacID == null)
{
return "";
}
else
{
return xmlMacID.InnerXml;
}
}
private XmlNode CreateNode(XmlNode ParaNode, string Name, string Value)
{
XmlNode objNodeChild = this.CreateElement(Name);
objNodeChild.InnerXml = Value;
ParaNode.AppendChild(objNodeChild);
return objNodeChild;
}
private XmlNode FindNode(string xPath)
{
XmlNode xmlNode = this.SelectSingleNode(xPath);
return xmlNode;
}
}
/// <summary>
/// 用于保存LicenseInfo
/// </summary>
internal class tagLicenseString
{
public string LiInfo { get; set; }
public string CuInfo { get; set; }
}
internal class LicenseInfo
{
public LicenseInfo()
{
}
public string CustomerName { get; set; }
public string ErrType { get; set; }
public bool HaveLicense
{
get
{
if (string.IsNullOrEmpty(SerialNumber))
return false;
else
return true;
}
}
public DateTime LicenseDays { get; set; }
/// <summary>
/// 软件期限
/// </summary>
public string LicenseString
{
get
{
if (SerialDate.AddYears(100) == LicenseDays)
{
return "终身使用";
}
else
{
return LicenseDays.ToLongDateString();
}
}
}
public int MaxUsers { get; set; }
public DateTime SerialDate { get; set; }
public string SerialNumber { get; set; }
public string SoftMode { get; set; }
}
}
+29
View File
@@ -0,0 +1,29 @@
using System.Security.Cryptography;
using System.Text;
namespace Opsoft.NetCore.O3App.WebApi
{
public static class MD5Help
{
//这样容易解的密码变的更难解=无解
const string MD5Key = "r16TD&*~12{]?[+3";
/// <summary>
///
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static string MD5Encrypt(string source, string hStrText = MD5Key)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] buffer = md5.ComputeHash(Encoding.UTF8.GetBytes(source));
string strMD5Value = string.Empty;
for (int i = 0; i < buffer.Length; i++)
{
int a = 0xf & buffer[i] >> 4;
int b = buffer[i] & 0xf;
strMD5Value += hStrText.Substring(a, 1) + hStrText[b];//0xf & buffer[i] >> 4 buffer[i] & 0xf
}
return strMD5Value;
}
}
}
+94
View File
@@ -0,0 +1,94 @@
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json;
using Opsoft.NetCore.O3App.Domain.Models;
using Opsoft.NetCore.O3App.WebApi.Model;
using System;
using System.Data;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text;
using Opsoft.Data;
namespace Opsoft.NetCore.O3App.WebApi
{
public class TokenAuthenticationService : IAuthenticateService
{
private readonly IUserService _userService;
private readonly TokenManagement _tokenManagement;
public TokenAuthenticationService(IUserService userService, IOptions<TokenManagement> tokenManagement)
{
_userService = userService;
_tokenManagement = tokenManagement.Value;
}
public bool IsAuthenticated(LoginRequest request, out string token)
{
token = string.Empty;
if (!_userService.IsValid(request))
return false;
var claims = new[]
{
new Claim(ClaimTypes.Name,request.UserID),
new Claim(ClaimTypes.UserData,"{\"UserName\": \""+ request.UserName +"\",\"DBaias\": \""+ request.DBAias +"\"}")
};
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_tokenManagement.Secret));
var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
var jwtToken = new JwtSecurityToken(_tokenManagement.Issuer, _tokenManagement.Audience, claims, expires: DateTime.Now.AddMinutes(_tokenManagement.AccessExpiration), signingCredentials: credentials);
token = new JwtSecurityTokenHandler().WriteToken(jwtToken);
return true;
}
public static LoginRequest GetLoinInfo(string Token)
{
JwtSecurityToken jwtToken = new JwtSecurityTokenHandler().ReadJwtToken(Token);
LoginRequest myInfo = new LoginRequest();
myInfo.UserID = jwtToken.Claims.First(o => o.Type == ClaimTypes.Name).Value;
dynamic temType = JsonConvert.DeserializeObject<dynamic>(jwtToken.Claims.First(o => o.Type == ClaimTypes.UserData).Value);
myInfo.UserName = temType.UserName;
myInfo.DBAias = temType.DBaias;
using APPServerContext context = new APPServerContext(myInfo.DBAias, myInfo.UserID);
var loginUserInfo = context.Database
.SqlQuery($"SELECT * FROM dbo.SYS_LOGINUSER WHERE USER_ID='{myInfo.UserID}'").Rows[0];
myInfo.PAType = loginUserInfo["PATYPE"].ToStringEx();
myInfo.PAID = loginUserInfo["PA_ID"].ToStringEx();
myInfo.IsPDA = loginUserInfo["IS_PDA"].ToBoolean();
myInfo.EMAIL = loginUserInfo["EMAIL"].ToStringEx();
myInfo.ERPID = loginUserInfo["ERPID"].ToStringEx();
myInfo.ISDEFAULT = loginUserInfo["ISDEFAULT"].ToBoolean();
myInfo.CARDID = loginUserInfo["CARDID"].ToStringEx();
myInfo.DOMAINUSER = loginUserInfo["DOMAINUSER"].ToStringEx();
myInfo.LASTLOGINTIME = loginUserInfo["LASTLOGINTIME"].ToStringEx();
myInfo.PHOTO = loginUserInfo["PHOTO"]==DBNull.Value?null:(byte[])loginUserInfo["PHOTO"];
var operatorInfo = context.Database.SqlQuery(
@$"SELECT
T1.FOPERATORTYPE,
T2.FDETAILID
FROM dbo.T_BD_OPERATOR T1
LEFT JOIN dbo.T_BD_OPERATORENTRY T2
ON T2.FINTERID = T1.FINTERID
LEFT JOIN dbo.T_HR_EMPINFO T3
ON T3.FSTAFFID = T2.FSTAFFID
WHERE T3.FNUMBER='{myInfo.PAID}'");
if (operatorInfo.Rows.Count > 0)
{
var operatorInfoGroup = operatorInfo
.AsEnumerable()
.GroupBy(o => o["FOPERATORTYPE"].ToStringEx())
.ToList();
foreach (var group in operatorInfoGroup)
{
if (!group.All(o => o["FDETAILID"].ToStringEx().IsNullOrEmpty()))
{
myInfo.OperatorIdDic.Add(group.Key, group.First(o => !o["FDETAILID"].ToStringEx().IsNullOrEmpty())["FDETAILID"].ToStringEx());
}
}
}
return myInfo;
}
}
}
+135
View File
@@ -0,0 +1,135 @@
using Newtonsoft.Json.Linq;
using Opsoft.Data;
using Opsoft.Data.Model;
using Opsoft.NetCore.O3App.Domain.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace Opsoft.NetCore.O3App.WebApi
{
public class UserService : IUserService
{
/// <summary>
/// 验证用户是否可以登录成功
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public bool IsValid(LoginRequest req)
{
try
{
using (APPServerContext DBContext = new APPServerContext(req.DBAias, req.UserID))
{
SYS_LOGINUSER myUser = DBContext.Database.SqlQuery<SYS_LOGINUSER>(
" select USER_ID,USER_NAME,PR_PASSWORD,FDELETED " +
" from SYS_LOGINUSER " +
" where USER_ID=" + DBContext.GetDBParName("@PA1"),
DBContext.CreateParameter("@PA1", req.UserID)).SingleOrDefault();
if (myUser != null)
{
var pass = myUser.GetPassWord();
var encryptPass = MD5Help.MD5Encrypt(pass);
req.UserName = myUser.USER_NAME;
if (req.IsFaceLogin || encryptPass.Equals(req.Password))
{
LicenseInfo PPermissions = this.GetLicense();
if (PPermissions.HaveLicense)
{
if (PPermissions.LicenseDays >= PPermissions.SerialDate)
{
if (PPermissions.LicenseDays < PPermissions.SerialDate.AddDays(30))
{
req.errtype = "3";//软件将过服务到期日,请提前申请或购买下一年度服务
return true;
}
else
{
req.errtype = "8";
return true;
}
}
else
{
req.errtype = "4"; //软件服务到期日已过,请申请或购买下一年度服务!
return true;
}
}
else
{
req.errtype = "5"; //软件未注册,请先注册再使用!
}
}
else
{
req.errtype = "2"; //密码不正确
}
}
else
{
req.errtype = "1"; //用户名不存在
}
}
return false;
}
catch (System.Exception ex)
{
req.errtype = ex.Message;
return false;
}
}
public JObject GetUser(string userId, string dbAias)
{
using APPServerContext DBContext = new APPServerContext(dbAias, userId);
var parameter = DBContext.CreateParameter("@UserId", userId);
string sql = $" SELECT T01.*,T03.FROLETYPE FROM SYS_LOGINUSER T01 LEFT JOIN SYS_USERROLERELATION T02 ON T01.USER_ID = T02.USER_ID LEFT JOIN SYS_USERROLE T03 ON T03.FROLENUMBER = T02.FROLEID WHERE T01.USER_ID = {parameter.ParameterName} ";
DataTable userMessage = DBContext.Database.SqlQuery(sql, parameter);
string fRoleType = "1";
JObject returnJObject = new JObject();
foreach (DataRow userRow in userMessage.Rows)
{
if (returnJObject.Property("USER_ID") == null)
{
returnJObject.Add("USER_ID", userRow["USER_ID"].ToStringEx());
returnJObject.Add("USER_NAME", userRow["USER_NAME"].ToStringEx());
returnJObject.Add("PR_PASSWORD", userRow["PR_PASSWORD"].ToStringEx());
returnJObject.Add("FDELETED", userRow["FDELETED"].ToStringEx());
returnJObject.Add("DBAias", dbAias);
}
if (userRow["FROLETYPE"].ToStringEx().Equals("0"))
{
fRoleType = "0";
}
}
returnJObject.Add("FROLETYPE", fRoleType);
DBContext.Database.SqlNonQueryAsync(sql, parameter);
return returnJObject;
}
private LicenseInfo GetLicense()
{
LicenseInfo myInfo = new LicenseInfo() { SerialNumber = "" };
try
{
//强制执行抓机器码
string Maction = "";//SecurityManage.GetLocalCustomerKey(wProductCode);
List<LicenseInfo> myList = SecurityManage.GetLocalSystemLicenseInfo(Maction);
foreach (LicenseInfo subinfo in myList)
{
//如果产品及版本有注册,那么就看使用日期是否已经有到
subinfo.SerialDate = DateTime.Now;
return subinfo;
}
}
catch (Exception e)
{
throw e;
}
return myInfo;
}
}
}