查询好友信息
查询好友关系数和待处理的好友请求数。
URL 确认
此 API 使用 service-api.playnanoo.com 域名。
API 信息
- URL:
https://service-api.playnanoo.com/friend/v20231201/info - Method:
PUT - 需要认证: 是
DeviceInfo 继承
此 API 的 Req 类继承自 DeviceInfo。DeviceInfo 的所有属性将自动包含。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| table_code | string | 必填 | 好友表代码 |
响应数据
Res 类
| 字段 | 类型 | 说明 |
|---|---|---|
| RelationshipCount | int | 当前好友数 |
| PendingCount | int | 待处理的好友请求数 |
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 UnityEngine.Networking;
public class FriendInfo
{
static string path = "https://service-api.playnanoo.com/friend/v20231201/info";
[Serializable]
public class Req : DeviceInfo
{
public string table_code;
public IEnumerator Send(string tableCode, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(tableCode)) this.table_code = tableCode;
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}
[Serializable]
public class Res : BaseResponse
{
public int RelationshipCount;
public int PendingCount;
}
}
使用示例
using PlayNANOO;
public class PlayNANOOExample : MonoBehaviour
{
void GetFriendInfo()
{
FriendInfo.Req req = new FriendInfo.Req();
StartCoroutine(req.Send(
tableCode: "friend_table",
onSuccess: res =>
{
Debug.Log($"현재 친구 수: {res.RelationshipCount}");
Debug.Log($"대기 중인 친구 요청: {res.PendingCount}");
// UI 업데이트
UpdateFriendUI(res.RelationshipCount, res.PendingCount);
},
onError: (error) =>
{
Debug.LogError($"친구 정보 조회 실패: [{error.ErrorCode}] [{error.Message}]");
}
));
}
void UpdateFriendUI(int friendCount, int pendingCount)
{
// UI 업데이트 로직
}
}
通知显示
可以利用 PendingCount 在有待处理的好友请求时显示通知徽章。