【发布时间】:2019-05-30 16:52:01
【问题描述】:
我正在实施具有此购买确认方法的新 billing API 2.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));
}
在我的活动结果中,我曾经获得购买对象
@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 标志更新购买对象对象。
有没有办法做到这一点?在文档中找不到任何内容。
【问题讨论】:
标签: android in-app-billing android-billing