跨会话/设备处理应用程序内购买/消费品? [英] Handling in-app purchases / consumable products across sessions/devices?

查看:94
本文介绍了跨会话/设备处理应用程序内购买/消费品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My question is centered around handling in-app purchases for consumables with Google's In-App Billing API. (https://developer.android.com/google/play/billing/api.html#consumetypes)

他们的文档将易损件描述为:

Their documentation describes consumables as:

消费品

相反,您可以对可以多次购买的产品实施消费.通常,这些产品会提供某些临时效果.例如,用户的游戏角色可能会获得生命点或在其库存中获得额外的金币.在您的应用程序中分配所购买产品的收益或影响称为供应被管理产品. 您负责控制和跟踪向用户提供被管理产品的方式.

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.

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

A consumable item is something that could be purchased several times (like in game currency, an in game item or upgrade that is used, etc.), whereas a non-consumable can only be purchased once (no-ads, a skin / character, etc.)

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

In the documentation on consuming a purchase (https://developer.android.com/training/play-billing-library/purchase-iab-products.html), it also mentions:

由您决定如何在应用中使用消费机制.通常,您将对用户可能想多次购买的具有临时利益的产品实施消费,例如游戏中的货币或可补充的游戏代币.通常,您不希望对一次性购买的产品实施消费并提供永久性影响,例如高级升级.

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.

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

My question is how to keep track of user inventory for consumable products? The documentation and various videos seem to quickly gloss over this, basically saying the app must apply the effects of the consumable when it gets confirmation of a successful purchase. But that isn't really the full picture. What if a user signs out and signs back in with a different account? Or they switch to a new phone, they should have the product on that phone.

您无法真正将购买记录保存在SharedPreferences或永久性缓存中,因为它与电话绑定.如果用户在其他手机上登录,那么他们应该会从所进行的所有购买中受益.

You can't really save record of the purchase in SharedPreferences or a persistent cache because it is tied to the phone. If a user signs in on a different phone then they should have the benefits of all the purchases they made.

以下面的示例为例:

游戏以1000金币开始玩家.玩家通过应用内购买再购买500黄金,然后花费200黄金.如果玩家购买了一部新手机并在该手机上安装了该应用,则他们应该拥有1300金币.

A game starts players with 1000 gold. Player buys 500 more gold through an in-app purchase, then spends 200 gold. If player buys a new phone and installs that app on that phone, they should have 1300 gold.

这通常如何完成?

您是否需要运行私人服务器来跟踪与Google无关的此类商品的购买/消费?

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

谢谢!

推荐答案

我自己正在实施应用内购买.

I am implementing in-app purchase myself.

您是否需要运行私人服务器来跟踪与Google无关的此类商品的购买/消费?

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

当然可以,正如Google在安全性最佳做法中建议的那样

Yes of course as Google suggests in 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绑定到帐户或设备. 在第一种情况下,您可以在用户切换设备时轻松管理购买(获得私有服务器的另一个原因). 在第二种情况下,您可以允许在同一设备上切换帐户. 因此,由您决定选择哪一个.

Tie the orderId to account or device. In the first case, you can easily manage the purchase when the user switches the devices(another reason to get a private server). While in the second case you can allow switching accounts on the same device. So it's up to you which one to select.

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

You need to Synchronize local consumption to the server.

这是验证购买的流程:

  1. 用户单击购买"按钮.
  2. 通过Google付款.
  3. 应用收到Google的收据"并将其存储在本地
  4. 将此"RECEIPT"发送到服务器.
  5. 服务器将"purchaseToken"发送到Google Play开发者API进行验证
  6. Google Play开发者API发送带有状态代码的响应.
  7. 将RECEIPT存储在服务器数据库中(如果您要保留用户的购买历史记录).

这是消费产品的流程:

  1. 用户打开应用程序.
  2. 应用程序通过读取本地存储为资源分配值.
  3. 应用尝试与服务器同步.(检查上次更新的时间戳)

不同的情况:

同步成功:从服务器分配资源值.在本地存储中设置新检索的值.

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. 用户消耗资源.
  2. 应用程序更新资源中的本地值并与服务器同步.(检查上次更新的时间戳记)

我使用了以下文章:

  • 教程:如何在Android中实现应用内结算 LINK .
  • 如何在服务器端验证Android应用的购买(Google Play在应用结算v3中) LINK .
  • 另一个答案 LINK .
  • 代码项目示例 LINK .
  • Tutorial: How to Implement In-app Billing in Android LINK
  • Article on implementing InApp purchase LINK.
  • How to verify purchase for android app in server side (google play in app billing v3) LINK.
  • Another SO answer LINK.
  • Another SO answer LINK.
  • Code Project Sample LINK.

这篇关于跨会话/设备处理应用程序内购买/消费品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆