_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Announcement/announcementPage31.cs

55 lines
2.1 KiB
C#

using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
//查询公告分页
public class announcementPage31 : MonoBehaviour
{
public async Task<announcementPage> announcementPage(int pageNo,int pageSize)
{
// 准备请求的头部信息,包含授权令牌
Dictionary<string, string> head31 = new Dictionary<string, string>
{
{ "Authorization", Global.global.serverResponse.data.token }
};
RealPlayerInfo realPlayerInfo = new RealPlayerInfo();
queryPlayerInfo queryPlayerInfo = new queryPlayerInfo();
realPlayerInfo = await queryPlayerInfo.QueryPlayerInfoPro();
// 请求体
announcementPageBody announcementPageBody = new announcementPageBody()
{
userId = realPlayerInfo.data.userId,
pageNo = pageNo,
pageSize = pageSize
};
Debug.Log("====入参====" + JsonConvert.SerializeObject(announcementPageBody));
// 异步发送请求
string response31 = await web.SendRequest(web.URL + "/snail/notice/page", "POST", JsonConvert.SerializeObject(announcementPageBody), head31);
// 调试输出接收到的响应
Debug.Log("3.1查询公告分页:=============== " + response31);
// 解析响应的 JSON 数据
announcementPage announcementPage = JsonConvert.DeserializeObject<announcementPage>(response31);
// 遍历公告列表
foreach (var announcement in announcementPage.data.dataList)
{
int id = announcement.id; // 公告ID
string title = announcement.title; // 公告标题
string icon = announcement.icon; // 公告图标URL
string content = announcement.content; // 公告内容
int onShelves = announcement.onShelves; // 是否上架
string createTime = announcement.createTime; // 创建时间
// 你可以在这里使用这些字段进行其他操作,例如展示公告内容
Debug.Log($"公告ID: {id}, 标题: {title}, 图标: {icon}, 内容: {content}, 上架状态: {onShelves}, 创建时间: {createTime}");
}
return announcementPage;
}
}