好友请求
向其他用户发送好友请求。
URL 确认
此 API 使用 service-api.playnanoo.com 域名。
API 信息
- URL:
https://service-api.playnanoo.com/friend/v20231201/request - Method:
PUT - 需要认证: 是
DeviceInfo 继承
此 API 的 Req 类继承自 DeviceInfo。DeviceInfo 的所有属性将自动包含。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| table_code | string | 必填 | 好友表代码 |
| open_id | string | 必填 | 要发送好友请求的用户的 Open ID |
响应数据
Res 类
| 字段 | 类型 | 说明 |
|---|---|---|
| Status | 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 UnityEngine.Networking;
public class FriendRequest
{
static string path = "https://service-api.playnanoo.com/friend/v20231201/request";
[Serializable]
public class Req : DeviceInfo
{
public string table_code;
public string open_id;
public IEnumerator Send(string tableCode, string openId, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(tableCode)) this.table_code = tableCode;
if (!string.IsNullOrEmpty(openId)) this.open_id = openId;
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}
[Serializable]
public class Res : BaseResponse
{
public string Status;
}
}
使用示例
using PlayNANOO;
public class PlayNANOOExample : MonoBehaviour
{
void SendFriendRequest(string targetOpenId)
{
FriendRequest.Req req = new FriendRequest.Req();
StartCoroutine(req.Send(
tableCode: "friend_table",
openId: targetOpenId,
onSuccess: res =>
{
Debug.Log($"친구 요청 전송 성공: {res.Status}");
ShowMessage("친구 요청을 보냈습니다.");
},
onError: (error) =>
{
Debug.LogError($"친구 요청 전송 실패: [{error.ErrorCode}] [{error.Message}]");
ShowMessage("친구 요청 전송에 실패했습니다.");
}
));
}
void ShowMessage(string message)
{
// UI 메시지 표시
Debug.Log(message);
}
}
OpenID
OpenID 可以通过随机用户搜索 API 获取。
重复请求
如果已经是好友或有待处理的请求,可能会发生错误。