数据查询
用于查询远程配置值的 API。
URL 确认
此 API 使用 service-api.playnanoo.com 域名。
API 信息
- URL:
https://service-api.playnanoo.com/storage/v20211101/load/public - Method:
PUT - 需要认证: 是
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| storage_key | string | 必填 | 远程配置键(RemoteConfig_{tableCode} 格式) |
DeviceInfo 继承
此 API 的 Req 类继承自 DeviceInfo。DeviceInfo 的所有属性会自动包含。
响应数据
Res 类
| 字段 | 类型 | 说明 |
|---|---|---|
| StorageKey | string | 存储键 |
| StorageValue | string | 存储值 |
| remote_config_variables | List\<RemoteConfigVariable> | 远程配置变量列表 |
RemoteConfigVariable 结构
| 字段 | 类型 | 说明 |
|---|---|---|
| remote_config_variable_type | string | 变量类型 |
| remote_config_variable_key | string | 变量键 |
| remote_config_variable_description | string | 变量说明 |
| remote_config_variable_value | string | 变量值 |
| remote_config_variable_createdAt | long | 创建时间 |
Unity C# 实现
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Networking;
public class RemoteConfig
{
static string url = "https://service-api.playnanoo.com/storage/v20211101/load/public";
[Serializable]
public class Req : DeviceInfo
{
public string storage_key;
public IEnumerator Send(
string tableCode,
Action<Res> onSuccess,
Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(tableCode)) this.storage_key = $"RemoteConfig_{tableCode}";
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
url,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}
[Serializable]
public class Res : BaseResponse
{
public string StorageKey;
public string StorageValue;
public List<RemoteConfigVariable> remote_config_variables;
}
[Serializable]
public class RemoteConfigVariable
{
public string remote_config_variable_type;
public string remote_config_variable_key;
public string remote_config_variable_description;
public string remote_config_variable_value;
public long remote_config_variable_createdAt;
}
}
使用示例
public void LoadRemoteConfig()
{
string tableCode = "Remote Config Table Code";
RemoteConfig.Req req = new RemoteConfig.Req();
StartCoroutine(req.Send(
tableCode: tableCode,
onSuccess: res =>
{
// Newtonsoft.Json을 사용하면 추가 파싱을 하지 않아도 됩니다.
var data = JsonUtility.FromJson<RemoteConfig.Res>(res.StorageValue);
foreach (var v in data.remote_config_variables)
{
Debug.Log($"Type : [{v.remote_config_variable_type}]");
Debug.Log($"Key : [{v.remote_config_variable_key}]");
Debug.Log($"Description : [{v.remote_config_variable_description}]");
Debug.Log($"Value : [{v.remote_config_variable_value}]");
Debug.Log($"CreateAt : [{v.remote_config_variable_createdAt}]");
}
},
onError: (error) =>
{
Debug.LogError($"RemoteConfig 실패: [{error.ErrorCode}] {error.Message}");
}
));
}