货币发放
向玩家发放货币的 API。
URL 确认
此 API 使用 service-api.playnanoo.com 域名。
API 信息
- URL:
https://service-api.playnanoo.com/currency/v20221101/currency/put - Method:
PUT - 需要认证: 是
DeviceInfo 继承
此 API 的 Req 类继承自 DeviceInfo。DeviceInfo 的所有属性将自动包含。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| items | string | 必填 | 货币列表 (JSON 字符串) |
响应数据
Res 类
| 字段 | 类型 | 说明 |
|---|---|---|
| items | List<ItemModel> | 发放后货币列表 |
ItemModel 类
| 字段 | 类型 | 说明 |
|---|---|---|
| currency_code | string | 货币代码 |
| currency_amount | double | 持有货币数量 |
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;
}
ItemsWrapper 类
[Serializable]
public class ItemsWrapper
{
public List<ItemModel> items;
}
货币发放类
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class CurrencyPut
{
static string path = "https://service-api.playnanoo.com/currency/v20221101/currency/put";
[Serializable]
public class Req : DeviceInfo
{
public string items;
public IEnumerator Send(List<ItemModel> itemsList, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if(itemsList != null && itemsList.Count > 0)
{
ItemsWrapper wrapper = new ItemsWrapper { items = itemsList };
this.items = JsonUtility.ToJson(wrapper);
}
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;
}
[Serializable]
public class ItemsWrapper
{
public List<ItemModel> items;
}
[Serializable]
public class ItemModel
{
public string currency_code;
public double currency_amount;
}
}
使用示例
public void PutCurrency()
{
CurrencyPut.Req req = new CurrencyPut.Req();
// 지급할 재화 목록 생성
List<CurrencyPut.ItemModel> itemList = new List<CurrencyPut.ItemModel>
{
new CurrencyPut.ItemModel { currency_code = "GOLD", currency_amount = 1000 },
new CurrencyPut.ItemModel { currency_code = "GEM", currency_amount = 50 }
};
StartCoroutine(req.Send(
itemsList: itemList,
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 向玩家发放货币。可以一次发放多种货币,响应返回发放后的货币列表。
JSON 序列化
items 通过 ItemsWrapper 包装后,使用 JsonUtility 转换为 JSON 字符串。