_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/kuangChang10/buyMiningContract103.cs
2024-12-05 17:02:12 +08:00

51 lines
1.7 KiB
C#

using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
//10.3,购买合约
public class buyMiningContract103 : MonoBehaviour
{
public async Task<bool> BuyMiningContract(long contractId) // 9.1
{
// 准备请求的头部信息,包含授权令牌
Dictionary<string, string> head = new Dictionary<string, string>
{
{ "Authorization", Global.global.serverResponse.data.token }
};
queryPlayerInfo queryPlayerInfo = new queryPlayerInfo();
RealPlayerInfo realPlayerInfo = await queryPlayerInfo.QueryPlayerInfoPro();
BuyMiningContractBody body = new BuyMiningContractBody();
body.userId = realPlayerInfo.data.userId;
body.contractId = contractId;
Debug.Log(JsonConvert.SerializeObject(body)+"====入参====");
// 异步发送请求以获取最新的蜗牛骑士信息
string response0103 = await web.SendRequest(web.URL + "/snail/mining/buyMiningContract" , "POST", JsonConvert.SerializeObject(body), head);
// 调试输出接收到的响应
Debug.Log("10.3购买合约" + response0103);
// 将响应反序列化为对象
BuyMiningResponse buyMiningResponse = JsonConvert.DeserializeObject<BuyMiningResponse>(response0103);
bool isSucceed;
if (buyMiningResponse.code == 200) { isSucceed = true; } else { isSucceed = false; }
// 返回解析后的对象
return isSucceed;
}
}
//==========请求体===========================
public class BuyMiningContractBody
{
public long contractId;
public long userId;
}
//==========返回值===========================
public class BuyMiningResponse : Response
{
public string data;
}