using Newtonsoft.Json; using OpenCVForUnity.UnityUtils; using Org.BouncyCastle.Ocsp; using System; using System.Collections; using System.Collections.Generic; using System.Text; using Unity.VisualScripting; using UnityEngine; using UnityEngine.Networking; using WpfApp1.Util; using System.IO; using System.Linq; using System.Net.NetworkInformation; public class SetJson : MonoBehaviour { public static SetJson instance; public string AesKey = "kGBxaThxMCMGaysp"; public string VersionNumber = "1.0.0"; public string url = "https://www.baidu.com/"; private void Awake() { instance = this; } // Start is called before the first frame update void Start() { // 输出查看url查询数据部分结构 // M.DrowQRCode("https://www.baidu.com/"); } // Update is called once per frame void Update() { } /// /// 从文件NewConfig.ini获取当前电脑物理地址地址 /// public bool ReadPhysicaladdress() { string Physicaladdress = ""; //获取当前程序运行目录 string baseDirectory = AppDomain.CurrentDomain.BaseDirectory + "/MonoBleedingEdge/EmbedRuntime/NewConfig.txt"; if (!File.Exists(baseDirectory)) { Debug.Log(GetMacAddress()); //"C:\\Users\\Administrator\\Desktop\\MyTxt.txt"; FileStream fs = new FileStream(baseDirectory, FileMode.Create); StreamWriter writer = new StreamWriter(fs, Encoding.Default); string str = GetMacAddress(); writer.WriteLine(str); writer.Close(); fs.Close(); return true; } else { bool enter=false; File.ReadAllLines(baseDirectory).ToList().ForEach(a => { if (a == GetMacAddress()) { enter= true; } else { enter= false; } }); return enter; } } private static string GetMacAddress() { string physicalAddress = ""; NetworkInterface[] netAllNetworkinterfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface nf in netAllNetworkinterfaces) { if (nf.Description == "en0") { physicalAddress = nf.GetPhysicalAddress().ToString(); break; } else { physicalAddress = nf.GetPhysicalAddress().ToString(); if (physicalAddress != "") { break; }; } } return physicalAddress; } /// /// 从文件NewConfig.ini获取url地址 /// public string ReadUrl() { string url_=""; File.ReadAllLines(Application.streamingAssetsPath + "/NewConfig.ini").ToList().ForEach(a => { if (!a.StartsWith("#") && !string.IsNullOrEmpty(a)) { string[] tmp = a.Split('='); Debug.Log(tmp); if (tmp[0].Trim() == "url") { url_ = tmp[1].Trim(); Debug.Log(url_); } } }); return url_; } /// /// 加密 /// /// 验证码 /// 日期 /// 版本号 /// 密钥 /// public string AssemblyField(string VerificationCode,string Data,string VersionNumber,string AesKey) { PortList br = new PortList { VerificationCode = VerificationCode , Data = Data , VersionNumber = VersionNumber }; Debug.Log(JsonConvert.SerializeObject(br)); Debug.Log(AESHelper.AesEncrypt(JsonConvert.SerializeObject(br), AesKey)); return "?param1=" + AESHelper.AesEncrypt(JsonConvert.SerializeObject(br), AesKey); } /* /// /// 解密 /// /// 验证码 /// 日期 /// 版本号 /// 密钥 /// public string AssemblyField(string VerificationCode,string Data,string VersionNumber,string AesKey) { PortList br = new PortList { VerificationCode = VerificationCode, Data = Data, VersionNumber = VersionNumber }; return "?param1=" + AESHelper.AesEncrypt(JsonConvert.SerializeObject(br), AesKey); } */ /// /// 生成验证码 /// /// 验证码 /// public string GenerateVerificationCode() { System.Random random = new System.Random(); string chars = "0123456789ABCDEFGHIJKLM0123456789NOPQRSTUVWXYZ0123456789abcdefghijklm0123456789nopqrstuvwxyz0123456789"; char[] stringChars = new char[6]; for (int i = 0; i < stringChars.Length; i++) { stringChars[i] = chars[random.Next(chars.Length)]; } string finalString = new String(stringChars); return finalString; } } #region JSON [System.Serializable] public class PortList { /// /// 验证码 /// [Tooltip("验证码")] public string VerificationCode; /// /// 日期 /// [Tooltip("日期")] public string Data; /// /// 版本号 /// [Tooltip("版本号")] public string VersionNumber; } #endregion