diff --git a/Assets/WebPlatform/LaiYiTe.meta b/Assets/WebPlatform/LaiYiTe.meta new file mode 100644 index 00000000..46d8f71e --- /dev/null +++ b/Assets/WebPlatform/LaiYiTe.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8f4e4f808ac25d946affe317d1b81545 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/WebPlatform/LaiYiTe/Resrouces.meta b/Assets/WebPlatform/LaiYiTe/Resrouces.meta new file mode 100644 index 00000000..9d6744c3 --- /dev/null +++ b/Assets/WebPlatform/LaiYiTe/Resrouces.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5da36794a84f2e24aa0626b1466f6360 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/WebPlatform/LaiYiTe/Resrouces/RSA.Private b/Assets/WebPlatform/LaiYiTe/Resrouces/RSA.Private new file mode 100644 index 00000000..3ead6dd1 --- /dev/null +++ b/Assets/WebPlatform/LaiYiTe/Resrouces/RSA.Private @@ -0,0 +1,10 @@ + + vsWZ0Eu/pLeJblZfeAQ7p+KWQHqiJnp9UNwfHLW8Ev2EI9Kg2aPiB/DGmhPab8yCfuQuZIqJSwcCX1XzVvtIOoeeKy53VHOity0oxADtoY+TZSbJraG0+kEwE+S8HZ8u8xAoVg1xcI1a/wnS2CmZSvoqwpOFKufcosyZZeWTyQXhTipLIudmmA+KFWxRjXzcigE/46fA76MzSoH9WUaIq+d8DPJMQwURZcxmMRwIkSmzz6rss10uSdTGqM7VmewDkqeWugIjS0wzSMBKQYgv1rxbMO38hd58J0mygKtjMRdm38MUaPfm2fYCFhqRBuUXnLZ992NHpUNsXesSzlLlyw== + AQAB +

+JTwTuuxi9suxLj+qVfpWwYQ7VIpG5EubZoZrFeHNynysgTbJuSvuujN7rgpT3uejxBbUMjxaOlikECKpTdGs6gyNaAKce6SA+4xobbWmFUS4uE7RBbI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ZyARLgs4EryA+6F7Fw3magQ== +
\ No newline at end of file diff --git a/Assets/WebPlatform/LaiYiTe/Resrouces/RSA.Private.meta b/Assets/WebPlatform/LaiYiTe/Resrouces/RSA.Private.meta new file mode 100644 index 00000000..288425aa --- /dev/null +++ b/Assets/WebPlatform/LaiYiTe/Resrouces/RSA.Private.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 72fe0ae24cde45946914fa10b54896b0 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/WebPlatform/Plugins.meta b/Assets/WebPlatform/Plugins.meta new file mode 100644 index 00000000..83ed0eb0 --- /dev/null +++ b/Assets/WebPlatform/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4a5ff23952c587c48ab012049e07df51 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/WebPlatform/Plugins/WebGL.meta b/Assets/WebPlatform/Plugins/WebGL.meta new file mode 100644 index 00000000..3a9a3ea3 --- /dev/null +++ b/Assets/WebPlatform/Plugins/WebGL.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 23a14a5f29ce27c4dab61a5fe698a2e9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib b/Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib new file mode 100644 index 00000000..a460273f --- /dev/null +++ b/Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib @@ -0,0 +1,9 @@ +// 名为 "URLParameters.jslib" 的插件文件 +mergeInto(LibraryManager.library, { + GetURLParameter: function (name) { + var search = window.location.search.substring(1); + var params = new URLSearchParams(search); + var value = params.get(name); + return value ? Pointer_stringify(value) : null; + } +}); \ No newline at end of file diff --git a/Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib.meta b/Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib.meta new file mode 100644 index 00000000..8e6335ec --- /dev/null +++ b/Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib.meta @@ -0,0 +1,32 @@ +fileFormatVersion: 2 +guid: af1b30451ed743d4f81b3f9c8c15baeb +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + WebGL: WebGL + second: + enabled: 1 + settings: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/WebPlatform/Scripts.meta b/Assets/WebPlatform/Scripts.meta new file mode 100644 index 00000000..978d3f73 --- /dev/null +++ b/Assets/WebPlatform/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b8dbba4c57255fc4495c422b41445cbe +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/WebPlatform/Scripts/WebGLHelper.cs b/Assets/WebPlatform/Scripts/WebGLHelper.cs new file mode 100644 index 00000000..ad0d032f --- /dev/null +++ b/Assets/WebPlatform/Scripts/WebGLHelper.cs @@ -0,0 +1,189 @@ +using Newtonsoft.Json; +using QFramework; +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices; +using System.Security.Cryptography; +using System.Text; +using UnityEngine; +using UnityEngine.Events; +using UnityEngine.Networking; + +public class WebGLHelper : Singleton +{ + private WebGLHelper() { } + public class LabData + { + public string GUID; + public string ExpID; + public string HOST; + public string PARA1; + public string PARA; + public string PARA2; + } + [DllImport("__Internal")] + private static extern string GetURLParameter(string name); + + string token = string.Empty; + + LabData labData = new LabData(); + [SerializeField] + private TextAsset RSA; + private const int RsaKeySize = 2048; + + public string uploadUrl; + + public void Init() + { + token = GetURLParameter("token").Replace("%2B", "+"); + RSA = Resources.Load("RSA"); + string urlData = Decrypt(token); + var datas = urlData.Split("&"); + labData.GUID = datas[0]; + labData.ExpID = datas[1]; + labData.HOST = datas[2]; + labData.PARA1 = datas[3]; + labData.PARA = datas[4]; + labData.PARA2 = datas[5]; + + uploadUrl = Path.Combine(labData.HOST, "host/public/Exp/AddScore/"); + } + /// + /// Decrypts encrypted text given a RSA private key file path.· RSA ˽Կļ + + /// + /// ܵ + /// ڼܵ˽Կ·. + /// δݵַ + public string Decrypt(string encryptedText) + { + using (var rsa = new RSACryptoServiceProvider(RsaKeySize)) + { + try + { + string privateXmlKey = RSA.text; + rsa.FromXmlString(privateXmlKey); + Debug.Log("encryptedText " + encryptedText); + var bytesEncrypted = Convert.FromBase64String(encryptedText); + string b = Encoding.UTF8.GetString(bytesEncrypted); + Debug.Log("byte " + b); + //var bytesPlainText = rsa.Decrypt(bytesEncrypted, false); + var bytesPlainText = rsa.Decrypt(bytesEncrypted, false); + Debug.Log("bytesPlainText " + bytesPlainText); + return System.Text.Encoding.UTF8.GetString(bytesPlainText); + } + finally + { + rsa.PersistKeyInCsp = false; + } + } + } + + + + public void UpLoadData(int totalScore, List stepNames, List maxScore, List score) + { + var data = new UploadData(); + data.GUID = labData.GUID; + data.ExpID = int.Parse(labData.ExpID); + data.score = totalScore; + data.flag = true; + + var list = new List(); + for (int i = 0; i < stepNames.Count; i++) + { + var step = new Expstepvtwolist(); + step.ExpStepName = stepNames[i]; + step.maxScore = maxScore[i]; + step.score = score[i]; + } + data.ExpStepVTwoList = list.ToArray(); + + + } + + IEnumerator SendScore(string json, UnityAction action) + { + if (string.IsNullOrEmpty(uploadUrl)) + { + Debug.LogError("ϴӿڵַ:" + uploadUrl); + yield break; + } + + using (UnityWebRequest request = new UnityWebRequest(uploadUrl, "POST")) + { + request.SetRequestHeader("Content-Type", "application/json"); + request.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(json)); + request.downloadHandler = new DownloadHandlerBuffer(); + yield return request.SendWebRequest(); + // Ӧ + if (request.result == UnityWebRequest.Result.ConnectionError || + request.result == UnityWebRequest.Result.ProtocolError) + { + Debug.LogError($"Upload failed: {request.error}"); + Debug.LogError($"Response Code: {request.responseCode}"); + } + else + { + Debug.Log("Upload complete!"); + Debug.Log($"Response Code: {request.responseCode}"); + Debug.Log($"Server Response: {request.downloadHandler.text}"); + Response response = JsonConvert.DeserializeObject(request.downloadHandler.text); + Debug.LogError(response.msg); + } + } + + } +} + + + + +public class UploadData +{ + public string GUID { get; set; } + // ʵ ID + public int ExpID { get; set; } + // ɼ + public int score { get; set; } + // ־λĬֵ true + public bool flag { get; set; } + // ʵ鲽б + public Expstepvtwolist[] ExpStepVTwoList { get; set; } +} + +public class Expstepvtwolist +{ + // ʵ鲽 + public int seq { get; set; } + // ʵ鲽 + public string ExpStepName = ""; + // ʵ鲽״̬ + public string StepState = ""; + // ʵ鲽迪ʼʱ + public DateTime startTime = default; + // ʵ鲽ʱ + public DateTime endTime = default; + // ʵ鲽ʱλ + public int expectTime = 0; + // ʵ鲽֣0 ~100ٷ + public int maxScore = 100; + // ʵ鲽÷֣0 ~100ٷ + public int score = 0; + // ʵ鲽 + public int repeatCount = 1; + // ۣ200 + public string evaluation = ""; + // ģͣ200 + public string scoringModel = ""; + // ע + public string remarks { get; set; } +} + +public class Response +{ + public string msg; + public bool success; +} \ No newline at end of file diff --git a/Assets/WebPlatform/Scripts/WebGLHelper.cs.meta b/Assets/WebPlatform/Scripts/WebGLHelper.cs.meta new file mode 100644 index 00000000..a2f6aa5c --- /dev/null +++ b/Assets/WebPlatform/Scripts/WebGLHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c1b108973e2a6cd43bf6b1943d979a23 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: