_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/snailFactory/queryFactory.cs
2024-12-01 23:17:54 +08:00

103 lines
3.7 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
//9.1查询工会分页列表
public class queryFactory : MonoBehaviour
{
public async Task<FactoryList> QueryFactoryList() // 9.1
{
// 准备请求的头部信息,包含授权令牌
Dictionary<string, string> head91 = new Dictionary<string, string>
{
{ "Authorization", Global.global.serverResponse.data.token }
};
queryPlayerInfo queryPlayerInfo = new queryPlayerInfo();
RealPlayerInfo realPlayerInfo = new RealPlayerInfo();
realPlayerInfo = await queryPlayerInfo.QueryPlayerInfoPro();
queryFactoryBody queryFactoryBody = new queryFactoryBody();
queryFactoryBody.userId = realPlayerInfo.data.userId;
Debug.Log("===入参====" + JsonUtility.ToJson(queryFactoryBody));
// 异步发送请求以获取最新的蜗牛骑士信息
string response91 = await web.SendRequest(web.URL + "/snail/factory/queryFactorySlot", "POST", JsonUtility.ToJson(queryFactoryBody), head91);
// 调试输出接收到的响应
Debug.Log("9.1查询工厂列表" + response91);
// 将响应反序列化为对象
FactoryList factoryList = JsonConvert.DeserializeObject<FactoryList>(response91);
// 访问并使用返回的数据
if (factoryList.code == 200 && factoryList.data != null)
{
// 访问第一页的数据列表
foreach (var factoryItem in factoryList.data.dataList)
{
Debug.Log($"工厂ID: {factoryItem.id}, 用户ID: {factoryItem.userId}, 状态: {factoryItem.status}, 使用类型: {factoryItem.useType}");
}
}
else
{
Debug.LogError("请求失败或没有数据");
}
// 返回解析后的对象
return factoryList;
}
}
//请求体===================================================================
//bodyuserIdLong用户的userId必传
//              pageNoInteger默认1非必传起始页
//              pageSizeInteger默认20非必传每页数目
public class queryFactoryBody
{
public long userId;
public int pageNo;
public int pageSize;
}
//======================================================
public class FactoryList:Response
{
public FactoryData data { get; set; }
}
public class FactoryData
{
public int pageNo { get; set; }
public int pageSize { get; set; }
public int totalCount { get; set; }
public List<FactoryItem> dataList { get; set; }
}
public class FactoryItem
{
public long id { get; set; }
public long userId { get; set; }
public long snailId { get; set; }
public long contractId { get; set; }
public string bindTime { get; set; }
public int source { get; set; }
public int useType { get; set; }
public int status { get; set; }
public int settle { get; set; }
}
//返回参数code200成功
//        message成功提示语
//        data用户信息
//             pageNo起始页
//             pageSize每页展示
//             totalCount总记录数
//             dataList列表
//                 idLong卡槽id
//                 userIdLong用户id
//                 snailIdLong蜗牛id
//                 contractIdLong合同id
//                 bindTimeString绑定到期时间
//                 statusInteger1绑定中其他未绑定
//                 settleInteger绑定中的进度取100-settle*2.5