62 lines
2.1 KiB
C#
62 lines
2.1 KiB
C#
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Threading.Tasks;
|
||
using UnityEngine;
|
||
//5.2.4查询击杀
|
||
public class queryKnightKill524 : MonoBehaviour
|
||
{
|
||
//返回的(解析后)
|
||
public KnightKill knightKill;
|
||
|
||
//async void Start()
|
||
//{
|
||
// KnightKill result = await queryKnightKill(39592); // =============================== 示例,仅供测试
|
||
// if (result != null)
|
||
// {
|
||
// Debug.Log("请求成功,Code: " + result.Code);
|
||
// }
|
||
//}
|
||
|
||
public async Task<KnightKill> queryKnightKill(int KnightId) // 5.2.2//需传入KightId
|
||
{
|
||
// 准备请求的头部信息,包含授权令牌
|
||
Dictionary<string, string> head524 = new Dictionary<string, string>
|
||
{
|
||
{ "Authorization", Global.global.serverResponse.data.token }
|
||
};
|
||
|
||
// 请求体
|
||
QueryKnightRoomListBody queryKnightRoomListBody = new QueryKnightRoomListBody
|
||
{
|
||
userId = Global.global.serverResponse.data.userId,
|
||
knightId = KnightId
|
||
};
|
||
Debug.Log(queryKnightRoomListBody);
|
||
// 异步发送请求
|
||
//string response524 = await web.SendRequest(web.URL + "/snail/gameKnight/queryKill", "POST", JsonUtility.ToJson(queryKnightRoomListBody), head524);
|
||
string response524 = await web.SendRequest(web.URL + "/snail/gameKnight/queryKill", "POST", JsonConvert.SerializeObject(queryKnightRoomListBody), head524);
|
||
|
||
// 调试输出接收到的响应
|
||
Debug.Log("5.2.4查询击杀(骑士):=============== " + response524);
|
||
|
||
// 将响应反序列化为 KnightRoomList 对象
|
||
try
|
||
{
|
||
knightKill = JsonConvert.DeserializeObject<KnightKill>(response524);
|
||
if (knightKill != null && knightKill.data != null)//==================================================访问之前先判空,未到或已过时间,data[]为空
|
||
{
|
||
Debug.Log(knightKill.data.beansCoinFee + "=524========");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Debug.LogError("反序列化响应失败: " + ex.Message);
|
||
}
|
||
|
||
//返回解析后的 KnightKill 对象
|
||
return knightKill;//knightKill;
|
||
}
|
||
}
|