|
@@ -12,11 +12,11 @@ public class Login : MonoBehaviour
|
|
|
{
|
|
{
|
|
|
public string id;
|
|
public string id;
|
|
|
public string key;
|
|
public string key;
|
|
|
- private string token;
|
|
|
|
|
private static long Jan1st1970Ms = new DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc).Ticks;
|
|
private static long Jan1st1970Ms = new DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc).Ticks;
|
|
|
void Start()
|
|
void Start()
|
|
|
{
|
|
{
|
|
|
- StartCoroutine(GetList());
|
|
|
|
|
|
|
+ StartCoroutine(GetList());
|
|
|
|
|
+ //GetToken();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
// Update is called once per frame
|
|
@@ -28,22 +28,26 @@ public class Login : MonoBehaviour
|
|
|
{
|
|
{
|
|
|
WWWForm form = new WWWForm();
|
|
WWWForm form = new WWWForm();
|
|
|
form.AddField("terminal-token", GetToken());
|
|
form.AddField("terminal-token", GetToken());
|
|
|
- //form.AddField("terminal-token", "eyJjbGllbnRJZCI6Imdkc3NsdzEwMiIsImV4cGlyZXNUaW1lIjoxNzE3Mzk3NTU1NTU0fQ%3D%3D.RaJJEIFJ7y8tliZaarqOncrtCnjMy1yjUZtMKGaFELc%3D");
|
|
|
|
|
form.AddField("phoneNumber", "15512719554");
|
|
form.AddField("phoneNumber", "15512719554");
|
|
|
UnityWebRequest unityWebRequest = UnityWebRequest.Post("http://gdsyzxlwxx.dds-ai.cn/jxpc-server/third-api/vr/api/get-train-state", form);
|
|
UnityWebRequest unityWebRequest = UnityWebRequest.Post("http://gdsyzxlwxx.dds-ai.cn/jxpc-server/third-api/vr/api/get-train-state", form);
|
|
|
yield return unityWebRequest.SendWebRequest();
|
|
yield return unityWebRequest.SendWebRequest();
|
|
|
|
|
+
|
|
|
Debug.Log(unityWebRequest.downloadHandler.text);
|
|
Debug.Log(unityWebRequest.downloadHandler.text);
|
|
|
}
|
|
}
|
|
|
private string GetToken()
|
|
private string GetToken()
|
|
|
{
|
|
{
|
|
|
Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
|
|
Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
|
|
|
keyValuePairs.Add("clientId", id);
|
|
keyValuePairs.Add("clientId", id);
|
|
|
- //keyValuePairs.Add("expiresTime", (DateTime.UtcNow.Ticks - Jan1st1970Ms) / 10000 + 20000);
|
|
|
|
|
- keyValuePairs.Add("expiresTime", 12345);
|
|
|
|
|
|
|
+ keyValuePairs.Add("expiresTime", (DateTime.UtcNow.Ticks - Jan1st1970Ms) / 10000 + 100000);
|
|
|
|
|
+ //keyValuePairs.Add("expiresTime", 12345);
|
|
|
|
|
+ Debug.Log(keyValuePairs["expiresTime"]);
|
|
|
string jsonString = JsonConvert.SerializeObject(keyValuePairs);
|
|
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);
|
|
|
|
|
|
|
+ string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(jsonString));
|
|
|
|
|
+ string token= System.Web.HttpUtility.UrlEncode(base64 + "." + ComputeHmacSha256(base64, key));
|
|
|
|
|
+ Debug.Log(token);
|
|
|
|
|
+ token = Regex.Replace(token, "%3d", "%3D");
|
|
|
|
|
+ Debug.Log(token);
|
|
|
|
|
+ return token;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -54,7 +58,6 @@ public class Login : MonoBehaviour
|
|
|
using (var hmac = new HMACSHA256(keyBytes))
|
|
using (var hmac = new HMACSHA256(keyBytes))
|
|
|
{
|
|
{
|
|
|
var hash = hmac.ComputeHash(messageBytes);
|
|
var hash = hmac.ComputeHash(messageBytes);
|
|
|
- Debug.Log(hash.ToString());
|
|
|
|
|
return Convert.ToBase64String(hash);
|
|
return Convert.ToBase64String(hash);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|