4

我试图搜索有关该问题的信息,但没有得到很多信息。我只知道:
- 在用户首次安装应用程序或用户卸载/擦除数据时重新安装时恢复。
- 恢复交易只适用于托管产品。
我试图阅读地牢示例,关于恢复事务的代码很少,例如:何时调用恢复请求,何时获得恢复响应......但我不知道:
- 如何获取返回信息?(如您购买的商品ID)

请有人再次解释一下应用内计费中恢复交易的过程。

非常感谢!!!

编辑:很抱歉,我很久没有在Android上工作了,现在我不知道这个问题的正确答案是什么,所以我不能标记答案:P

4

4 回答 4

7

典型流程如下:

  1. 用户安装您的应用程序。

  2. 首次加载应用时,您会检查是否需要恢复购买。

  3. 如果这样做,请向 Google 发送 RESTORE_TRANSACTION 同步请求。

  4. Google 将对您的 RESTORE_TRANSACTION 请求作出确认响应。(这只是确认他们收到了您的请求。)

  5. 此时,您应该标记您已经向 Google 发送了恢复请求,并且不需要从应用程序发送进一步的恢复。

  6. 现在,对于用户之前购买的每个应用内购买,Google 将开始异步向您的应用发送“PURCHASE_STATE_CHANGED”事件。如果用户第一次购买,该调用与 Google 发送的调用相同。

  7. 由于它是同一个调用,您的应用程序将接收事件并正常处理它,就好像用户刚刚购买了应用程序内产品一样(从而“恢复”购买的功能)。

关于第 2 步和第 5 步,我为我的应用程序所做的是保留一个名为“APP_INITIALISED”的 SharedPreference 值,该值默认为 false。每次我的应用启动时,如果“APP_INITIALISED”为假,我会告诉 Google RESTORE_TRANSACTION(第 2 步),然后我将 APP_INITIALISED 设置为真(第 5 步)。

于 2012-08-29T23:34:19.320 回答
0

我不确定,但我认为,在调用 restoreTransactions() 之后,将调用 onPurchaseStateChange 并带有已购买物品的 id。

于 2012-02-24T15:34:24.943 回答
0

我使用了这种方法:

public static void restoreTransactionInformation(Long nonce){
    if (amIDead()) 
    {
        return;
    }
    Log.i(TAG, "confirmTransaction()");
    Bundle request = makeRequestBundle("RESTORE_TRANSACTIONS");
    // The REQUEST_NONCE key contains a cryptographically secure nonce (number used once) that you must generate
    request.putLong("NONCE", nonce);
    try 
    {
        Bundle response = mService.sendBillingRequest(request);

        //The REQUEST_ID key provides you with a unique request identifier for the request
        Long requestIndentifier     = (Long) response.get("REQUEST_ID");
        Log.i(TAG, "current request is:" + requestIndentifier);

        //The RESPONSE_CODE key provides you with the status of the request
        Integer responseCodeIndex   = (Integer) response.get("RESPONSE_CODE");
        C.ResponseCode responseCode = C.ResponseCode.valueOf(responseCodeIndex);
        Log.i(TAG, "RESTORE_TRANSACTIONS Sync Response code: "+responseCode.toString());
    } 
    catch (RemoteException e) 
    {
        Log.e(TAG, "Failed, internet error maybe", e);
        Log.e(TAG, "Billing supported: " + isBillingSupported());
    }
}

通过使用调用它

BillingHelper.restoreTransactionInformation(BillingSecurity.generateNonce());
于 2012-12-06T08:33:13.343 回答
0

我会通过编辑证明@Frank Leigh的回答,即所有购买都是一体PURCHASE_STATE_CHANGED的,签名数据如下

signedData:{

    "nonce":1234*,
    "orders":[
         {
         "orderId":"1234*.1234*",
         "packageName":"com.*",
         "productId":"**p1**",
         "purchaseTime":time,
         "purchaseState":0,
         "purchaseToken":"*"
        },
        {
         "orderId":"1234*.1234*",
         "packageName":"com.*",
         "productId":"**p2**",
         "purchaseTime":time,
         "purchaseState":0,
         "purchaseToken":"*"
        },
        {
         "orderId":"1234*.1234*",
         "packageName":"com.*",
         "productId":"**p3**",
         "purchaseTime":time,
         "purchaseState":0,
         "purchaseToken":"*"
        }
    ]
}
于 2013-03-27T22:25:22.007 回答