跳转到主要内容

数据查询

用于查询远程配置值的 API。

URL 确认

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

API 信息

  • URL: https://service-api.playnanoo.com/storage/v20211101/load/public
  • Method: PUT
  • 需要认证: 是

请求参数

参数类型必填说明
storage_keystring必填远程配置键(RemoteConfig_{tableCode} 格式)
DeviceInfo 继承

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

响应数据

Res 类

字段类型说明
StorageKeystring存储键
StorageValuestring存储值
remote_config_variablesList\<RemoteConfigVariable>远程配置变量列表

RemoteConfigVariable 结构

字段类型说明
remote_config_variable_typestring变量类型
remote_config_variable_keystring变量键
remote_config_variable_descriptionstring变量说明
remote_config_variable_valuestring变量值
remote_config_variable_createdAtlong创建时间

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