如何使用Appcelerator的Titanium SDK使用Android应用内结算模块检查用户的应用内购买情况?

时间:2014-04-28 21:07:32

标签: android in-app-purchase titanium titanium-modules

我们的应用程序使用Google Play商店中的托管购买,我们使用In-App Billing free module from the market,我们能够毫无问题地将其功能实施到我们的项目中。直到出现一个问题:我们如何检查这些托管购买?

在本地,应用内结算库访问Play商店应用并检查用户所做的购买,但我们检查了此模块的文档和示例,并且没有公开的方法来进行此检查,因此我们如何检查用户购买了什么?

这很重要,因为如果用户购买了例如Basic皮肤,则用户必须能够在其安装的应用程序中拥有的每个设备中看到此皮肤并登录到标有产品的同一帐户购买时。

简而言之,我如何检查用户从Play商店进行的托管购买?可以使用应用内结算模块完成吗?如果模块不能这样做,它可以完成吗?

我们正在使用Titanium SDK 3.2.0.GA,Studio 3.2.0.201312191547,并使用Android 4.4测试Moto G和使用Android 4.1.2测试Xperia Acro S.

1 个答案:

答案 0 :(得分:1)

您可以使用恢复购买功能间接执行此操作,我相信您处理此操作的方式是在调用restoreTransactions之后侦听状态更改,然后在您设置时返回每个(或根本没有)那些物品作为购买的方式与用户在那里购买它们的方式相同,所以我认为这样......

InAppBilling.restoreTransactions();

...

// Then wait for this to get called per item to be restored
InAppBilling.addEventListener(InAppBilling.PURCHASE_STATE_CHANGED_EVENT, function(e){
    // These events and the JSON object returned are detailed on the [Android Dev Site](http://developer.android.com/google/play/billing/billing_reference.html#billing-intents)
    // verify signature 
    var sign = e.signature;
    .....
    // Get the returned JSON object
    var response = JSON.parse(e.signedData);

    // Now do app logic with an identifier from the response object, I think like below
    var id = response.productId;
    ....
});

或者上面的一些变体,我认为这里的关键观察是使用restoreTransactions是要走的路。