跳转到主要内容

货币初始化

初始化玩家货币的 API。

URL 确认

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

API 信息

  • URL: https://service-api.playnanoo.com/currency/v20240301/init
  • Method: PUT
  • 需要认证: 是
DeviceInfo 继承

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

请求参数

此 API 没有额外的请求参数。

响应数据

Res 类

字段类型说明
itemsList<ItemModel>初始化后的货币列表

ItemModel 类

字段类型说明
currency_codestring货币代码
currency_amountdouble持有货币数量

Unity C# 实现

BaseResponse 类

所有 API 响应的基类。

public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}

字段说明:

  • ErrorCode: 错误代码
  • Message: 错误消息
  • WithdrawalKey: 处于注销等待状态时用于恢复的密钥 (仅在注销等待中的账户提供)
  • BlockKey: 账户被封禁时提供的密钥 (仅在被封禁的账户提供)

ItemModel 类

[Serializable]
public class ItemModel
{
public string currency_code;

public double currency_amount;
}

货币初始化类

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Networking;

public class CurrencyInit
{
static string path = "https://service-api.playnanoo.com/currency/v20240301/init";

[Serializable]
public class Req : DeviceInfo
{
public IEnumerator Send(Action<Res> onSuccess, Action<BaseResponse> onError)
{
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}

[Serializable]
public class Res : BaseResponse
{
public List<ItemModel> items = new List<ItemModel>();
}

[Serializable]
public class ItemModel
{
public string currency_code;

public double currency_amount;
}
}

使用示例

public void InitCurrency()
{
CurrencyInit.Req req = new CurrencyInit.Req();

StartCoroutine(req.Send(
onSuccess: res =>
{
Debug.Log("재화 초기화 성공");

foreach (var item in res.items)
{
Debug.Log($"재화 코드: {item.currency_code}");
Debug.Log($"보유 수량: {item.currency_amount}");
}
},
onError: error =>
{
Debug.LogError($"재화 초기화 실패: [{error.ErrorCode}] {error.Message}");
}
));
}
货币初始化注意

此 API 将初始化玩家的所有货币。请谨慎使用。