본문으로 건너뛰기

재화 지급

플레이어에게 재화를 지급하는 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의 모든 속성이 자동으로 포함됩니다.

요청 파라미터

파라미터타입필수설명
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 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 문자열로 변환됩니다.