_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/kuangChang10/buyMiningContract103.cs
2024-12-05 21:23:44 +08:00

56 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<BuyMiningResponse> 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);
Debug.Log("10.3购买合约的ID" + buyMiningResponse.data);
// 返回解析后的对象
return buyMiningResponse;
}
}
//==========请求体===========================
public class BuyMiningContractBody
{
public long contractId;
public long userId;
}
//==========返回值===========================
public class BuyMiningResponse : Response
{
public long data;
}
public class BuyResponse
{
public long id;
}