diff --git a/Assets/WebPlatform/LaiYiTe/LYTWebGLHelper.cs b/Assets/WebPlatform/LaiYiTe/LYTWebGLHelper.cs index 3f82b5fd..1607d79a 100644 --- a/Assets/WebPlatform/LaiYiTe/LYTWebGLHelper.cs +++ b/Assets/WebPlatform/LaiYiTe/LYTWebGLHelper.cs @@ -25,7 +25,7 @@ public class LYTWebGLHelper : MonoSingleton } #if UNITY_WEBGL [DllImport("__Internal")] - private static extern string GetURLParameter(string name); + private static extern IntPtr GetURLParameter(string name); #endif string token = string.Empty; @@ -42,9 +42,21 @@ public class LYTWebGLHelper : MonoSingleton } public void Init() { -#if UNITY_WEBGL&&!UNITY_EDITOR - token = GetURLParameter("token").Replace("%2B", "+"); +#if UNITY_WEBGL && !UNITY_EDITOR + + var paramPtr = GetURLParameter("token"); + if (paramPtr != IntPtr.Zero) + { + string value = Marshal.PtrToStringUTF8(paramPtr); + //token = value.Replace("%2B", "+"); + token = value.Replace(" ", "+"); + Marshal.FreeHGlobal(paramPtr); // 释放分配的内存 + } + Debug.LogError("获取的:" + token); #endif + + + RSA = Resources.Load("LYTWebGL/RSA"); if (string.IsNullOrEmpty(token) == false) { @@ -109,6 +121,7 @@ public class LYTWebGLHelper : MonoSingleton step.ExpStepName = stepNames[i]; step.maxScore = maxScore[i]; step.score = score[i]; + list.Add(step); } data.ExpStepVTwoList = list.ToArray(); @@ -122,7 +135,7 @@ public class LYTWebGLHelper : MonoSingleton Debug.LogError("上传接口地址错误:" + uploadUrl); yield break; } - + Debug.LogError("上传的数据:" + json); using (UnityWebRequest request = new UnityWebRequest(uploadUrl, "POST")) { request.SetRequestHeader("Content-Type", "application/json"); diff --git a/Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib b/Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib index a460273f..5a076284 100644 --- a/Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib +++ b/Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib @@ -1,9 +1,17 @@ -// 鍚嶄负 "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; + const paramName = UTF8ToString(name); + const search = window.location.search.substring(1); + const params = new URLSearchParams(search); + const value = params.get(paramName); + console.log('GetURLParameter:', value); + + if (value) { + var buffer = _malloc((value.length + 1) * 2); + stringToUTF8(value, buffer, (value.length + 1) * 2); + return buffer; + } else { + return 0; + } } }); \ No newline at end of file