_xiaofang/xiaofang/Assets/Script/DirllInterface/querySubjectList.cs

94 lines
3.1 KiB
C#
Raw Normal View History

2024-11-29 17:27:21 +08:00
using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
2024-11-29 20:06:53 +08:00
using System.Threading.Tasks;
2024-11-29 17:27:21 +08:00
using UnityEngine;
public class querySubjectList : MonoBehaviour
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
public Dictionary<string, string> CreateHeaders()
{
2024-12-04 15:26:46 +08:00
if (string.IsNullOrEmpty(MyGlobal.global.loginResponse.data.access_token))
2024-11-29 17:27:21 +08:00
{
Debug.LogWarning("<22><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷʱ<CDB7><CAB1>token δ<><CEB4><EFBFBD>á<EFBFBD>");
return new Dictionary<string, string>();
}
return new Dictionary<string, string>
{
2024-12-04 15:26:46 +08:00
{ "Authorization","Bearer "+MyGlobal.global.loginResponse.data.access_token },
2024-11-29 17:27:21 +08:00
{"clientId", "e5cd7e4891bf95d1d19206ce24a7b32e" }
};
}
//<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>Ϣ<EFBFBD>б<EFBFBD>
2024-11-29 20:06:53 +08:00
public async Task<DrillSubject> QueryDrillSubject()
2024-11-29 17:27:21 +08:00
{
string response = await web.SendRequest(web.URL + "/game/subject/list", "GET", "", CreateHeaders());
Debug.Log("<22><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>Ϣ<EFBFBD>б<EFBFBD>: " + response);
// ʹ<><CAB9> Newtonsoft.Json <20><><EFBFBD>з<EFBFBD><D0B7><EFBFBD><EFBFBD>л<EFBFBD>
DrillSubject drillSubject = JsonConvert.DeserializeObject<DrillSubject>(response);
// <20><><EFBFBD><EFBFBD><E9B7B4><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
if (drillSubject == null)
{
Debug.LogError("Failed to deserialize JSON. DrillSubject is null.");
}
if (drillSubject.data == null || drillSubject.data.Count == 0)
{
Debug.LogWarning("No subjects found in the returned data.");
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD> data <20>б<EFBFBD>
foreach (var subject in drillSubject.data)
{
2024-11-29 20:06:53 +08:00
//Debug.Log("ID: " + subject.id);
//Debug.Log("Scene Names: " + subject.sceneNames);
//Debug.Log("Name: " + subject.name);
//Debug.Log("Suit Version: " + subject.suitVersion);
//Debug.Log("Type: " + subject.type);
//Debug.Log("Description: " + subject.description);
//Debug.Log("Price: " + subject.price);
//Debug.Log("Company ID: " + subject.companyId);
//Debug.Log("Status: " + subject.status);
//Debug.Log("Delete Flag: " + subject.delFlag);
//Debug.Log("Remark: " + subject.remark);
//Debug.Log("Game Name: " + subject.gameName);
//Debug.Log("OSS ID: " + subject.ossId);
//Debug.Log("File List: " + subject.fileList);
2024-11-29 17:27:21 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶΣ<D6B6><CEA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><E7A3AC><EFBFBD>۸<EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD>ּ<EFBFBD><D6BC><EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD>߼<EFBFBD>
}
2024-11-29 20:06:53 +08:00
return drillSubject;
2024-11-29 17:27:21 +08:00
}
}
2024-11-29 20:06:53 +08:00
//=======================================================================================================
public class DrillSubject : Response
{
[JsonProperty("data")]
public List<QueryDrillSubjectData> data; // ȷ<><C8B7><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD> JSON <20>е<EFBFBD>ƥ<EFBFBD><C6A5>
}
public class QueryDrillSubjectData
{
public string id;//
public string[] sceneIds;
public string sceneNames;
public string name;
public string suitVersion;
public string type;
public string description;
public string price;
public string companyId;
public string status;
public string delFlag;
public string remark;
public string gameName;
public string ossId;
public string fileList;
}