ZXP 1 год назад
Родитель
Сommit
35ceb4f97a
4 измененных файлов с 80 добавлено и 3 удалено
  1. 16 0
      Assets/Scenes/Main.unity
  2. 56 3
      Assets/Scripts/Login.cs
  3. 1 0
      Packages/manifest.json
  4. 7 0
      Packages/packages-lock.json

+ 16 - 0
Assets/Scenes/Main.unity

@@ -3063,6 +3063,8 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 0bb5e4d934d798343a34c26749cec382, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
+  id: 
+  key: 
 --- !u!222 &1437060350621267016
 CanvasRenderer:
   m_ObjectHideFlags: 0
@@ -3666,6 +3668,18 @@ PrefabInstance:
       propertyPath: m_Padding.m_Bottom
       value: 0
       objectReference: {fileID: 0}
+    - target: {fileID: 5256516899290289149, guid: 2980ccc56dc596f498fa8bbd3b808cd9, type: 3}
+      propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.size
+      value: 1
+      objectReference: {fileID: 0}
+    - target: {fileID: 5256516899290289149, guid: 2980ccc56dc596f498fa8bbd3b808cd9, type: 3}
+      propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Target
+      value: 
+      objectReference: {fileID: 5374442942383228809}
+    - target: {fileID: 5256516899290289149, guid: 2980ccc56dc596f498fa8bbd3b808cd9, type: 3}
+      propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
+      value: SetActive
+      objectReference: {fileID: 0}
     - target: {fileID: 5477182567403614777, guid: 2980ccc56dc596f498fa8bbd3b808cd9, type: 3}
       propertyPath: m_audioClip
       value: 
@@ -7549,6 +7563,8 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 0bb5e4d934d798343a34c26749cec382, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
+  id: gdsslw102
+  key: gdsslw102
 --- !u!222 &7492295443749115791
 CanvasRenderer:
   m_ObjectHideFlags: 0

+ 56 - 3
Assets/Scripts/Login.cs

@@ -1,18 +1,71 @@
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+using Newtonsoft.Json;
+using System;
+using System.Text.RegularExpressions;
+using System.Security.Cryptography;
+using System.Text;
+using UnityEngine.Networking;
 
 public class Login : MonoBehaviour
 {
-    // Start is called before the first frame update
+    public string id;
+    public string key;
+    private string token;
+    private static long Jan1st1970Ms = new DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc).Ticks;
     void Start()
     {
-        
+        StartCoroutine(GetList());
     }
 
     // Update is called once per frame
     void Update()
     {
-        
+
+    }
+    public IEnumerator GetList()
+    {
+        WWWForm form = new WWWForm();
+        form.AddField("terminal-token", GetToken());
+        //form.AddField("terminal-token", "eyJjbGllbnRJZCI6Imdkc3NsdzEwMiIsImV4cGlyZXNUaW1lIjoxNzE3Mzk3NTU1NTU0fQ%3D%3D.RaJJEIFJ7y8tliZaarqOncrtCnjMy1yjUZtMKGaFELc%3D");
+        form.AddField("phoneNumber", "15512719554");
+        UnityWebRequest unityWebRequest = UnityWebRequest.Post("http://gdsyzxlwxx.dds-ai.cn/jxpc-server/third-api/vr/api/get-train-state", form);
+        yield return unityWebRequest.SendWebRequest();
+        Debug.Log(unityWebRequest.downloadHandler.text);
+    }
+    private string GetToken()
+    {
+        Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
+        keyValuePairs.Add("clientId", id);
+        //keyValuePairs.Add("expiresTime", (DateTime.UtcNow.Ticks - Jan1st1970Ms) / 10000 + 20000);
+        keyValuePairs.Add("expiresTime", 12345);
+        string jsonString = JsonConvert.SerializeObject(keyValuePairs);
+        string base64 = Regex.Replace(Convert.ToBase64String(Encoding.UTF8.GetBytes(jsonString)), "=", "%3D");
+        Debug.Log(base64 + "." + ComputeHmacSha256(base64, key));
+        return base64 + "." + ComputeHmacSha256(base64, key);
+
     }
+
+    private string ComputeHmacSha256(string message, string secret)
+    {
+        var keyBytes = Encoding.UTF8.GetBytes(secret);
+        var messageBytes = Encoding.UTF8.GetBytes(message);
+        using (var hmac = new HMACSHA256(keyBytes))
+        {
+            var hash = hmac.ComputeHash(messageBytes);
+            Debug.Log(hash.ToString());
+            return Convert.ToBase64String(hash);
+        }
+    }
+
+
+
+
+
+
+
+
+
+
 }

+ 1 - 0
Packages/manifest.json

@@ -4,6 +4,7 @@
     "com.unity.ide.rider": "3.0.21",
     "com.unity.ide.visualstudio": "2.0.18",
     "com.unity.ide.vscode": "1.2.5",
+    "com.unity.nuget.newtonsoft-json": "3.2.1",
     "com.unity.test-framework": "1.1.33",
     "com.unity.textmeshpro": "3.0.6",
     "com.unity.timeline": "1.4.8",

+ 7 - 0
Packages/packages-lock.json

@@ -55,6 +55,13 @@
       "dependencies": {},
       "url": "https://packages.unity.cn"
     },
+    "com.unity.nuget.newtonsoft-json": {
+      "version": "3.2.1",
+      "depth": 0,
+      "source": "registry",
+      "dependencies": {},
+      "url": "https://packages.unity.cn"
+    },
     "com.unity.subsystemregistration": {
       "version": "1.0.6",
       "depth": 2,

粤ICP备19079148号