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 BuyMiningContract(long contractId) // 9.1 { // 准备请求的头部信息,包含授权令牌 Dictionary head = new Dictionary { { "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(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; }