web使用莱医特平台接口
This commit is contained in:
parent
00b308544f
commit
04e725d4d5
@ -1,12 +1,9 @@
|
||||
using Newtonsoft.Json;
|
||||
using QFramework;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SocialPlatforms.Impl;
|
||||
using XMLTool;
|
||||
|
||||
public class ScoreController : MonoSingleton<ScoreController>
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class DateManager : MonoBehaviour
|
||||
@ -19,10 +21,14 @@ public class DateManager : MonoBehaviour
|
||||
{
|
||||
Application.Quit();
|
||||
});
|
||||
UpdateTime(ShowTip, ShowTip, () =>
|
||||
#if UNITY_WEBGL
|
||||
StartCoroutine(WebUpdateTime());
|
||||
#else
|
||||
UpdateTime(DecryptFileReader.ReadAndDecryptData("Timer.txt"), ShowTip, ShowTip, () =>
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
public void ShowTip(string str)
|
||||
@ -32,14 +38,35 @@ public class DateManager : MonoBehaviour
|
||||
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>
|
||||
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
|
||||
{
|
||||
string datas = DecryptFileReader.ReadAndDecryptData("Timer.txt");
|
||||
EndTimer = datas.Split('|')[0];
|
||||
RecordData = datas.Split('|')[1];
|
||||
//第一次获取获取系统时间
|
||||
@ -54,11 +81,13 @@ public class DateManager : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !UNITY_WEBGL
|
||||
//把上一次存储得系统时间更新到最新
|
||||
string timer = "Timer.txt";
|
||||
RecordData = Data;
|
||||
string strMerge = EndTimer + "|" + RecordData;
|
||||
EncryptFileCreator.EncryptAndSaveData(strMerge, timer);
|
||||
#endif
|
||||
updateTimer?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,6 +14,12 @@ public class DecryptFileReader
|
||||
if (File.Exists(filePath)) return "";
|
||||
// 读取加密文件
|
||||
byte[] encryptedData = File.ReadAllBytes(fullPath);
|
||||
return ReadAndDecryptData(encryptedData);
|
||||
}
|
||||
|
||||
|
||||
public static string ReadAndDecryptData(byte[] encryptedData)
|
||||
{
|
||||
|
||||
// 创建AES解密器
|
||||
using (Aes aesAlg = Aes.Create())
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using static LYTWebGLHelper;
|
||||
|
||||
namespace QFramework.Example
|
||||
{
|
||||
@ -84,9 +86,9 @@ namespace QFramework.Example
|
||||
onlyCur = mData.onlyCurModule;
|
||||
}
|
||||
|
||||
List<string> stepNames = new List<string>();
|
||||
List<int> maxScore = new List<int>();
|
||||
List<int> scores = new List<int>();
|
||||
|
||||
List<Expstepvtwolist> datas = new List<Expstepvtwolist>();
|
||||
int seq = 0;
|
||||
if (onlyCur)
|
||||
{
|
||||
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();
|
||||
sum += float.Parse(item.Value.sum);
|
||||
score += item.Value.value;
|
||||
stepNames.Add(item.Value.step + item.Value.name);
|
||||
maxScore.Add(int.Parse(item.Value.sum));
|
||||
scores.Add((int)item.Value.value);
|
||||
datas.Add(new Expstepvtwolist()
|
||||
{
|
||||
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
|
||||
@ -116,9 +125,16 @@ namespace QFramework.Example
|
||||
obj.transform.Find("Score").GetComponent<TextMeshProUGUI>().text = item.Value.value.ToString();
|
||||
sum += float.Parse(item.Value.sum);
|
||||
score += item.Value.value;
|
||||
stepNames.Add(item.Value.step + item.Value.name);
|
||||
maxScore.Add((int)float.Parse(item.Value.sum));
|
||||
scores.Add((int)item.Value.value);
|
||||
datas.Add(new Expstepvtwolist()
|
||||
{
|
||||
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.Sum.text = sum.ToString();
|
||||
|
||||
//#if UNITY_WEBGL
|
||||
// LYTWebGLHelper.Instance.UpLoadData((int)score, stepNames, maxScore, scores);
|
||||
//#endif
|
||||
#if UNITY_WEBGL
|
||||
|
||||
LYTWebGLHelper.Instance.UpLoadData((int)score, datas.ToArray());
|
||||
#endif
|
||||
}
|
||||
|
||||
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.PARA2 = datas[5];
|
||||
}
|
||||
uploadUrl = Path.Combine(labData.HOST, "host/public/Exp/AddScore/");
|
||||
uploadUrl = Path.Combine(labData.HOST, "public/Exp/AddScore/");
|
||||
}
|
||||
/// <summary>
|
||||
/// 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();
|
||||
data.GUID = labData.GUID;
|
||||
int expId = 0;
|
||||
@ -113,17 +117,17 @@ public class LYTWebGLHelper : MonoSingleton<LYTWebGLHelper>
|
||||
data.ExpID = expId;
|
||||
data.score = totalScore;
|
||||
data.flag = true;
|
||||
|
||||
var list = new List<Expstepvtwolist>();
|
||||
for (int i = 0; i < stepNames.Count; i++)
|
||||
{
|
||||
var step = new Expstepvtwolist();
|
||||
step.ExpStepName = stepNames[i];
|
||||
step.maxScore = maxScore[i];
|
||||
step.score = score[i];
|
||||
list.Add(step);
|
||||
}
|
||||
data.ExpStepVTwoList = list.ToArray();
|
||||
//var list = new List<Expstepvtwolist>();
|
||||
//for (int i = 0; i < stepNames.Count; i++)
|
||||
//{
|
||||
// var step = new Expstepvtwolist();
|
||||
// step.ExpStepName = stepNames[i];
|
||||
// step.maxScore = maxScore[i];
|
||||
// step.score = score[i];
|
||||
// step.seq = i + 1;
|
||||
// list.Add(step);
|
||||
//}
|
||||
data.ExpStepVTwoList = datas;
|
||||
|
||||
StartCoroutine(SendScore(JsonConvert.SerializeObject(data)));
|
||||
}
|
||||
@ -185,9 +189,9 @@ public class LYTWebGLHelper : MonoSingleton<LYTWebGLHelper>
|
||||
// 实验步骤状态
|
||||
public string StepState = "";
|
||||
// 实验步骤开始时间
|
||||
public DateTime startTime = default;
|
||||
public string startTime;
|
||||
// 实验步骤结束时间
|
||||
public DateTime endTime = default;
|
||||
public string endTime;
|
||||
// 实验步骤合理用时:单位秒
|
||||
public int expectTime = 0;
|
||||
// 实验步骤满分:0 ~100,百分制
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user