排名查询
用于查询排行榜特定范围排名的 API。
URL 确认
此 API 使用 service-api.playnanoo.com 域名。
API 信息
- URL:
https://service-api.playnanoo.com/leaderboard/v20240301/range - Method:
PUT - 需要认证: 是
DeviceInfo 继承
此 API 的 Req 类继承自 DeviceInfo。DeviceInfo 的所有属性会自动包含。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| uid | string | 必填 | 表代码 |
| range_start | int | 必填 | 起始排名(从 1 开始) |
| range_end | int | 必填 | 结束排名 |
响应数据
Res 类
| 字段 | 类型 | 说明 |
|---|---|---|
| Items | List<RangeItemModel> | 排名列表 |
RangeItemModel 类
| 字段 | 类型 | 说明 |
|---|---|---|
| Rank | int | 排名 |
| RotationCount | int | 赛季编号 |
| RecordId | string | 记录 ID |
| Score | int | 分数 |
| ExtraData | string | 附加数据(JSON 字符串) |
Unity C# 实现
BaseResponse 类
所有 API 响应的基类。
public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}
字段说明:
ErrorCode:错误代码Message:错误信息WithdrawalKey:账号处于注销等待状态时,用于恢复的密钥(仅注销等待中的账号提供)BlockKey:账号被封禁时提供的密钥(仅被封禁的账号提供)
排名查询类
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Networking;
public class Range
{
static string path = "https://service-api.playnanoo.com/leaderboard/v20240301/range";
[Serializable]
public class Req : DeviceInfo
{
public string uid;
public int range_start;
public int range_end;
public IEnumerator Send(string table_code, int rangeStart, int rangeEnd, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(table_code)) this.uid = table_code;
this.range_start = rangeStart;
this.range_end = rangeEnd;
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}
[Serializable]
public class Res : BaseResponse
{
public List<RangeItemModel> Items;
}
[Serializable]
public class RangeItemModel
{
public int Rank;
public int RotationCount;
public string RecordId;
public int Score;
public string ExtraData;
}
}
使用示例
public void GetLeaderboardRange()
{
Range.Req req = new Range.Req();
StartCoroutine(req.Send(
table_code: "my_leaderboard_table",
rangeStart: 1, // 1위부터
rangeEnd: 10, // 10위까지
onSuccess: res =>
{
Debug.Log("순위 조회 성공");
Debug.Log($"조회된 기록 수: {res.Items.Count}");
foreach (var item in res.Items)
{
Debug.Log($"순위: {item.Rank}");
Debug.Log($"플레이어 ID: {item.RecordId}");
Debug.Log($"점수: {item.Score}");
Debug.Log($"시즌: {item.RotationCount}");
if (!string.IsNullOrEmpty(item.ExtraData))
{
Debug.Log($"추가 데이터: {item.ExtraData}");
}
}
},
onError: error =>
{
Debug.LogError($"순위 조회 실패: [{error.ErrorCode}] {error.Message}");
}
));
}
排名范围
可以使用 range_start 和 range_end 指定所需的排名范围。例如,要查询前 10 名,请设置 range_start=1,range_end=10。
高效查询
一次查询过多排名可能会影响性能。建议仅查询所需的范围。