跳转到主要内容

向邮箱中特定玩家发送物品

用于通过邮箱向特定玩家发送物品的 API。

URL 确认

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

API 信息

  • URL: https://service-api.playnanoo.com/inbox/v20220901/send/player
  • Method: PUT
  • 需要认证: 是
DeviceInfo 继承

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

请求参数

参数类型必填说明
table_codestring必填表代码
player_idstring必填接收者玩家 ID
itemsstring必填发送的物品数据(JSON 字符串)
periodint必填有效期(天)

响应数据

Res 类

字段类型说明
statusstring处理状态

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 UnityEngine;
using UnityEngine.Networking;

public class InboxSendItemPlayer
{
static string url = "https://service-api.playnanoo.com/inbox/v20220901/send/player";

[Serializable]
public class Req : DeviceInfo
{
public string table_code;
public string player_id;

// string items = JsonUtility.ToJson(SerializePost items)
public string items;
public int period;

public IEnumerator Send(
string table_code,
string playerId,
string items,
int period,
Action<Res> onSuccess,
Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(table_code)) this.table_code = table_code;
if (!string.IsNullOrEmpty(playerId)) this.player_id = playerId;
if (!string.IsNullOrEmpty(items)) this.items = items;
this.period = period;

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

[Serializable]
public class Res : BaseResponse
{
public string status;
}

[Serializable]
public class SerializePost
{
public SerializeItems[] items;
public SerializeItemMessages[] messages;
}

[Serializable]
public class SerializeItems
{
public string item_code;
public int item_count;
}

[Serializable]
public class SerializeItemMessages
{
public string language;
public string title;
public string content;
}

// 공용 설정 데이터에 추가해서 사용해 주세요.
public class InboxConfigure
{
public static readonly string PN_LANG_CODE_DEFAULT = "default";

public static readonly string PN_LANG_CODE_AF = "AF";

public static readonly string PN_LANG_CODE_AR = "AR";

public static readonly string PN_LANG_CODE_EU = "EU";

public static readonly string PN_LANG_CODE_BE = "BE";

public static readonly string PN_LANG_CODE_BG = "BG";

public static readonly string PN_LANG_CODE_CA = "CA";

public static readonly string PN_LANG_CODE_CN = "zh-CN";

public static readonly string PN_LANG_CODE_TW = "zh-TW";

public static readonly string PN_LANG_CODE_CS = "CS";

public static readonly string PN_LANG_CODE_DA = "DA";

public static readonly string PN_LANG_CODE_NL = "NL";

public static readonly string PN_LANG_CODE_EN = "EN";

public static readonly string PN_LANG_CODE_ET = "ET";

public static readonly string PN_LANG_CODE_FO = "FO";

public static readonly string PN_LANG_CODE_FI = "FI";

public static readonly string PN_LANG_CODE_FR = "FR";

public static readonly string PN_LANG_CODE_DE = "DE";

public static readonly string PN_LANG_CODE_EL = "EL";

public static readonly string PN_LANG_CODE_IW = "IW";

public static readonly string PN_LANG_CODE_HU = "HU";

public static readonly string PN_LANG_CODE_IS = "IS";

public static readonly string PN_LANG_CODE_IN = "IN";

public static readonly string PN_LANG_CODE_IT = "IT";

public static readonly string PN_LANG_CODE_JA = "JA";

public static readonly string PN_LANG_CODE_KO = "KO";

public static readonly string PN_LANG_CODE_LV = "LV";

public static readonly string PN_LANG_CODE_LT = "LT";

public static readonly string PN_LANG_CODE_NO = "NO";

public static readonly string PN_LANG_CODE_PL = "PN";

public static readonly string PN_LANG_CODE_PT = "PT";

public static readonly string PN_LANG_CODE_RO = "RO";

public static readonly string PN_LANG_CODE_RU = "RU";

public static readonly string PN_LANG_CODE_SH = "SH";

public static readonly string PN_LANG_CODE_SK = "SK";

public static readonly string PN_LANG_CODE_SL = "SL";

public static readonly string PN_LANG_CODE_ES = "ES";

public static readonly string PN_LANG_CODE_SV = "SV";

public static readonly string PN_LANG_CODE_TH = "TH";

public static readonly string PN_LANG_CODE_TR = "TR";

public static readonly string PN_LANG_CODE_UK = "UK";

public static readonly string PN_LANG_CODE_VI = "VI";
}
}

使用示例

public void SendInboxItemToPlayer()
{
InboxSendItemPlayer.Req req = new InboxSendItemPlayer.Req();

// 아이템 데이터 구성
InboxSendItemPlayer.SerializePost postData = new InboxSendItemPlayer.SerializePost
{
items = new InboxSendItemPlayer.SerializeItems[]
{
new InboxSendItemPlayer.SerializeItems { item_code = "gold", item_count = 1000 },
new InboxSendItemPlayer.SerializeItems { item_code = "diamond", item_count = 50 }
},
messages = new InboxSendItemPlayer.SerializeItemMessages[]
{
new InboxSendItemPlayer.SerializeItemMessages
{
language = InboxSendItemPlayer.InboxConfigure.PN_LANG_CODE_KO,
title = "보상",
content = "친구가 보낸 선물입니다."
},
new InboxSendItemPlayer.SerializeItemMessages
{
language = InboxSendItemPlayer.InboxConfigure.PN_LANG_CODE_EN,
title = "Reward",
content = "Gift from friend."
}
}
};

// JSON 문자열로 변환
string itemsJson = JsonUtility.ToJson(postData);

StartCoroutine(req.Send(
table_code: "inbox_table_01",
playerId: "target_player_uuid",
items: itemsJson,
period: 7, // 7일 (일 단위)
onSuccess: res =>
{
Debug.Log($"특정 플레이어에게 우편함 아이템 전송 성공: {res.status}");
},
onError: (error) =>
{
Debug.LogError($"특정 플레이어에게 우편함 아이템 전송 실패: [{error.ErrorCode}] [{error.Message}]");
}
));
}
玩家 ID

player_id 是接收者的唯一玩家 ID。

有效期

period 以天为单位指定。例如设置 7 天时输入 7。

语言代码

可以使用 InboxConfigure 类中定义的语言代码来设置多语言消息。