50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
using Newtonsoft.Json;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Threading.Tasks;
|
||
using UnityEngine;
|
||
|
||
public class bindMaterial : MonoBehaviour
|
||
{
|
||
|
||
// 创建请求头,使用最新的 token
|
||
public Dictionary<string, string> CreateHeaders()
|
||
{
|
||
if (string.IsNullOrEmpty(MyGlobal.global.loginResponse.data.access_token))
|
||
{
|
||
Debug.LogWarning("尝试创建请求头时,token 未设置。");
|
||
return new Dictionary<string, string>();
|
||
}
|
||
|
||
return new Dictionary<string, string>
|
||
{
|
||
{ "Authorization","Bearer "+MyGlobal.global.loginResponse.data.access_token },
|
||
{"clientId", "e5cd7e4891bf95d1d19206ce24a7b32e" }
|
||
};
|
||
}
|
||
//模板设备绑定
|
||
public async Task<BindMaterial> BindMaterial(BindMaterialBody _bindMaterialBody)
|
||
{
|
||
|
||
string response = await web.SendRequest(web.URL + "/game/gameTemplate/material", "POST", JsonConvert.SerializeObject(_bindMaterialBody), CreateHeaders());
|
||
Debug.Log("模板设备绑定: " + response);
|
||
BindMaterial serverData = JsonConvert.DeserializeObject<BindMaterial>(response);
|
||
if (serverData.data == null)
|
||
{
|
||
Debug.Log("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
|
||
}
|
||
Debug.Log(serverData.data);
|
||
return serverData;
|
||
}
|
||
}
|
||
//=====请求体===============================================
|
||
public class BindMaterialBody
|
||
{
|
||
public string templateId;
|
||
MaterialList[] materialList;
|
||
}
|
||
//=====返回===============================================
|
||
public class BindMaterial : Response
|
||
{
|
||
public string data;//++++++++++++++++++++++++++++++++++++
|
||
} |