gpt4 book ai didi

java - 跨 session /设备处理应用内购买/消耗品?

转载 作者:太空宇宙 更新时间:2023-11-03 13:42:22 24 4
gpt4 key购买 nike

我的问题主要围绕使用 Google 的应用内结算 API 处理应用内消费品购买。 ( https://developer.android.com/google/play/billing/api.html#consumetypes )

他们的文档将消耗品描述为:

Consumable products

In contrast, you can implement consumption for products that can be made available for purchase multiple times. Typically, these products provide certain temporary effects. For example, the user's in-game character might gain life points or gain extra gold coins in their inventory. Dispensing the benefits or effects of the purchased product in your application is called provisioning the managed product. You are responsible for controlling and tracking how managed products are provisioned to the users.

消耗品是可以多次购买的东西(例如游戏货币、游戏内元素或使用的升级等),而非消耗品只能购买一次(无广告、皮肤/角色等)

在关于消费购买的文档 ( https://developer.android.com/training/play-billing-library/purchase-iab-products.html ) 中,它还提到:

How you use the consumption mechanism in your app is up to you. Typically, you would implement consumption for products with temporary benefits that users may want to purchase multiple times, such as in-game currency or replenishable game tokens. You would typically not want to implement consumption for products that are purchased once and provide a permanent effect, such as a premium upgrade.

It's your responsibility to control and track how the in-app product is provisioned to the user. For example, if the user purchased in-game currency, you should update the player's inventory with the amount of currency purchased.

我的问题是如何跟踪消耗品的用户库存?文档和各种视频似乎很快就掩盖了这一点,基本上是说应用程序必须在获得成功购买确认后应用消耗品的效果。但这并不是真正的全貌。如果用户注销并使用其他帐户重新登录怎么办?或者他们换了一部新手机,他们应该在该手机上安装该产品。

您无法真正将购买记录保存在 SharedPreferences 或永久缓存中,因为它与手机相关联。如果用户在不同的手机上登录,那么他们应该享受他们所做的所有购买的好处。

举个例子:

游戏开始时玩家有 1000 金币。玩家通过应用内购买再购买 500 金币,然后花费 200 金币。如果玩家购买新手机并在该手机上安装该应用程序,他们应该有 1300 金币。

这通常是如何完成的?

您是否需要独立于 Google 运行私有(private)服务器来跟踪此类商品的购买/消费情况?

谢谢!!

最佳答案

我正在自己实现应用内购买。

Do you need to run a private server that keeps track of purchases/consumption of such things separate from Google?

当然可以,正如 Google 在 Security Best Practices 中所建议的那样

It's highly recommended to validate purchase details on a server that you trust. If you cannot use a server, however, it's still possible to validate these details within your app on a device.

你的第二个问题

What if a user signs out and signs back in with a different account?

orderId 绑定(bind)到帐户或设备。在第一种情况下,您可以在用户切换设备时轻松管理购买(获得私有(private)服务器的另一个原因)。而在第二种情况下,您可以允许在同一台设备上切换帐户。因此,选择哪一个取决于您。

您需要将本地消费同步到服务器。

这是验证购买的流程:

  1. User clicks “BUY” button.
  2. Makes payment with google.
  3. App receives “receipt” from google and store it locally
  4. Send this “RECEIPT” to the Server.
  5. The Server sends the “purchaseToken” to Google Play Developer API for validation
  6. The Google Play Developer API sends response with status code.
  7. Store the RECEIPT in the server database (If we you to keep history of purchases by users).

这是使用产品的流程:

  1. The user opens the app.
  2. App assigns values to the Resources by reading from local storage.
  3. App tries to synchronize with the Server.(checks last updated timestamp)

Different scenarios:

Synchronization Successful: Assigns Resource values from the server. Set newly retrieved values in the local storage.

Synchronization Failed: Keep Resource values and try again.

  1. User consumes the Resource.
  2. App updates local values in Resource and sync with the server.(checks last updated timestamp)

我使用了以下文章:

  • 教程:如何在 Android 中实现应用内结算 LINK
  • 关于实现 InApp 购买的文章 LINK .
  • 如何在服务器端验证 Android 应用的购买(Google Play in App Billing v3)LINK .
  • 另一个 SO 答案 LINK .
  • 另一个 SO 答案 LINK .
  • 代码项目示例 LINK .

关于java - 跨 session /设备处理应用内购买/消耗品?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49344238/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com