随机用户搜索
随机搜索其他用户。
URL 确认
此 API 使用 service-api.playnanoo.com 域名。
API 信息
- URL:
https://service-api.playnanoo.com/friend/v20231201/searchRandom - Method:
PUT - 需要认证: 是
DeviceInfo 继承
此 API 的 Req 类继承自 DeviceInfo。DeviceInfo 的所有属性将自动包含。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| table_code | string | 必填 | 好友表代码 |
| limit | int | 必填 | 要搜索的用户数 |
响应数据
Res 类
| 字段 | 类型 | 说明 |
|---|---|---|
| Items | List<ItemModel> | 随机用户列表 |
ItemModel 类
| 字段 | 类型 | 说明 |
|---|---|---|
| OpenId | string | Open ID |
| UserId | string | 用户 ID |
| Nickname | string | 昵称 |
| AccessSeconds | int | 最后访问时间 (秒) |
| InDate | string | 注册日期 |
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 FriendRandomSearch
{
static string path = "https://service-api.playnanoo.com/friend/v20231201/searchRandom";
[Serializable]
public class Req : DeviceInfo
{
public string table_code;
public int limit;
public IEnumerator Send(string tableCode, int limit, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(tableCode)) this.table_code = tableCode;
this.limit = limit;
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}
[Serializable]
public class Res : BaseResponse
{
public List<ItemModel> Items = new List<ItemModel>();
}
[Serializable]
public class ItemModel
{
public string OpenId;
public string UserId;
public string Nickname;
public int AccessSeconds;
public string InDate;
}
}
使用示例
using PlayNANOO;
public class PlayNANOOExample : MonoBehaviour
{
void SearchRandomUsers()
{
FriendRandomSearch.Req req = new FriendRandomSearch.Req();
StartCoroutine(req.Send(
tableCode: "friend_table",
limit: 10,
onSuccess: res =>
{
Debug.Log($"랜덤 사용자 {res.Items.Count}명 검색됨");
foreach (var user in res.Items)
{
Debug.Log($"사용자: {user.Nickname} (ID: {user.UserId})");
Debug.Log($" OpenId: {user.OpenId}");
Debug.Log($" 가입일: {user.InDate}");
}
},
onError: (error) =>
{
Debug.LogError($"랜덤 사용자 검색 실패: [{error.ErrorCode}] [{error.Message}]");
}
));
}
}
好友推荐
可以利用此 API 实现"推荐好友"功能。可以向搜索到的用户发送好友请求。