跳转到主要内容

批量查询数据

用于一次性加载多个已保存数据的 API。

URL 确认

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

API 信息

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

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

请求参数

参数类型必填说明
storage_keysstring[]必填要加载的数据键列表

响应数据

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 UnityEngine.Networking;

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

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

[Serializable]
public class Req : DeviceInfo
{
public string[] storage_keys; // 불러올 데이터 키 목록

public IEnumerator Send(string[] storage_keys, Action<Res> onSuccess, Action<BaseResponse> onError)
{
this.storage_keys = storage_keys;

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;
}
}

使用示例

public void LoadMultipleData()
{
StorageMultiLoad.Req req = new StorageMultiLoad.Req();

// 불러올 데이터 키 목록
string[] keys = new string[]
{
"player_level",
"player_gold",
"player_inventory"
};

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

foreach (var item in res.Items)
{
Debug.Log($"플레이어 ID: {item.PlayerId}");
Debug.Log($"{item.StorageKey}: {item.StorageValue}");
}
},
onError: error =>
{
Debug.LogError($"다중 데이터 불러오기 실패: [{error.ErrorCode}] {error.Message}");
}
));
}
高效加载

需要同时加载多个数据时,使用此 API 可以减少网络请求次数,更加高效。

不存在的键

即使请求的键中部分不存在也不会报错,仅返回存在的数据。