跳到主要内容

Player Wallet

1. 什么是玩家钱包?

玩家钱包旨在帮助您管理玩家持有的货币。您可以查看玩家在钱包中购买和获得的货币余额及消费情况。出于安全考虑,我们仅为游戏服务器和虚拟服务器提供向钱包授予货币的API。

2. 在门户网站中使用钱包

前往门户网站 -> 玩家并找到目标玩家。在玩家详情的经济标签页中,您可以找到玩家的钱包。在这里,您可以看到玩家持有的所有货币。

  • 货币代码(Currency Code):货币的唯一标识符。
  • 类型(Type):目前仅支持虚拟货币
  • 数量(Amount):此货币的余额。
  • 总支出(Total Spend):玩家使用此货币的总支出金额。

image-20210630151847301

在某些情况下,您可能需要直接向玩家钱包添加货币或从玩家钱包中扣除指定金额。要执行此操作,请前往管理后台,在玩家查询区域找到该玩家,并打开玩家钱包页面:

  • 点击操作 -> \"+\" 向玩家发放指定货币。

image-20210630151720104

  • 点击操作 -> "-" 从玩家扣除指定货币。

image-20210630151803646

3. 通过客户端 SDK 使用余额

3.1 获取余额

此操作用于获取玩家余额。调用客户端 Economy 模块的 GetBalances 方法:

#include "PgosSDKCpp/Public/PgosSDKCpp.h"
#include "PgosSDKCpp/Public/Core/PgosErrorCode.h"

void SomeUObjectClass::GetBalances()
{
auto economy = IPgosSDKCpp::Get().GetClientEconomyAPI();
if (economy)
{
economy->GetBalances(
[](const FPgosResult& Ret, const FClientGetBalancesResult* Response) {
if (Ret.err_code == (int32)Pgos::PgosErrCode::kSuccess)
{
UE_LOG(LogTemp, Log, TEXT("GetBalances Success"));
}
else
{
UE_LOG(LogTemp, Log, TEXT("GetBalances Failed: err_code=%d, err_msg=%s"), Ret.err_code, *Ret.msg);
}
});
}
}

4. 通过 DS SDK 使用余额

4.1 发放货币

此操作用于向指定玩家发放指定货币。

调用服务器经济模块的 GrantCurrencyToPlayer 方法:

#include "PgosSDKCpp/Public/PgosSDKCpp.h"
#include "PgosSDKCpp/Public/Core/PgosErrorCode.h"

void SomeUObjectClass::GrantCurrencyToPlayer()
{
auto economy = IPgosSDKCpp::Get().GetServerEconomyAPI();
if (economy)
{
FString PlayerId = "13148";
FServerGrantCurrency Currency;
Currency.currency_code = "DIAMOND";
Currency.amount = 888;
economy->GrantCurrencyToPlayer(
PlayerId, Currency,
[](const FPgosResult& Ret, const FServerGrantCurrencyResult* Response) {
if (Ret.err_code == (int32)Pgos::PgosErrCode::kSuccess)
{
UE_LOG(LogTemp, Log, TEXT("GrantCurrencyToPlayer Success"));
}
else
{
UE_LOG(LogTemp, Log, TEXT("GrantCurrencyToPlayer Failed: err_code=%d, err_msg=%s"), Ret.err_code, *Ret.msg);
}
});
}
}

6. Key Errors Handling

错误马相关 API处理建议
kBackendThrottlingGrantCurrencyToPlayer检测到当前玩家操作过于频繁,请稍后重试。
kBackendShouldRetryGrantCurrencyToPlayer失败的请求可以重试以获得成功。
kBackendIdempotentParamsMismatchGrantCurrencyToPlayeridempotency_token 输入参数在操作中被重复使用,但至少有一个其他输入参数与之前的操作调用不同。现在当玩家 ID 不一致时将返回错误。