_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/SnailKnight52/SnailKnightBet523.cs
2024-11-28 04:40:30 +08:00

69 lines
1.9 KiB
C#

using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
//5.2.3下注
public class SnailKnightBet523 : Base
{
//返回的(解析后)====================
//public KnightRoomBetList knightRoomBetList;
//async void Start()
//{
// await SnailKnightBet(39592, 1, 3); // =============================== 示例,仅供测试
//}
public async Task<bool> SnailKnightBet(int KnightId,float bet,int horseNo)
{
// 准备请求的头部信息,包含授权令牌
Dictionary<string, string> head523 = new Dictionary<string, string>
{
{ "Authorization", Global.global.serverResponse.data.token }
};
// 请求体
KnightBetBody knightBetBody = new KnightBetBody
{
userId = Global.global.serverResponse.data.userId,
knightId = KnightId,
bet = bet,
horseNo = horseNo
};
// 异步发送请求
string response523 = await web.SendRequest(web.URL + "/snail/gameKnight/userBet", "POST", JsonConvert.SerializeObject(knightBetBody), head523);
// 调试输出接收到的响应
Debug.Log("入参"+ JsonConvert.SerializeObject(knightBetBody) + "5.2.3下注: " + response523);
KnightBetResponse knightResponse = new KnightBetResponse();
// 将响应反序列化为对象
try
{
knightResponse = JsonConvert.DeserializeObject<KnightBetResponse>(response523);
}
catch (Exception ex)
{
Debug.LogError("反序列化响应失败: " + ex.Message);
}
bool isSucceed;
if (knightResponse.code == 200)
{
isSucceed = true;
addEventPopUp(knightResponse.message);
}
else
{
isSucceed = false;
addEventPopUp(knightResponse.message);
}
// 返回解析后的 KnightRoomBetList 对象
return isSucceed;
}
}