web使用莱医特平台接口
This commit is contained in:
parent
00b308544f
commit
04e725d4d5
@ -1,12 +1,9 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using QFramework;
|
using QFramework;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.SocialPlatforms.Impl;
|
|
||||||
using XMLTool;
|
using XMLTool;
|
||||||
|
|
||||||
public class ScoreController : MonoSingleton<ScoreController>
|
public class ScoreController : MonoSingleton<ScoreController>
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
using UnityEngine.Networking;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class DateManager : MonoBehaviour
|
public class DateManager : MonoBehaviour
|
||||||
@ -19,10 +21,14 @@ public class DateManager : MonoBehaviour
|
|||||||
{
|
{
|
||||||
Application.Quit();
|
Application.Quit();
|
||||||
});
|
});
|
||||||
UpdateTime(ShowTip, ShowTip, () =>
|
#if UNITY_WEBGL
|
||||||
|
StartCoroutine(WebUpdateTime());
|
||||||
|
#else
|
||||||
|
UpdateTime(DecryptFileReader.ReadAndDecryptData("Timer.txt"), ShowTip, ShowTip, () =>
|
||||||
{
|
{
|
||||||
gameObject.SetActive(false);
|
gameObject.SetActive(false);
|
||||||
});
|
});
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowTip(string str)
|
public void ShowTip(string str)
|
||||||
@ -32,14 +38,35 @@ public class DateManager : MonoBehaviour
|
|||||||
text.text = str;
|
text.text = str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerator WebUpdateTime()
|
||||||
|
{
|
||||||
|
string path = Path.Combine(Application.streamingAssetsPath, "Timer.txt");
|
||||||
|
using (UnityWebRequest request = new UnityWebRequest(path))
|
||||||
|
{
|
||||||
|
request.downloadHandler = new DownloadHandlerBuffer();
|
||||||
|
yield return request.SendWebRequest();
|
||||||
|
if (string.IsNullOrEmpty(request.error))
|
||||||
|
{
|
||||||
|
string datas = DecryptFileReader.ReadAndDecryptData(request.downloadHandler.data);
|
||||||
|
UpdateTime(datas, ShowTip, ShowTip, () =>
|
||||||
|
{
|
||||||
|
gameObject.SetActive(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogError(request.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新系统时间
|
/// 更新系统时间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void UpdateTime(UnityAction<string> error = null, UnityAction<string> timeOut = null, UnityAction updateTimer = null)
|
public void UpdateTime(string datas, UnityAction<string> error = null, UnityAction<string> timeOut = null, UnityAction updateTimer = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string datas = DecryptFileReader.ReadAndDecryptData("Timer.txt");
|
|
||||||
EndTimer = datas.Split('|')[0];
|
EndTimer = datas.Split('|')[0];
|
||||||
RecordData = datas.Split('|')[1];
|
RecordData = datas.Split('|')[1];
|
||||||
//第一次获取获取系统时间
|
//第一次获取获取系统时间
|
||||||
@ -54,11 +81,13 @@ public class DateManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if !UNITY_WEBGL
|
||||||
//把上一次存储得系统时间更新到最新
|
//把上一次存储得系统时间更新到最新
|
||||||
string timer = "Timer.txt";
|
string timer = "Timer.txt";
|
||||||
RecordData = Data;
|
RecordData = Data;
|
||||||
string strMerge = EndTimer + "|" + RecordData;
|
string strMerge = EndTimer + "|" + RecordData;
|
||||||
EncryptFileCreator.EncryptAndSaveData(strMerge, timer);
|
EncryptFileCreator.EncryptAndSaveData(strMerge, timer);
|
||||||
|
#endif
|
||||||
updateTimer?.Invoke();
|
updateTimer?.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,12 @@ public class DecryptFileReader
|
|||||||
if (File.Exists(filePath)) return "";
|
if (File.Exists(filePath)) return "";
|
||||||
// 读取加密文件
|
// 读取加密文件
|
||||||
byte[] encryptedData = File.ReadAllBytes(fullPath);
|
byte[] encryptedData = File.ReadAllBytes(fullPath);
|
||||||
|
return ReadAndDecryptData(encryptedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static string ReadAndDecryptData(byte[] encryptedData)
|
||||||
|
{
|
||||||
|
|
||||||
// 创建AES解密器
|
// 创建AES解密器
|
||||||
using (Aes aesAlg = Aes.Create())
|
using (Aes aesAlg = Aes.Create())
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using static LYTWebGLHelper;
|
||||||
|
|
||||||
namespace QFramework.Example
|
namespace QFramework.Example
|
||||||
{
|
{
|
||||||
@ -84,9 +86,9 @@ namespace QFramework.Example
|
|||||||
onlyCur = mData.onlyCurModule;
|
onlyCur = mData.onlyCurModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<string> stepNames = new List<string>();
|
|
||||||
List<int> maxScore = new List<int>();
|
List<Expstepvtwolist> datas = new List<Expstepvtwolist>();
|
||||||
List<int> scores = new List<int>();
|
int seq = 0;
|
||||||
if (onlyCur)
|
if (onlyCur)
|
||||||
{
|
{
|
||||||
foreach (var item in ScoreController.Instance.GetCurScoreData())
|
foreach (var item in ScoreController.Instance.GetCurScoreData())
|
||||||
@ -98,9 +100,16 @@ namespace QFramework.Example
|
|||||||
obj.transform.Find("Score").GetComponent<TextMeshProUGUI>().text = item.Value.value.ToString();
|
obj.transform.Find("Score").GetComponent<TextMeshProUGUI>().text = item.Value.value.ToString();
|
||||||
sum += float.Parse(item.Value.sum);
|
sum += float.Parse(item.Value.sum);
|
||||||
score += item.Value.value;
|
score += item.Value.value;
|
||||||
stepNames.Add(item.Value.step + item.Value.name);
|
datas.Add(new Expstepvtwolist()
|
||||||
maxScore.Add(int.Parse(item.Value.sum));
|
{
|
||||||
scores.Add((int)item.Value.value);
|
ExpStepName = item.Value.step + item.Value.name,
|
||||||
|
maxScore = int.Parse(item.Value.sum),
|
||||||
|
score = (int)item.Value.value,
|
||||||
|
startTime = item.Value.time,
|
||||||
|
endTime = item.Value.time,
|
||||||
|
seq = seq,
|
||||||
|
});
|
||||||
|
seq++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -116,9 +125,16 @@ namespace QFramework.Example
|
|||||||
obj.transform.Find("Score").GetComponent<TextMeshProUGUI>().text = item.Value.value.ToString();
|
obj.transform.Find("Score").GetComponent<TextMeshProUGUI>().text = item.Value.value.ToString();
|
||||||
sum += float.Parse(item.Value.sum);
|
sum += float.Parse(item.Value.sum);
|
||||||
score += item.Value.value;
|
score += item.Value.value;
|
||||||
stepNames.Add(item.Value.step + item.Value.name);
|
datas.Add(new Expstepvtwolist()
|
||||||
maxScore.Add((int)float.Parse(item.Value.sum));
|
{
|
||||||
scores.Add((int)item.Value.value);
|
ExpStepName = item.Value.step + item.Value.name,
|
||||||
|
maxScore = int.Parse(item.Value.sum),
|
||||||
|
score = (int)item.Value.value,
|
||||||
|
startTime = item.Value.time,
|
||||||
|
endTime = item.Value.time,
|
||||||
|
seq = seq
|
||||||
|
});
|
||||||
|
seq++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,9 +143,10 @@ namespace QFramework.Example
|
|||||||
this.Score.text = score.ToString();
|
this.Score.text = score.ToString();
|
||||||
this.Sum.text = sum.ToString();
|
this.Sum.text = sum.ToString();
|
||||||
|
|
||||||
//#if UNITY_WEBGL
|
#if UNITY_WEBGL
|
||||||
// LYTWebGLHelper.Instance.UpLoadData((int)score, stepNames, maxScore, scores);
|
|
||||||
//#endif
|
LYTWebGLHelper.Instance.UpLoadData((int)score, datas.ToArray());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnShow()
|
protected override void OnShow()
|
||||||
|
|||||||
1
Assets/StreamingAssets/Timer.txt
Normal file
1
Assets/StreamingAssets/Timer.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
ILBJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>05<EFBFBD>
<0A><>l<EFBFBD><6C>F<03>)<29>#<1E><>BȲ<42><17>Uv<55>}]<5D>u.<2E><>\G<>
|
||||||
7
Assets/StreamingAssets/Timer.txt.meta
Normal file
7
Assets/StreamingAssets/Timer.txt.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9b4029b9b6235264f8d2594721eb300a
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -69,7 +69,7 @@ public class LYTWebGLHelper : MonoSingleton<LYTWebGLHelper>
|
|||||||
labData.PARA = datas[4];
|
labData.PARA = datas[4];
|
||||||
labData.PARA2 = datas[5];
|
labData.PARA2 = datas[5];
|
||||||
}
|
}
|
||||||
uploadUrl = Path.Combine(labData.HOST, "host/public/Exp/AddScore/");
|
uploadUrl = Path.Combine(labData.HOST, "public/Exp/AddScore/");
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Decrypts encrypted text given a RSA private key file path.给定路径的 RSA 私钥文件解
|
/// Decrypts encrypted text given a RSA private key file path.给定路径的 RSA 私钥文件解
|
||||||
@ -104,8 +104,12 @@ public class LYTWebGLHelper : MonoSingleton<LYTWebGLHelper>
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void UpLoadData(int totalScore, List<string> stepNames, List<int> maxScore, List<int> score)
|
public void UpLoadData(int totalScore, Expstepvtwolist[] datas)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(labData.GUID))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
var data = new UploadData();
|
var data = new UploadData();
|
||||||
data.GUID = labData.GUID;
|
data.GUID = labData.GUID;
|
||||||
int expId = 0;
|
int expId = 0;
|
||||||
@ -113,17 +117,17 @@ public class LYTWebGLHelper : MonoSingleton<LYTWebGLHelper>
|
|||||||
data.ExpID = expId;
|
data.ExpID = expId;
|
||||||
data.score = totalScore;
|
data.score = totalScore;
|
||||||
data.flag = true;
|
data.flag = true;
|
||||||
|
//var list = new List<Expstepvtwolist>();
|
||||||
var list = new List<Expstepvtwolist>();
|
//for (int i = 0; i < stepNames.Count; i++)
|
||||||
for (int i = 0; i < stepNames.Count; i++)
|
//{
|
||||||
{
|
// var step = new Expstepvtwolist();
|
||||||
var step = new Expstepvtwolist();
|
// step.ExpStepName = stepNames[i];
|
||||||
step.ExpStepName = stepNames[i];
|
// step.maxScore = maxScore[i];
|
||||||
step.maxScore = maxScore[i];
|
// step.score = score[i];
|
||||||
step.score = score[i];
|
// step.seq = i + 1;
|
||||||
list.Add(step);
|
// list.Add(step);
|
||||||
}
|
//}
|
||||||
data.ExpStepVTwoList = list.ToArray();
|
data.ExpStepVTwoList = datas;
|
||||||
|
|
||||||
StartCoroutine(SendScore(JsonConvert.SerializeObject(data)));
|
StartCoroutine(SendScore(JsonConvert.SerializeObject(data)));
|
||||||
}
|
}
|
||||||
@ -185,9 +189,9 @@ public class LYTWebGLHelper : MonoSingleton<LYTWebGLHelper>
|
|||||||
// 实验步骤状态
|
// 实验步骤状态
|
||||||
public string StepState = "";
|
public string StepState = "";
|
||||||
// 实验步骤开始时间
|
// 实验步骤开始时间
|
||||||
public DateTime startTime = default;
|
public string startTime;
|
||||||
// 实验步骤结束时间
|
// 实验步骤结束时间
|
||||||
public DateTime endTime = default;
|
public string endTime;
|
||||||
// 实验步骤合理用时:单位秒
|
// 实验步骤合理用时:单位秒
|
||||||
public int expectTime = 0;
|
public int expectTime = 0;
|
||||||
// 实验步骤满分:0 ~100,百分制
|
// 实验步骤满分:0 ~100,百分制
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user