104 lines
2.8 KiB
C#
104 lines
2.8 KiB
C#
using Best.HTTP;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Text;
|
|
using UnityEngine;
|
|
|
|
public class HTTP : MonoBehaviour
|
|
{
|
|
[Serializable]
|
|
public class ItemManagementData
|
|
{
|
|
public string status;
|
|
public string code;
|
|
public string message;
|
|
public ItemDatum data;
|
|
public string remark;
|
|
}
|
|
[Serializable]
|
|
public class ItemDatum
|
|
{
|
|
public string count;
|
|
public ItemData[] rows;
|
|
}
|
|
[Serializable]
|
|
public class ItemData
|
|
{
|
|
public string id;
|
|
public string modelId;
|
|
public string createUserId;
|
|
public string lastUpdateUserId;
|
|
public string itemCode;
|
|
public string itemName;
|
|
public string spec;
|
|
public string unit;
|
|
public string timestamp;
|
|
public string createdAt;
|
|
public string updatedAt;
|
|
public Model Model;
|
|
}
|
|
[Serializable]
|
|
public class Model
|
|
{
|
|
public string id;
|
|
public string previewFileld;
|
|
public string fileName;
|
|
public PrevieFile PreviewFile;
|
|
}
|
|
[Serializable]
|
|
public class PrevieFile
|
|
{
|
|
public string id;
|
|
public string title;
|
|
public string path;
|
|
public string type;
|
|
public string size;
|
|
public string createdAt;
|
|
}
|
|
|
|
private string httpServer = "https://samkwang-hub.flexing.ai/server/api/item-management/item";
|
|
private string api = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJzeXN0ZW0iLCJncm91cElkIjoxLCJncm91cENvZGUiOiIiLCJuYW1lIjoi7Iuc7Iqk7YWcIOq0gOumrOyekCIsInBob25lIjoiMDEwLTExMTEtMTExMSIsImlhdCI6MTc2MzA4MTA4NiwiZXhwIjoxODI2MTk2Mjg2LCJpc3MiOiJodWIifQ.BXZ9tghs9zjh-2zfqk3BOOjUZ2wLLNpGfDFTaD0SkFg";
|
|
|
|
public ItemManagementData itemManagementData;
|
|
public Action<ItemDatum> onItemDatum;
|
|
|
|
public void Start()
|
|
{
|
|
HTTPConnect();
|
|
}
|
|
public void HTTPConnect()
|
|
{
|
|
var path = httpServer;
|
|
|
|
var request = HTTPRequest.CreateGet(path, RequestFinishedCallback);
|
|
request.AddHeader("access-token", api);
|
|
|
|
request.Send();
|
|
}
|
|
private void RequestFinishedCallback(HTTPRequest req, HTTPResponse resp)
|
|
{
|
|
switch (req.State)
|
|
{
|
|
case HTTPRequestStates.Finished:
|
|
if (resp.IsSuccess)
|
|
{
|
|
var payload = Encoding.UTF8.GetString(resp.Data);
|
|
var response = JsonConvert.DeserializeObject<ItemManagementData>(payload);
|
|
itemManagementData = response;
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Error");
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
public void SetSendItemDatum()
|
|
{
|
|
onItemDatum?.Invoke(itemManagementData.data);
|
|
}
|
|
}
|