|
|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|