跳转到主要内容

批量查询玩家数据

用于一次性加载其他玩家的多个公开数据的 API。

URL 确认

此 API 使用 service-storage-api.playnanoo.com 域名。

API 信息

  • URL: https://service-storage-api.playnanoo.com/storage/v20221001/playerDataLoad/multi
  • Method: PUT
  • 需要认证: 是
DeviceInfo 继承

此 API 的 Req 类继承自 DeviceInfo。DeviceInfo 的所有属性会自动包含。

请求参数

参数类型必填说明
storage_keysstring必填要查询的数据列表(JSON 字符串)

storage_keys JSON 结构(MultiLoadParam)

字段类型必填说明
ItemsMultiLoadParamValue[]必填要查询的数据列表

MultiLoadParamValue 结构

字段类型必填说明
PlayerIdstring必填要查询的玩家 ID
StorageKeystring必填要加载的数据键

响应数据

Res 类

字段类型说明
ItemsStorageItem[]已加载的数据列表

StorageItem 结构

字段类型说明
PlayerIdstring玩家 ID
StorageKeystring数据键
StorageValuestring数据值

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;

[Serializable]
public class MultiLoadParam
{
public List<MultiLoadParamValue> Items = new List<MultiLoadParamValue>();
}

[Serializable]
public class MultiLoadParamValue
{
public string PlayerId;
public string StorageKey;
}

public class StorageMultiPlayerDataLoad
{
static string path = "https://service-storage-api.playnanoo.com/storage/v20221001/playerDataLoad/multi";

[Serializable]
public class Req : DeviceInfo
{
public string storage_keys;

public IEnumerator Send(
MultiLoadParam storageKeys,
Action<Res> onSuccess,
Action<BaseResponse> onError)
{
if (storageKeys != null) this.storage_keys = JsonUtility.ToJson(storageKeys);

yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}

[Serializable]
public class Res : BaseResponse
{
public StorageItem[] Items;
}

[Serializable]
public class StorageItem
{
public string PlayerId;
public string StorageKey;
public string StorageValue;
}
}

使用示例

public void LoadOtherPlayerMultipleData()
{
StorageMultiPlayerDataLoad.Req req = new StorageMultiPlayerDataLoad.Req();

// 조회할 플레이어와 데이터 목록 생성
MultiLoadParam storageKeys = new MultiLoadParam();
storageKeys.Items.Add(new MultiLoadParamValue { PlayerId = "PLAYER_ID_1", StorageKey = "public_profile" });
storageKeys.Items.Add(new MultiLoadParamValue { PlayerId = "PLAYER_ID_2", StorageKey = "achievement_list" });
storageKeys.Items.Add(new MultiLoadParamValue { PlayerId = "PLAYER_ID_1", StorageKey = "ranking_info" });

StartCoroutine(req.Send(
storageKeys: storageKeys,
onSuccess: res =>
{
Debug.Log("다른 플레이어 다중 데이터 불러오기 성공");

foreach (var item in res.Items)
{
Debug.Log($"플레이어 ID: {item.PlayerId}");
Debug.Log($"{item.StorageKey}: {item.StorageValue}");

// 각 데이터 처리
switch (item.StorageKey)
{
case "public_profile":
var profile = JsonUtility.FromJson<PublicProfile>(item.StorageValue);
Debug.Log($"플레이어 이름: {profile.name}");
break;
case "achievement_list":
// 업적 처리
break;
}
}
},
onError: error =>
{
Debug.LogError($"데이터 불러오기 실패: [{error.ErrorCode}] {error.Message}");
}
));
}

[Serializable]
public class PublicProfile
{
public string name;
public int level;
public string avatar;
}
高效查询

查询其他玩家的多个公开数据时,使用此 API 可以减少网络请求次数。

安全注意

此 API 查询的是其他玩家的数据,因此只应存储即使公开也无妨的数据。请绝不要存储敏感个人信息。

排名和好友系统

此 API 适用于在排名系统或好友列表中高效获取多个玩家信息。