_xiaofang/xiaofang/Assets/Script/DirllInterface/bindPlayer.cs
2024-12-04 15:26:46 +08:00

53 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
public class bindPlayer : 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<BindPlayer> BindPlayer(bindPlayerBody bindPlayerBody)
{
//bindPlayerBody bindPlayerBody1 = new bindPlayerBody();
//bindPlayerBody1 = bindPlayerBody;
string response = await web.SendRequest(web.URL + "/game/gameTemplate/player", "POST", JsonConvert.SerializeObject(bindPlayerBody), CreateHeaders());
Debug.Log("模板玩家绑定: " + response);
BindPlayer serverData = JsonConvert.DeserializeObject<BindPlayer>(response);
return serverData;
}
}
//=====请求体====================================================================================
public class bindPlayerBody
{
string templateId;//===============必须
PlayerList[] playerList;//见createTemplate.cs第37行//=========必须
}
//===============================================================================================
public class BindPlayer : Response
{
public string data;
}