跳转到主要内容

货币充值

为玩家充值货币的 API。

URL 确认

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

API 信息

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

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

请求参数

参数类型必填说明
itemsstring必填货币列表 (JSON 字符串)

响应数据

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

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 CurrencyCharge
{
static string path = "https://service-api.playnanoo.com/currency/v20221101/currency/charge";

[Serializable]
public class Req : DeviceInfo
{
public string items;

public IEnumerator Send(List<ItemModel> itemList, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if(itemList != null && itemList.Count > 0)
{
ItemsWrapper wrapper = new ItemsWrapper { items = itemList };
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 ChargeCurrency()
{
CurrencyCharge.Req req = new CurrencyCharge.Req();

// 충전할 재화 목록 생성
List<CurrencyCharge.ItemModel> itemList = new List<CurrencyCharge.ItemModel>
{
new CurrencyCharge.ItemModel { currency_code = "GOLD", currency_amount = 500 },
new CurrencyCharge.ItemModel { currency_code = "GEM", currency_amount = 100 }
};

StartCoroutine(req.Send(
itemList: 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 字符串。