我正在实现新的计费API2.0,它具有这个购买确认方法。早些时候,我使用AIDL进行购买,我有以下用例:我在发起购买时传递开发人员负载,并在响应中将开发人员负载作为购买对象的一部分返回。
Bundle bundle = mService.getBuyIntent(3, "com.example.myapp",
MY_SKU, "subs", developerPayload);
PendingIntent pendingIntent = bundle.getParcelable(RESPONSE_BUY_INTENT);
if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_OK) {
// Start purchase flow (this brings up the Google Play UI).
// Result will be delivered through onActivityResult().
startIntentSenderForResult(pendingIntent, RC_BUY, new Intent(),
Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
}
在我的on activity结果中,我用来获取购买对象
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1001) {
int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
if (resultCode == RESULT_OK) {
try {
JSONObject jo = new JSONObject(purchaseData);
String sku = jo.getString("productId");
alert("You have bought the " + sku + ". Excellent choice,
adventurer!");
}
catch (JSONException e) {
alert("Failed to parse purchase data.");
e.printStackTrace();
}
}
}
}
这个购买对象有一个开发人员负载,我将其发送到服务器进行验证。
现在,在新的API中,只有在购买完成之后或者当我们消费购买时,才能添加开发人员负载,所以问题是在确认购买之后,我需要更新的购买对象,但是如何获取它的
if (!purchase.isAcknowledged()) {
AcknowledgePurchaseParams acknowledgePurchaseParams =
AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken(purchase.getPurchaseToken())
.setDeveloperPayload(/* my payload */)
.build();
client.acknowledgePurchase(acknowledgePurchaseParams, acknowledgePurchaseResponseListener);
}
在acknowledgePurchaseResponseListener中,无论是成功还是失败,我只得到响应代码。但是我需要用developerPayload和isAcknowledged标记为真来更新购买对象对象。
有没有办法做到这一点?在文档中找不到任何内容。
发布于 2019-06-06 05:44:02
本地购买缓存在调用acknowledgePurchaseResponseListener时更新,因此您可以使用https://developer.android.com/reference/com/android/billingclient/api/BillingClient.html#querypurchases从缓存中查询购买。我们将考虑在将来的库版本中将更新购买添加到侦听器中,以使这一点更方便。
https://stackoverflow.com/questions/56382436
复制相似问题