其他分享
首页 > 其他分享> > android-将应用内商品数据存储在设备上

android-将应用内商品数据存储在设备上

作者:互联网

我想在应用程序中添加应用程序内购买功能,并且我想知道什么是推荐的方法来存储产品的可用数量(例如100个硬币).

具有root用户访问权限的用户可以:

>访问/操纵应用程序存储的未加密数据(以便他可以更改
硬币数量).
>保存加密的(或模糊的)数据,然后稍后将其替换以取回
说明他有更多硬币的时候

因此,即使使用加密,作弊也相对容易.我的问题是:

>除了加密外,我还应该进一步吗? (值得付出努力吗?)
>用户滥用它是否很常见?
>有没有更好的方法来存储项目计数?
>实践是什么?

解决方法:

将您的游戏世界货币存储在本地,并允许交易在没有网络连接的情况下在本地进行,但是当用户重新连接到Internet时,请将本地代币与服务器显示为已购买的代币进行调和.

基本上,当您建立网络连接后,请从Google下载所有购买的应用内商品.检查您的库存,然后根据用户离线时的消耗量消耗应减少的任何产品.完成此操作后,如果本地总数与服务器显示的内容(使用后)之间存在差异,则将其标记为潜在的hack.否则,你就很好(一切都平衡了).

当使用这种消耗性应用程序内产品(听起来像您正在尝试做的事情)时,实际上并没有完全脱机的方法.您依赖Google的应用内结算服务,因此您必须不时检查其服务器,以协调/刷新购买的库存.从Google的in-app billing documentation

To record a purchase consumption, send the consumePurchase method to
the In-app Billing service and pass in the purchaseToken String value
that identifies the purchase to be removed. The purchaseToken is part
of the data returned in the INAPP_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 the
consumePurchase 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和解,就很可能不需要加密.实际上,只有极少数人尝试利用应用程序.大多数用户不生根,而对于那些这样做的人,大多数实际上不知道如何进行这些攻击.如果您仍然担心,可以继续进行加密.这足以吓阻您,让您的绝大多数用户保持诚实.

标签:encryption,in-app-purchase,android
来源: https://codeday.me/bug/20191029/1960277.html