我想在我的应用程序中添加应用内购买功能,我想知道存储产品可用数量(例如 100 个硬币)的推荐方法是什么。
具有根访问权限的用户可以:
- 访问/操作应用程序存储的未加密数据(这样他就可以更改 硬币数量)。
- 保存加密(或混淆)数据,然后替换它以取回 说明他什么时候有更多硬币
所以即使有加密,也相对容易作弊。我的问题是:
- 我应该比加密更进一步吗? (值得付出努力吗?)
- 用户滥用此功能是否常见?
- 有没有更好的方法来存储项目数量?
- 练习内容是什么?
最佳答案
在本地存储您的游戏世界货币,让交易在没有网络连接的情况下在本地发生,但当用户重新连接到互联网时,将本地硬币与服务器显示的购买金额进行核对。
基本上,当您有网络连接时,下载任何从 Google 购买的应用内产品。检查您的库存,然后根据用户离线时的行为消耗任何应该减少的产品。执行此操作后,如果本地总数与服务器显示的内容(消费后)存在差异,则将其标记为潜在的黑客攻击。否则,你很好(一切都平衡)。
当使用像这样的消耗性应用内产品时(这听起来像是您正在尝试做的),确实没有完全离线的方式来做到这一点。您依赖 Google 的应用内结算服务,因此您必须不时检查他们的服务器以协调/刷新购买的库存。来自谷歌的 in-app billing documentation :
To record a purchase consumption, send the
consumePurchase
method to the In-app Billing service and pass in thepurchaseToken
String value that identifies the purchase to be removed. ThepurchaseToken
is part of the data returned in theINAPP_PURCHASE_DATA
String by the Google Play service following a successful purchase request. In this example, you are recording the consumption of a product that is identified with the purchaseToken in the token variable.
int response = mService.consumePurchase(3, getPackageName(), token);
Warning: Do not call the
consumePurchase
method on the main thread. Calling this method triggers a network request which could block your main thread. Instead, create a separate thread and call theconsumePurchase
method from inside that thread.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.
至于离线时如何存储和管理库存,您提到的方法听起来不错。加密没有坏处,但只要您以合理的时间间隔与 Google 进行协调,就可能没有必要。只有极少数人真正尝试利用应用程序。大多数用户没有 root,而对于那些有 root 权限的用户,大多数人实际上不知道如何利用这些漏洞。如果您仍然担心,是的,请继续加密。这应该足以让绝大多数用户保持诚实。
关于android - 在设备上存储应用内项目数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24088992/