Android应用内购买检查买家离线 [英] Android In-App Purchase check buyer offline

查看:170
本文介绍了Android应用内购买检查买家离线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用结算服务的应用程序中实施应用程序购买(管理)时,如果用户想要购买物品,他将提出需要互联网的购买请求,即使用户已经购买了该物品。所以为了方便用户,我正在这样做,如果用户已经购买了该项目,那么值将被保存在共享的前缀中。并且当用户点击该特定项目时,首先它将检查共享前缀。价值,无论用户是否已经购买物品,如果不是,则去购买请求,否则显示他/她的物品。
我的问题是,这是安全的方式?或者我还要做别的事情? 这是不安全的。我会阻止你以这种方式实施这样的检查。您应该采用标准方法并使用 getPurchases()方法。您可以随时(甚至离线)调用此方法,并且如果用户已购买,它们将从该方法返回。以下是一个示例代码:

  IInAppBillingService服务; //首先初始化

Bundle response = service.getPurchases(3,you app package,inapp,null);
int responseCode = response.getInt(KEY_RESPONSE_CODE);
if(responseCode == RESPONSE_OK){
ArrayList< String> purchases = response.getStringArrayList(KEY_INAPP_PURCHASE_ITEM_LIST);
...
}

诅咒您需要验证购买签署正确的证书和购买状态不会被取消。但是这比在共享属性中存储数据更安全。这种方法的另一个优点是,在用户重新安装应用程序后,所有购买都将在那里自动提供。


I have implement in app purchase (managed) in my application using billing services when ever user wants to buy item he will make purchase request that required internet even if user has already bought the item. so for user convenience i am doing that if user has bought the item then a value will be save in shared pref. and when ever user click on that particular item then 1st it will check shared pref. value that either user has bought item or not if not then go for purchase request else show him/her item. My Question is that is it safe way? or i have to do something else?

解决方案

This is not safe. I would discourage you from implementing such a check this way. You should rather go for standard approach and use getPurchases() method. You can call this method at any time (even offline) and if a user has purchases, they will be returned back from that method. Here is a sample code:

IInAppBillingService service; // initialize it first

Bundle response = service.getPurchases(3, "you app package", "inapp", null);
int responseCode = response.getInt(KEY_RESPONSE_CODE);
if (responseCode == RESPONSE_OK) {
    ArrayList<String> purchases = response.getStringArrayList(KEY_INAPP_PURCHASE_ITEM_LIST);
    ...
}

Of curse you need to verify that purchases are signed with correct certificate and purchase state is not cancelled. But this is much safer than storing data in shared properties. Another advantage of this approach is that after user reinstalls the app, all purchases will be automatically available there too.

这篇关于Android应用内购买检查买家离线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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