我试图搜索这个问题,但没有得到很多信息。我只知道:
- 在用户首次安装应用程序时或用户在卸载/擦除数据时重新安装时还原。
- 恢复交易仅适用于托管产品。
我试着阅读Dungeon Example,关于恢复事务的代码行很少,比如:何时调用恢复请求,何时恢复请求...但我不知道:
- 如何获得退货信息? (比如你买的商品ID)
有人请再次解释在应用内结算中恢复交易的过程。
非常感谢你!!!
编辑:很抱歉,我很久没有在Android上工作了,现在我不知道这个问题的答案是什么,所以我不能回答:P
答案 0 :(得分:6)
典型流程如下:
用户安装您的应用。
首次加载应用时,您需要检查是否需要还原 购买。
如果您这样做,请向Google发送RESTORE_TRANSACTION同步请求。
Google会回复您的回复 RESTORE_TRANSACTION请求。 (这是只是一种认可 他们收到了您的请求。)
此时,您应该标记您已向Google发送了恢复请求,并且无需从该应用程序发送进一步的恢复。
现在异步 Google将开始向您的应用发送'PURCHASE_STATE_CHANGED'事件,以便用户先前购买的每个应用内购买。如果用户第一次进行购买,则此次通话与Google发送的相同。
由于这是同一个电话,您的应用会选择该事件并正常处理,就像用户刚刚购买了应用内商品一样(从而“恢复”购买的功能)。
< / LI> 醇>关于步骤2和5,我为我的应用做的是保持名为'APP_INITIALISED'的SharedPreference值默认为false。每次我的应用程序启动时,如果'APP_INITIALISED'为false,我告诉Google RESTORE_TRANSACTION(步骤2)然后我将APP_INITIALISED设置为true(步骤5)。
答案 1 :(得分:0)
我不确定,但我认为,在调用restoreTransactions()之后,将使用购买项目的ID调用onPurchaseStateChange。
答案 2 :(得分: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());
答案 3 :(得分: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":"*"
}
]
}