为自己的游戏创建兑换码

为自己的游戏创建兑换码

在开发者控制台设置兑换码,让玩家获得道具、货币或其他游戏内奖励。

创建免费开发者账户

灵活的奖励内容

奖励数据为自由格式的 JSON,你可以发放游戏能识别的任意货币、道具或标记组合。

服务器玩家数值

兑换时由服务器发放最多八种已配置的数值。giftData仍是独立的游戏数据。显示返回的余额,不要在本地再次叠加奖励。

即时撤销

如果礼品码泄露或被滥用,可在 Dashboard 中即刻撤销,无需推送 App 更新。

快速集成

快速集成

兑换礼品码

输入礼品码

在下方输入你的促销码

WINTER2024
快速集成
Unity (C#)
// Develop Unity SDK: signed-in player, durable original redemption intent.
using PM.horizOn.Cloud.Manager;
using UnityEngine;

// Run from one explicit player action; serialize this handler until it completes.
string userId = UserManager.Instance.CurrentUser.UserId;
string project = HorizonApp.Network.GetApiKey();
string scope = PM.horizOn.Cloud.Objects.Network.Responses.GiftCodeIntent.ProjectFingerprint(project);
string pendingKey = "horizOn_gift_v2_" + scope + "_" + userId;
// Preserve an old V1 demo record for reconciliation. Never reinterpret its UUID as a count.
if (PlayerPrefs.HasKey("horizOn_gift_pending_" + userId)) return;
PM.horizOn.Cloud.Objects.Network.Responses.GiftCodeIntent pending;
if (PlayerPrefs.HasKey(pendingKey)) {
    pending = JsonUtility.FromJson<PM.horizOn.Cloud.Objects.Network.Responses.GiftCodeIntent>(PlayerPrefs.GetString(pendingKey));
    if (pending == null || !pending.IsValidFor(project, userId)) return;
} else {
    pending = await GiftCodeManager.Instance.PrepareRedemption("WELCOME");
    if (pending == null || !pending.IsValidFor(project, userId) || PlayerPrefs.HasKey(pendingKey)) return;
    PlayerPrefs.SetString(pendingKey, JsonUtility.ToJson(pending));
    PlayerPrefs.Save(); // All seven fields before the first mutating request.
}
string original = JsonUtility.ToJson(pending);
if (PlayerPrefs.GetString(pendingKey) != original) return;
var result = await GiftCodeManager.Instance.RedeemPrepared(pending);
if (result == null || !result.success) return; // Keep the exact tuple after any uncertain result.
if (PlayerPrefs.GetString(pendingKey) == original) {
    PlayerPrefs.DeleteKey(pendingKey);
    PlayerPrefs.Save();
}
if (result.playerValues != null) {
    foreach (var value in result.playerValues.values) Debug.Log(value.key + "=" + value.balance);
}
// alreadyApplied/replayed means the sequence slot was consumed, with no copied historical rewards.
// Replace balances with playerValues. Never add grantedValues locally.

这些示例使用 Unity SDK(C#)和 REST API。Godot 和 Unreal 在各自的 SDK 中有相同的调用: 参见快速入门

常见问题

常见问题

准备好开始集成了吗?

今天就开始使用 horizOn 构建你的游戏后端,免费套餐开箱即用。