跳转到主要内容

使用优惠券

使用优惠券代码获取奖励的 API。

URL 确认

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

API 信息

  • URL: https://service-api.playnanoo.com/coupon/v20240301/search
  • Method: PUT
  • 需要认证: 是

请求参数

参数类型必填说明
codestring必填要使用的优惠券代码

响应数据

Res 类

字段类型说明
ItemsSerializeReward[]奖励物品列表

SerializeReward 结构

字段类型说明
item_codestring物品代码
item_countdouble物品数量

Unity C# 实现

BaseResponse 类

所有 API 响应的基类。

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

字段说明:

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

使用优惠券类

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

public class CouponUse
{
static string url = "https://service-api.playnanoo.com/coupon/v20240301/search";

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

public IEnumerator Send(
string coupon_code,
Action<Res> onSuccess,
Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(coupon_code)) this.code = coupon_code;

// PUT 방식 호출
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
url,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}

[Serializable]
public class Res : BaseResponse
{
public List<SerializeReward> Items;
}

[Serializable]
public class SerializeReward
{
public string item_code;
public double item_count;
}
}

使用示例

public void UseCoupon()
{
CouponUse.Req req = new CouponUse.Req();

StartCoroutine(req.Send(
coupon_code: "PLAYNANOO2024",
onSuccess: res =>
{
// 보상 정보
foreach (var item in res.Items)
{
Debug.Log($"보상: {item.item_code} x{item.item_count}");
}
},
onError: (error) =>
{
Debug.LogError($"쿠폰 사용 실패: [{error.ErrorCode}] [{error.Message}]");
}
));
}
优惠券代码

优惠券代码区分大小写,可以设置为一次性或多次使用。