web平台接口对接
This commit is contained in:
parent
806bd0d404
commit
b15b1e1fba
8
Assets/WebPlatform/LaiYiTe.meta
Normal file
8
Assets/WebPlatform/LaiYiTe.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f4e4f808ac25d946affe317d1b81545
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/WebPlatform/LaiYiTe/Resrouces.meta
Normal file
8
Assets/WebPlatform/LaiYiTe/Resrouces.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5da36794a84f2e24aa0626b1466f6360
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Assets/WebPlatform/LaiYiTe/Resrouces/RSA.Private
Normal file
10
Assets/WebPlatform/LaiYiTe/Resrouces/RSA.Private
Normal file
@ -0,0 +1,10 @@
|
||||
<RSAKeyValue>
|
||||
<Modulus>vsWZ0Eu/pLeJblZfeAQ7p+KWQHqiJnp9UNwfHLW8Ev2EI9Kg2aPiB/DGmhPab8yCfuQuZIqJSwcCX1XzVvtIOoeeKy53VHOity0oxADtoY+TZSbJraG0+kEwE+S8HZ8u8xAoVg1xcI1a/wnS2CmZSvoqwpOFKufcosyZZeWTyQXhTipLIudmmA+KFWxRjXzcigE/46fA76MzSoH9WUaIq+d8DPJMQwURZcxmMRwIkSmzz6rss10uSdTGqM7VmewDkqeWugIjS0wzSMBKQYgv1rxbMO38hd58J0mygKtjMRdm38MUaPfm2fYCFhqRBuUXnLZ992NHpUNsXesSzlLlyw==</Modulus>
|
||||
<Exponent>AQAB</Exponent>
|
||||
<P>+JTwTuuxi9suxLj+qVfpWwYQ7VIpG5EubZoZrFeHNynysgTbJuSvuujN7rgpT3uejxBbUMjxaOlikECKpTdGs6gyNaA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t1R3kk1Y2NZb3GIrcPUaQ7+75/DlVL05Leabc/eMi/ghhyCqOotHnLw8uNf3kK6QvD/bv3C4Ikdy1ZYBpENz74OMeINWAEXZyARLgs4EryA+6F7Fw3magQ==</D>
|
||||
</RSAKeyValue>
|
||||
7
Assets/WebPlatform/LaiYiTe/Resrouces/RSA.Private.meta
Normal file
7
Assets/WebPlatform/LaiYiTe/Resrouces/RSA.Private.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72fe0ae24cde45946914fa10b54896b0
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/WebPlatform/Plugins.meta
Normal file
8
Assets/WebPlatform/Plugins.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a5ff23952c587c48ab012049e07df51
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/WebPlatform/Plugins/WebGL.meta
Normal file
8
Assets/WebPlatform/Plugins/WebGL.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23a14a5f29ce27c4dab61a5fe698a2e9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib
Normal file
9
Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib
Normal file
@ -0,0 +1,9 @@
|
||||
// 名为 "URLParameters.jslib" 的插件文件
|
||||
mergeInto(LibraryManager.library, {
|
||||
GetURLParameter: function (name) {
|
||||
var search = window.location.search.substring(1);
|
||||
var params = new URLSearchParams(search);
|
||||
var value = params.get(name);
|
||||
return value ? Pointer_stringify(value) : null;
|
||||
}
|
||||
});
|
||||
32
Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib.meta
Normal file
32
Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib.meta
Normal file
@ -0,0 +1,32 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af1b30451ed743d4f81b3f9c8c15baeb
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
WebGL: WebGL
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/WebPlatform/Scripts.meta
Normal file
8
Assets/WebPlatform/Scripts.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8dbba4c57255fc4495c422b41445cbe
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
189
Assets/WebPlatform/Scripts/WebGLHelper.cs
Normal file
189
Assets/WebPlatform/Scripts/WebGLHelper.cs
Normal file
@ -0,0 +1,189 @@
|
||||
using Newtonsoft.Json;
|
||||
using QFramework;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
public class WebGLHelper : Singleton<WebGLHelper>
|
||||
{
|
||||
private WebGLHelper() { }
|
||||
public class LabData
|
||||
{
|
||||
public string GUID;
|
||||
public string ExpID;
|
||||
public string HOST;
|
||||
public string PARA1;
|
||||
public string PARA;
|
||||
public string PARA2;
|
||||
}
|
||||
[DllImport("__Internal")]
|
||||
private static extern string GetURLParameter(string name);
|
||||
|
||||
string token = string.Empty;
|
||||
|
||||
LabData labData = new LabData();
|
||||
[SerializeField]
|
||||
private TextAsset RSA;
|
||||
private const int RsaKeySize = 2048;
|
||||
|
||||
public string uploadUrl;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
token = GetURLParameter("token").Replace("%2B", "+");
|
||||
RSA = Resources.Load<TextAsset>("RSA");
|
||||
string urlData = Decrypt(token);
|
||||
var datas = urlData.Split("&");
|
||||
labData.GUID = datas[0];
|
||||
labData.ExpID = datas[1];
|
||||
labData.HOST = datas[2];
|
||||
labData.PARA1 = datas[3];
|
||||
labData.PARA = datas[4];
|
||||
labData.PARA2 = datas[5];
|
||||
|
||||
uploadUrl = Path.Combine(labData.HOST, "host/public/Exp/AddScore/");
|
||||
}
|
||||
/// <summary>
|
||||
/// Decrypts encrypted text given a RSA private key file path.给定路径的 RSA 私钥文件解
|
||||
|
||||
/// </summary>
|
||||
/// <param name="encryptedText">加密的密文</param>
|
||||
/// <param name="pathToPrivateKey">用于加密的私钥路径.</param>
|
||||
/// <returns>未加密数据的字符串</returns>
|
||||
public string Decrypt(string encryptedText)
|
||||
{
|
||||
using (var rsa = new RSACryptoServiceProvider(RsaKeySize))
|
||||
{
|
||||
try
|
||||
{
|
||||
string privateXmlKey = RSA.text;
|
||||
rsa.FromXmlString(privateXmlKey);
|
||||
Debug.Log("encryptedText " + encryptedText);
|
||||
var bytesEncrypted = Convert.FromBase64String(encryptedText);
|
||||
string b = Encoding.UTF8.GetString(bytesEncrypted);
|
||||
Debug.Log("byte " + b);
|
||||
//var bytesPlainText = rsa.Decrypt(bytesEncrypted, false);
|
||||
var bytesPlainText = rsa.Decrypt(bytesEncrypted, false);
|
||||
Debug.Log("bytesPlainText " + bytesPlainText);
|
||||
return System.Text.Encoding.UTF8.GetString(bytesPlainText);
|
||||
}
|
||||
finally
|
||||
{
|
||||
rsa.PersistKeyInCsp = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void UpLoadData(int totalScore, List<string> stepNames, List<int> maxScore, List<int> score)
|
||||
{
|
||||
var data = new UploadData();
|
||||
data.GUID = labData.GUID;
|
||||
data.ExpID = int.Parse(labData.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];
|
||||
}
|
||||
data.ExpStepVTwoList = list.ToArray();
|
||||
|
||||
|
||||
}
|
||||
|
||||
IEnumerator SendScore(string json, UnityAction<string> action)
|
||||
{
|
||||
if (string.IsNullOrEmpty(uploadUrl))
|
||||
{
|
||||
Debug.LogError("上传接口地址错误:" + uploadUrl);
|
||||
yield break;
|
||||
}
|
||||
|
||||
using (UnityWebRequest request = new UnityWebRequest(uploadUrl, "POST"))
|
||||
{
|
||||
request.SetRequestHeader("Content-Type", "application/json");
|
||||
request.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(json));
|
||||
request.downloadHandler = new DownloadHandlerBuffer();
|
||||
yield return request.SendWebRequest();
|
||||
// 处理响应
|
||||
if (request.result == UnityWebRequest.Result.ConnectionError ||
|
||||
request.result == UnityWebRequest.Result.ProtocolError)
|
||||
{
|
||||
Debug.LogError($"Upload failed: {request.error}");
|
||||
Debug.LogError($"Response Code: {request.responseCode}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Upload complete!");
|
||||
Debug.Log($"Response Code: {request.responseCode}");
|
||||
Debug.Log($"Server Response: {request.downloadHandler.text}");
|
||||
Response response = JsonConvert.DeserializeObject<Response>(request.downloadHandler.text);
|
||||
Debug.LogError(response.msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public class UploadData
|
||||
{
|
||||
public string GUID { get; set; }
|
||||
// 实验 ID
|
||||
public int ExpID { get; set; }
|
||||
// 成绩
|
||||
public int score { get; set; }
|
||||
// 标志位:默认值 true
|
||||
public bool flag { get; set; }
|
||||
// 实验步骤列表
|
||||
public Expstepvtwolist[] ExpStepVTwoList { get; set; }
|
||||
}
|
||||
|
||||
public class Expstepvtwolist
|
||||
{
|
||||
// 实验步骤序号
|
||||
public int seq { get; set; }
|
||||
// 实验步骤名称
|
||||
public string ExpStepName = "";
|
||||
// 实验步骤状态
|
||||
public string StepState = "";
|
||||
// 实验步骤开始时间
|
||||
public DateTime startTime = default;
|
||||
// 实验步骤结束时间
|
||||
public DateTime endTime = default;
|
||||
// 实验步骤合理用时:单位秒
|
||||
public int expectTime = 0;
|
||||
// 实验步骤满分:0 ~100,百分制
|
||||
public int maxScore = 100;
|
||||
// 实验步骤得分:0 ~100,百分制
|
||||
public int score = 0;
|
||||
// 实验步骤操作次数
|
||||
public int repeatCount = 1;
|
||||
// 步骤评价:200 字以内
|
||||
public string evaluation = "";
|
||||
// 赋分模型:200 字以内
|
||||
public string scoringModel = "";
|
||||
// 备注
|
||||
public string remarks { get; set; }
|
||||
}
|
||||
|
||||
public class Response
|
||||
{
|
||||
public string msg;
|
||||
public bool success;
|
||||
}
|
||||
11
Assets/WebPlatform/Scripts/WebGLHelper.cs.meta
Normal file
11
Assets/WebPlatform/Scripts/WebGLHelper.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1b108973e2a6cd43bf6b1943d979a23
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
x
Reference in New Issue
Block a user