> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 欺诈防范快速入门

> 在 PlayFab Economy v2 中启用 Microsoft Store、iOS、Google Play 和其他平台的收据验证和欺诈防范的快速入门指南。

<Info>
  Economy v2 现已正式发布。如需支持和反馈，请访问 [PlayFab 论坛](https://community.playfab.com)。
</Info>

本快速入门将帮助你在 Microsoft Store ([Windows 10/11](https://learn.microsoft.com/en-us/windows/uwp/publish/)、[XBOX](https://learn.microsoft.com/en-us/gaming/xbox/)、[Android](https://blogs.windows.com/windows-insider/2021/10/20/announcing-android-apps-on-windows-11-preview-for-windows-insiders-in-the-beta-channel/)) 上运行收据验证。

## 先决条件

[PlayFab Economy v2 快速入门](/services/playfab/economy-monetization/economy-v2/quickstart) 将帮助你完成设置并准备好执行收据验证。

## Microsoft Store 市场收据验证

* [GetMicrosoftStoreAccessTokens](https://learn.microsoft.com/en-us/rest/api/playfab/economy/inventory/get-microsoft-store-access-tokens)
* [RedeemMicrosoftStoreInventoryItems](https://learn.microsoft.com/en-us/rest/api/playfab/economy/inventory/redeem-microsoft-store-inventory-items)

要使用 Redeem API，你需要首先在你使用的任何市场（Apple Store、Steam、Google Play 等）中设置你的产品 ID 和价格。最初，所有产品都是无名的——玩家可以购买的数字条目——但在 PlayFab 中没有意义。

要为这些条目赋予意义，我们需要在 PlayFab 目录中镜像它们。镜像它们会将无名实体变成目录捆绑包。当你在新服务中调用 `RedeemMicrosoftStoreInventoryItems` 时，我们会在目录中查找匹配的捆绑包，以授予实体玩家的虚拟库存。

每个捆绑包可以通过向其添加 AlternateId 来链接到一个或多个合作伙伴市场产品。AlternateId 是 PlayFab 与任何外部 IAP 市场之间的链接。当你的游戏为给定的玩家实体调用 Redeem 时，我们会将此 ID 传递到 IAP 市场进行检查。一般流程为：

1. 在 Microsoft Store 中创建 1 个（或多个）真实世界的优惠
2. 使用 IAP 市场调用权限填充 PlayFab 中的加载项，并在 PlayFab 中创建链接到你创建的优惠的相应捆绑包
3. 调用 `RedeemMicrosoftStoreInventoryItems`

<Note>
  与 PlayFab 之前的版本不同，在新系统中你只需创建一个捆绑包优惠，然后将每个需要引用的市场 SKU 添加到 AlternateId 列表中。你不需要为每个 IAP 市场创建新物品。
</Note>

### 步骤 1 - 设置你的市场集成

你需要在 GameManager 的 Add-ons 部分中设置每个 IAP 市场集成，以允许 PlayFab 代表游戏调用市场。

### 步骤 2 - 创建用于收据验证的捆绑包

你可以在 GameManager 内或通过调用 `CreateDraftItem` 来[创建捆绑包](/services/playfab/economy-monetization/economy-v2/catalog/bundles)。捆绑包最少需要 Title、Description 和 Items。在 GameManager 中，你可以使用 Marketplace Mapping 部分链接市场条目。

如果你使用 API 构建捆绑包，则需要在捆绑包的 alternateIds 部分下添加 IAP 市场映射。市场枚举是特定的且区分大小写；你必须使用以下 Add-ons 之一：

* Apple = "AppleAppStore"
* Google Play = "GooglePlay"
* Nintendo = "NintendoEShop"
* Microsoft = "MicrosoftStore"
* PlayStation = "PlayStationStore"
* Steam = "Steam"

### 步骤 3 - 从你的游戏调用 Redeem

你的游戏使用实体和收据详细信息调用 `RedeemMicrosoftStoreInventoryItems` API，以"兑换"真实世界的优惠并填充相应的实体库存。你需要在调用中提供一些内容以使其正常工作：

* 请求头中所需
  * X-EntityToken - 唯一标识 PlayFab 实体的令牌
  * Content-Type - Application/Json
* 请求正文中所需
  * `CollectionsIdKey`

每个 IAP 市场对进行这些调用的要求略有不同。例如，Apple 和 GooglePlay 购买，你需要附加市场收据。

当你的游戏客户端启动时，首先为市场发起一次 PlayFab Redeem 调用。Redeem 调用允许 PlayFab 与可能发生的离线或游戏视线之外的购买同步。你的游戏应在发生任何市场优惠的游戏内购买时使用这些调用。

Redeem 将确保在调用 Redeem 端点之后填充玩家实体的库存货币。

## 第 4 部分：购买物品

### Game Manager

你可以在各个玩家视图中验证物品或货币是否存在。在 GameManager 中，选择 Players，并导航到单个玩家实体。使用库存选项卡查看和更新该实体玩家拥有的内容。

### API

在你的游戏中，以已获得虚拟货币的玩家身份登录。

调用 `SearchItems` 以使用先前发布的目录 itemId。

使用目录物品的 itemId 和授予的虚拟货币 ID 调用 `PurchaseInventoryItems`。

最后，`GetInventoryItems` 并查看该方法的结果。

***

你可以在[此处](https://learn.microsoft.com/en-us/windows/uwp/monetize/)详细了解在 Microsoft 平台上的货币化。


## Related topics

- [使用 Google 市场进行兑换](/zh-CN/services/playfab/economy-monetization/economy-v2/marketplace/marketplace-redemption/google.md)
- [使用 Steam 市场进行兑换](/zh-CN/services/playfab/economy-monetization/economy-v2/marketplace/marketplace-redemption/steam.md)
- [Economy v2 真钱价格](/zh-CN/services/playfab/economy-monetization/economy-v2/catalog/real-money-prices.md)
- [Economy v2 中的真钱价格跟踪](/zh-CN/services/playfab/economy-monetization/economy-v2/tutorials/real-money-price-tracking.md)
- [使用 Microsoft Store 市场进行兑换](/zh-CN/services/playfab/economy-monetization/economy-v2/marketplace/marketplace-redemption/microsoft.md)
