209 lines
5.6 KiB
C#
209 lines
5.6 KiB
C#
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()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 从文件NewConfig.ini获取当前电脑物理地址地址
|
|
/// </summary>
|
|
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;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 从文件NewConfig.ini获取url地址
|
|
/// </summary>
|
|
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_;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 加密
|
|
/// </summary>
|
|
/// <param name="VerificationCode">验证码</param>
|
|
/// <param name="Data">日期</param>
|
|
/// <param name="VersionNumber">版本号</param>
|
|
/// <param name="AesKey">密钥</param>
|
|
/// <returns></returns>
|
|
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);
|
|
}
|
|
|
|
/*
|
|
/// <summary>
|
|
/// 解密
|
|
/// </summary>
|
|
/// <param name="VerificationCode">验证码</param>
|
|
/// <param name="Data">日期</param>
|
|
/// <param name="VersionNumber">版本号</param>
|
|
/// <param name="AesKey">密钥</param>
|
|
/// <returns></returns>
|
|
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);
|
|
}
|
|
*/
|
|
|
|
/// <summary>
|
|
/// 生成验证码
|
|
/// </summary>
|
|
/// <param name="VerificationCode">验证码</param>
|
|
/// <returns></returns>
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// 验证码
|
|
/// </summary>
|
|
[Tooltip("验证码")] public string VerificationCode;
|
|
/// <summary>
|
|
/// 日期
|
|
/// </summary>
|
|
[Tooltip("日期")] public string Data;
|
|
/// <summary>
|
|
/// 版本号
|
|
/// </summary>
|
|
[Tooltip("版本号")] public string VersionNumber;
|
|
}
|
|
#endregion |