diff --git a/Assets/Scripts/Editor/FixedMainEditor.cs b/Assets/Scripts/Editor/FixedMainEditor.cs index 44d2fa2c..568d4eee 100644 --- a/Assets/Scripts/Editor/FixedMainEditor.cs +++ b/Assets/Scripts/Editor/FixedMainEditor.cs @@ -1,3 +1,6 @@ +using QFramework; +using System; +using System.IO; using UnityEditor; using UnityEngine; @@ -31,5 +34,26 @@ public class FixedMainEditor Menu.SetChecked("Tools/强制Main场景启动", isFixedMain); return true; } + + + + [MenuItem("Tools/创建时间锁")] + private static void TimerLock() + { + //创建数据资源文件 + //泛型是继承自ScriptableObject的类 + TimerLock asset = ScriptableObject.CreateInstance(); + //前一步创建的资源只是存在内存中,现在要把它保存到本地 + //通过编辑器API,创建一个数据资源文件,第二个参数为资源文件在Assets目录下的路径 + AssetDatabase.CreateAsset(asset, "Assets/TimerLock.asset"); + //保存创建的资源 + AssetDatabase.SaveAssets(); + //刷新界面 + AssetDatabase.Refresh(); + } + + + + } #endif \ No newline at end of file diff --git a/Assets/Scripts/Editor/TimerLock.cs b/Assets/Scripts/Editor/TimerLock.cs new file mode 100644 index 00000000..a7482a9f --- /dev/null +++ b/Assets/Scripts/Editor/TimerLock.cs @@ -0,0 +1,11 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[CreateAssetMenu(fileName = "时间锁", menuName = "创建时间锁/配置文件")] +public class TimerLock : ScriptableObject +{ + [Header("软件有效期")] + public string time; + +} diff --git a/Assets/Scripts/Editor/TimerLock.cs.meta b/Assets/Scripts/Editor/TimerLock.cs.meta new file mode 100644 index 00000000..d412f066 --- /dev/null +++ b/Assets/Scripts/Editor/TimerLock.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3fa014c2238b5a942b96b9f55a3f9841 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Editor/VirtualFPostProcess.cs b/Assets/Scripts/Editor/VirtualFPostProcess.cs index a687e3f0..a6d39e6f 100644 --- a/Assets/Scripts/Editor/VirtualFPostProcess.cs +++ b/Assets/Scripts/Editor/VirtualFPostProcess.cs @@ -29,6 +29,34 @@ public class VirtualFPostProcess : IPostprocessBuildWithReport Debug.LogWarning("未找到数据目录: " + dataFolderPath); } DeletAssetBundle(buildOutputPath); + + // 生成时间锁 + GneratorTimerLock(); + } + + /// + /// 生成时间锁文件 + /// + public void GneratorTimerLock() + { + if (File.Exists(Application.dataPath + "/TimerLock.asset")) + { + string path = "Assets/TimerLock.asset"; + var asset = AssetDatabase.LoadAssetAtPath(path); + if (asset != null) + { + if (string.IsNullOrEmpty(asset.time) == false) + { + //第一次获取获取系统时间 + DateTime currentDateTime = DateTime.Now; + string RecordData = currentDateTime.ToString("yyyy-MM-dd HH:mm:ss"); + string strMerge = asset.time + "|" + RecordData; + EncryptFileCreator.EncryptAndSaveData(strMerge, "Timer.txt"); + } + } + } + + } /// @@ -64,7 +92,7 @@ public class VirtualFPostProcess : IPostprocessBuildWithReport Debug.LogError($"Directory not found: {path}"); } } - else if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows|| EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows64) + else if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows || EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows64) { string path = Path.Combine(buildOutPutPath, "VirtualFramwork_Data", "StreamingAssets", "AssetBundles"); if (Directory.Exists(path)) @@ -92,7 +120,7 @@ public class VirtualFPostProcess : IPostprocessBuildWithReport Debug.LogError($"Directory not found: {path}"); } } - + } diff --git a/Assets/Scripts/Tools/ZXKLicenses.meta b/Assets/Scripts/Tools/ZXKLicenses.meta new file mode 100644 index 00000000..2dfa7e11 --- /dev/null +++ b/Assets/Scripts/Tools/ZXKLicenses.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4fec87e21a9630c46b1a6ef7dec72ea6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tools/ZXKLicenses/Encryption.meta b/Assets/Scripts/Tools/ZXKLicenses/Encryption.meta new file mode 100644 index 00000000..65aade6d --- /dev/null +++ b/Assets/Scripts/Tools/ZXKLicenses/Encryption.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bb335401f53d3c94490f449b410da1ba +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tools/ZXKLicenses/Encryption/DateManager.cs b/Assets/Scripts/Tools/ZXKLicenses/Encryption/DateManager.cs new file mode 100644 index 00000000..24f60bc0 --- /dev/null +++ b/Assets/Scripts/Tools/ZXKLicenses/Encryption/DateManager.cs @@ -0,0 +1,88 @@ +using System; +using System.IO; +using UnityEngine; +using UnityEngine.Events; + +public class DateManager : MonoBehaviour +{ + private string EndTimer;//缁撴潫鏃堕棿 + private string RecordData; + private void Start() + { + UpdateTime(); + } + + /// + /// 鏇存柊绯荤粺鏃堕棿 + /// + public void UpdateTime(UnityAction back1 = null, UnityAction back2 = null, UnityAction back3 = null) + { + try + { + string datas = DecryptFileReader.ReadAndDecryptData("Timer.txt"); + EndTimer = datas.Split('|')[0]; + RecordData = datas.Split('|')[1]; + //绗竴娆¤幏鍙栬幏鍙栫郴缁熸椂闂 + DateTime currentDateTime = DateTime.Now; + string Data = currentDateTime.ToString("yyyy-MM-dd HH:mm:ss"); + if (DateTime.TryParse(RecordData, out DateTime recordDateTime) && DateTime.TryParse(Data, out DateTime nowDateTime)) + { + if (recordDateTime > nowDateTime) + { + Debug.Log("浠跨湡鏂囦欢琚崯鍧忥紝璇疯仈绯荤鐞嗗憳杩涜淇"); + back1?.Invoke(); + } + else + { + //鎶婁笂涓娆″瓨鍌ㄥ緱绯荤粺鏃堕棿鏇存柊鍒版渶鏂 + string timer = "Timer.txt"; + RecordData = Data; + string strMerge = EndTimer + "|" + RecordData; + EncryptFileCreator.EncryptAndSaveData(strMerge, timer); + back3?.Invoke(); + } + } + } + catch (Exception e) + { + Debug.LogError($"鏁版嵁鍑洪敊: {e.Message}"); + back1?.Invoke(); + } + + if (JudgeExpire()) + { + Debug.Log("璇疯仈绯荤鐞嗗憳杩涜鍗囩骇"); + back2?.Invoke(); + } + } + + /// + /// 鍒ゆ柇鏄惁鍒版湡 + /// + /// + public bool JudgeExpire() + { + if (DateTime.TryParse(EndTimer, out DateTime endDataTime) && DateTime.TryParse(RecordData, out DateTime recordDateTime)) + { + //缁撴潫鏃ユ湡灏忎簬鐩墠鏃ユ湡浠h〃鍒版湡 + if (endDataTime < recordDateTime) + { + return true; + } + } + return false; + } + + + /// + /// 缁欏鎴锋墦鍖呯殑鏃跺,闇瑕佽缃瓻ndTimer,鐒跺悗杩愯涓娆$敓鎴愭枃浠跺苟娉ㄩ噴鎺 + /// + public void CreatTimer() + { + //绗竴娆¤幏鍙栬幏鍙栫郴缁熸椂闂 + DateTime currentDateTime = DateTime.Now; + RecordData = currentDateTime.ToString("yyyy-MM-dd HH:mm:ss"); + string strMerge = EndTimer + "|" + RecordData; + EncryptFileCreator.EncryptAndSaveData(strMerge, "Timer.txt"); + } +} diff --git a/Assets/Scripts/Tools/ZXKLicenses/Encryption/DateManager.cs.meta b/Assets/Scripts/Tools/ZXKLicenses/Encryption/DateManager.cs.meta new file mode 100644 index 00000000..604aec1b --- /dev/null +++ b/Assets/Scripts/Tools/ZXKLicenses/Encryption/DateManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 718cf7f3f1b16f141ab751a37af8cae1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tools/ZXKLicenses/Encryption/DecryptFileReader.cs b/Assets/Scripts/Tools/ZXKLicenses/Encryption/DecryptFileReader.cs new file mode 100644 index 00000000..9a68c1bb --- /dev/null +++ b/Assets/Scripts/Tools/ZXKLicenses/Encryption/DecryptFileReader.cs @@ -0,0 +1,44 @@ +using System.IO; +using System.Security.Cryptography; +using System.Text; +using UnityEngine; + +public class DecryptFileReader +{ + private static byte[] key = Encoding.UTF8.GetBytes("Sixteen byte key"); // 鍔犲瘑瀵嗛挜锛岄渶涓庡姞瀵嗘椂涓鑷 + private static byte[] iv = Encoding.UTF8.GetBytes("InitializationVe"); // 纭繚IV闀垮害涓16瀛楄妭 + + public static string ReadAndDecryptData(string filePath) + { + string fullPath = Path.Combine(Application.streamingAssetsPath, filePath); + if (File.Exists(fullPath) == false) + { + return ""; + } + // 璇诲彇鍔犲瘑鏂囦欢 + byte[] encryptedData = File.ReadAllBytes(fullPath); + + // 鍒涘缓AES瑙e瘑鍣 + using (Aes aesAlg = Aes.Create()) + { + aesAlg.Key = key; + aesAlg.IV = iv; + + ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); + + // 鍒涘缓鍐呭瓨娴佸拰鍔犲瘑娴 + using (MemoryStream msDecrypt = new MemoryStream(encryptedData)) + { + using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) + { + byte[] decryptedBytes = new byte[encryptedData.Length]; + int decryptedByteCount = csDecrypt.Read(decryptedBytes, 0, decryptedBytes.Length); + + // 灏嗚В瀵嗗悗鐨勬暟鎹浆鎹负瀛楃涓 + string decryptedData = Encoding.UTF8.GetString(decryptedBytes, 0, decryptedByteCount); + return decryptedData; + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Tools/ZXKLicenses/Encryption/DecryptFileReader.cs.meta b/Assets/Scripts/Tools/ZXKLicenses/Encryption/DecryptFileReader.cs.meta new file mode 100644 index 00000000..a4452c9b --- /dev/null +++ b/Assets/Scripts/Tools/ZXKLicenses/Encryption/DecryptFileReader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 354bc54210a77764ebad2d49b5e927ba +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tools/ZXKLicenses/Encryption/EncryptFileCreator.cs b/Assets/Scripts/Tools/ZXKLicenses/Encryption/EncryptFileCreator.cs new file mode 100644 index 00000000..e19b7f24 --- /dev/null +++ b/Assets/Scripts/Tools/ZXKLicenses/Encryption/EncryptFileCreator.cs @@ -0,0 +1,56 @@ +using System.IO; +using System.Security.Cryptography; +using System.Text; +using UnityEngine; + +public class EncryptFileCreator +{ + private static byte[] key = Encoding.UTF8.GetBytes("Sixteen byte key"); // 鍔犲瘑瀵嗛挜锛岄渶16瀛楄妭 + private static byte[] iv = Encoding.UTF8.GetBytes("InitializationVe"); // 纭繚IV闀垮害涓16瀛楄妭 + + public static void EncryptAndSaveData(string data,string path) + { + string filePath = Path.Combine(Application.streamingAssetsPath, path); + if (!File.Exists(filePath)) + { + try + { + // 鍒涘缓鏂囦欢 + File.WriteAllText(filePath, ""); + Debug.Log("鏂囦欢宸插垱寤"); + } + catch (IOException e) + { + Debug.LogError($"鍒涘缓鏂囦欢鏃跺嚭閿: {e.Message}"); + } + } + // 灏嗘暟鎹浆鎹负瀛楄妭鏁扮粍 + byte[] plainText = Encoding.UTF8.GetBytes(data); + + // 鍒涘缓AES鍔犲瘑鍣 + using (Aes aesAlg = Aes.Create()) + { + aesAlg.Key = key; + aesAlg.IV = iv; + + ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV); + + // 鍒涘缓鍐呭瓨娴佸拰鍔犲瘑娴 + using (MemoryStream msEncrypt = new MemoryStream()) + { + using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) + { + csEncrypt.Write(plainText, 0, plainText.Length); + csEncrypt.FlushFinalBlock(); + + // 鑾峰彇鍔犲瘑鍚庣殑鏁版嵁 + byte[] encryptedData = msEncrypt.ToArray(); + + // 淇濆瓨鍔犲瘑鏂囦欢鍒癝treamingAssets鏂囦欢澶 + string fullPath = Path.Combine(Application.streamingAssetsPath, filePath); + File.WriteAllBytes(fullPath, encryptedData); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Tools/ZXKLicenses/Encryption/EncryptFileCreator.cs.meta b/Assets/Scripts/Tools/ZXKLicenses/Encryption/EncryptFileCreator.cs.meta new file mode 100644 index 00000000..77d8e4b9 --- /dev/null +++ b/Assets/Scripts/Tools/ZXKLicenses/Encryption/EncryptFileCreator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 22f7660ba2e708d4eb33622fe324499b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tools/ZXKLicenses/HttpRestful.cs b/Assets/Scripts/Tools/ZXKLicenses/HttpRestful.cs new file mode 100644 index 00000000..dd538b34 --- /dev/null +++ b/Assets/Scripts/Tools/ZXKLicenses/HttpRestful.cs @@ -0,0 +1,73 @@ +using QFramework; +using System; +using System.Collections; +using UnityEngine; +using UnityEngine.Networking; + +public class HttpRestful : MonoSingleton +{ + public void Get(string url, Action actionResult = null) + { + StartCoroutine(_Get(url, actionResult)); + } + + private IEnumerator _Get(string url, Action action) + { + using (UnityWebRequest request = UnityWebRequest.Get(url)) + { + yield return request.SendWebRequest(); + + string resstr = ""; + if (request.isNetworkError || request.isHttpError) + { + resstr = request.error; + } + else + { + resstr = request.downloadHandler.text; + } + + if (action != null) + { + action(request.isHttpError, resstr); + } + } + } + public void Post(string url, string form, Action callBack, string Header = null, string HeaderValue = null, int timeOut = 3) + { + + StartCoroutine(_Post(url, form, callBack, Header, HeaderValue, timeOut)); + } + + public IEnumerator _Post(string url, string form, Action callBack, string Header = null, string HeaderValue = null, int timeOut = 3) + { + //璇锋眰閾炬帴锛屽苟灏唂orm瀵硅薄鍙戦佸埌杩滅▼鏈嶅姟鍣 + using (UnityWebRequest webRequest = UnityWebRequest.Post(url, form, "application/json"))//;charset=utf-8 + { + if (!string.IsNullOrEmpty(Header) && !string.IsNullOrEmpty(HeaderValue)) + { + webRequest.SetRequestHeader(Header, HeaderValue); + } + webRequest.timeout = timeOut * 1000; + yield return webRequest.SendWebRequest(); + if (webRequest.result!= UnityWebRequest.Result.Success) + { + Debug.Log(webRequest.error); + callBack?.Invoke(false, webRequest.downloadHandler); + } + else + { + callBack?.Invoke(true, webRequest.downloadHandler); + } + //if (webRequest.isHttpError || webRequest.isNetworkError) + //{ + // //Debug.LogError("==========="); + // callBack?.Invoke(false, null); + //} + //else + //{ + // callBack?.Invoke(true, webRequest.downloadHandler); + //} + }; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Tools/ZXKLicenses/HttpRestful.cs.meta b/Assets/Scripts/Tools/ZXKLicenses/HttpRestful.cs.meta new file mode 100644 index 00000000..2fa9020e --- /dev/null +++ b/Assets/Scripts/Tools/ZXKLicenses/HttpRestful.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cca16177d7a134a43a4fb3320d5b8fc7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tools/ZXKLicenses/Licence.meta b/Assets/Scripts/Tools/ZXKLicenses/Licence.meta new file mode 100644 index 00000000..a4c0b9c7 --- /dev/null +++ b/Assets/Scripts/Tools/ZXKLicenses/Licence.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 32677377141e60248a7a2484825ce1d4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tools/ZXKLicenses/Licence/LicenceData.cs b/Assets/Scripts/Tools/ZXKLicenses/Licence/LicenceData.cs new file mode 100644 index 00000000..d84ee2c5 --- /dev/null +++ b/Assets/Scripts/Tools/ZXKLicenses/Licence/LicenceData.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LicenceData +{ + public string project_id; + public string user_name; + public string license_code; + public string host_id; + public string duration; //浣跨敤鏃堕暱 + public string sign; +} +public class Datas +{ + public static string Project_id = "7"; + public static string secretKey = "pZNwkYoMRp7MG_O7aGtmA"; + public static string UserName; + public static string Licensecode; + public static string Hostid; + public static int Duration;//鎸佺画鏃堕棿 +} +[Serializable] +public class License +{ + public int id; + public string user_name; + public string license_code; + public int is_authorized; + public string host_id; + public string authorization_at; + public string authorization_end_at; + public string created_at; + public int login_count; + public int duration; + public string last_login; +} + +[Serializable] +public class LicenseValidationResponse +{ + public string status; + public string message; + public License license; +} \ No newline at end of file diff --git a/Assets/Scripts/Tools/ZXKLicenses/Licence/LicenceData.cs.meta b/Assets/Scripts/Tools/ZXKLicenses/Licence/LicenceData.cs.meta new file mode 100644 index 00000000..de5c59a7 --- /dev/null +++ b/Assets/Scripts/Tools/ZXKLicenses/Licence/LicenceData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8f40d10c2dcbad941ac179b38fde96bd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tools/ZXKLicenses/Licence/LicenseManager.cs b/Assets/Scripts/Tools/ZXKLicenses/Licence/LicenseManager.cs new file mode 100644 index 00000000..0246d5db --- /dev/null +++ b/Assets/Scripts/Tools/ZXKLicenses/Licence/LicenseManager.cs @@ -0,0 +1,180 @@ +using Newtonsoft.Json; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using System.Security.Cryptography; +using System.Text; +using UnityEngine; + +public class LicenseManager : MonoBehaviour +{ + private Dictionary Data = new(); + private LicenseValidationResponse LicenseRes = new LicenseValidationResponse(); + private string Hostid = ""; + + public void Init() + { + Hostid = GetPhysicalAddress(); + Datas.Hostid = Hostid; + } + public LicenceData GetLicenceData(string projectid, string userName, string licensecode, string hostid, int duration) + { + Data.Clear(); + LicenceData licence = new LicenceData(); + licence.project_id = projectid; + licence.user_name = userName; + licence.license_code = licensecode; + licence.host_id = hostid; + licence.duration = duration.ToString(); + if (!Data.ContainsKey("project_id")) + { + Data.Add("project_id", licence.project_id); + } + if (!Data.ContainsKey("user_name")) + { + Data.Add("user_name", licence.user_name); + } + if (!Data.ContainsKey("license_code")) + { + Data.Add("license_code", licence.license_code); + } + if (!Data.ContainsKey("host_id")) + { + Data.Add("host_id", licence.host_id); + } + if (!Data.ContainsKey("duration")) + { + Data.Add("duration", licence.duration); + } + licence.sign = GenerateSignature(Datas.secretKey, Data); + return licence; + } + /// + /// 璇锋眰 + /// + /// + /// + public void LicensePost(Action callBack = null) + { + LicenceData licence = GetLicenceData(Datas.Project_id, Datas.UserName, Datas.Licensecode, Datas.Hostid, Datas.Duration); + + string json = JsonConvert.SerializeObject(licence); + HttpRestful.Instance.Post("https://locallicense.zxkedu.com/api/license/validate/", json, (m, n) => + { + JsonConvert.DeserializeObject(n.text); + if (LicenseRes.status == "success") + { + EncryptedFile(); + } + callBack.Invoke(m); + }); + } + + /// + /// 鐢熸垚瀵嗗寵 + /// + /// + /// + /// + public string GenerateSignature(string secretKey, Dictionary data) + { + // 娣诲姞褰撳墠鏃堕棿鎴 + //string timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString(); + //鑾峰彇褰撳墠鏃堕棿鎴冲苟鍥涜垗浜斿叆鍒版渶杩戠殑鍒嗛挓 + long timestamp = (long)(DateTimeOffset.UtcNow.ToUnixTimeSeconds() / 60) * 60; + //long timestamp = (long)(GetTimestamp() / 60) * 60; + if (!data.ContainsKey("timestamp")) + { + data.Add("timestamp", timestamp.ToString()); + } + else + { + data["timestamp"] = timestamp.ToString(); + } + // 瀵归敭鍊煎杩涜鎺掑簭 + var sortedData = data.OrderBy(kvp => kvp.Key); + Debug.Log("sortedData瀵归敭鍊煎杩涜鎺掑簭:" + sortedData); + + // 鏋勫缓鏌ヨ瀛楃涓 + string queryString = string.Join("&", sortedData.Select(kvp => $"{kvp.Key}={kvp.Value}")); + Debug.Log("queryString鏋勫缓鏌ヨ瀛楃涓:" + queryString); + // 浣跨敤HMAC-SHA256鐢熸垚绛惧悕 + using (var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secretKey))) + { + byte[] hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(queryString)); + Debug.Log("鐢熸垚绛惧悕:" + BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant()); + return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); + } + } + + public void StartSetDuration() + { + if (gameObject.activeSelf) + { + StartCoroutine(SetDuration(60f)); + } + } + + IEnumerator SetDuration(float times) + { + while (true) + { + yield return new WaitForSeconds(times); + Datas.Duration++; + LicensePost(); + Datas.Duration = 0; + } + } + public string GetMachineGuid() + { + if (string.IsNullOrEmpty(Hostid)) + { + NetworkInterface[] nis = NetworkInterface.GetAllNetworkInterfaces(); + foreach (NetworkInterface ni in nis) + { + if (ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || + ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) + { + Hostid = ni.GetPhysicalAddress().ToString(); + break; + } + } + } + return Hostid; + } + + string GetPhysicalAddress() + { + //string physicalAddress = ""; + //NetworkInterface[] nis = NetworkInterface.GetAllNetworkInterfaces(); + //foreach (NetworkInterface ni in nis) + //{ + // if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet && ni.OperationalStatus == OperationalStatus.Up) + // { + // physicalAddress = ni.GetPhysicalAddress().ToString(); + // break; + // } + //} + return SystemInfo.deviceUniqueIdentifier; + } + + /// + /// 鏈湴瀛樺偍Hostid + /// + public void EncryptedFile() + { + string dataToEncrypt = Datas.UserName + "|" + Datas.Licensecode + "|"; + EncryptFileCreator.EncryptAndSaveData(dataToEncrypt, "encryptedData.txt"); + } + /// + /// 璇诲彇Hostid + /// + /// + public string ReadDecryptedFile() + { + string decryptedData = DecryptFileReader.ReadAndDecryptData("encryptedData.txt"); + return decryptedData; + } +} diff --git a/Assets/Scripts/Tools/ZXKLicenses/Licence/LicenseManager.cs.meta b/Assets/Scripts/Tools/ZXKLicenses/Licence/LicenseManager.cs.meta new file mode 100644 index 00000000..b85899a3 --- /dev/null +++ b/Assets/Scripts/Tools/ZXKLicenses/Licence/LicenseManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 13a2f840c2d90a44b8473ca7cf9adef1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: