我正在尝试在我的 Android 应用程序中实现应用内购买。我正在使用应用内计费 API v3 来实现 IAP(应用内购买)。作为引用,我正在关注 Google 提供的 trivialdrive 示例。在 launchPurchaseFlow
方法中
public void launchPurchaseFlow(Activity act, String sku, String itemType, int requestCode,
OnIabPurchaseFinishedListener listener, String extraData) {
checkSetupDone("launchPurchaseFlow");
flagStartAsync("launchPurchaseFlow");
IabResult result;
if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) {
IabResult r = new IabResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE,
"Subscriptions are not available.");
if (listener != null) listener.onIabPurchaseFinished(r, null);
return;
}
try {
logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
Bundle buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData);
int response = getResponseCodeFromBundle(buyIntentBundle);
if (response != BILLING_RESPONSE_RESULT_OK) {
logError("Unable to buy item, Error response: " + getResponseDesc(response));
result = new IabResult(response, "Unable to buy item");
if (listener != null) listener.onIabPurchaseFinished(result, null);
return;
}
PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
logDebug("Launching buy intent for " + sku + ". Request code: " + requestCode);
mRequestCode = requestCode;
mPurchaseListener = listener;
mPurchasingItemType = itemType;
act.startIntentSenderForResult(pendingIntent.getIntentSender(),
requestCode, new Intent(),
Integer.valueOf(0), Integer.valueOf(0),
Integer.valueOf(0));
}
catch (SendIntentException e) {
logError("SendIntentException while launching purchase flow for sku " + sku);
e.printStackTrace();
result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
if (listener != null) listener.onIabPurchaseFinished(result, null);
}
catch (RemoteException e) {
logError("RemoteException while launching purchase flow for sku " + sku);
e.printStackTrace();
result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
if (listener != null) listener.onIabPurchaseFinished(result, null);
}
}
在上面的代码中,getBuyIntent
不期望 nonce
,我们有额外的数据,我们在其中传递 developerpayload(特定于每个购买项目)。
在这里我无法弄清楚如何传递随机数,因为它在 API V2 中传递并作为成功购买的响应收到。 V3不需要nonce
吗?
谢谢
最佳答案
使用 IAB API v3 时,只需使用您从 Google Play 收到的原始 JSON 响应,并使用签名和公共(public) RSA 对其执行 OpenSSL 验证。
您最好通过自己的 API 执行此检查,因为在您的应用程序中 bundle 公共(public) RSA key 是不安全的。 Here's a PHP sample for this OpenSSL verification.
如该示例所示,它只是从请求中获取参数:响应数据和签名,并使用公钥对其进行验证。
您只需篡改应用内和 API 上的原始 JSON 数据,以便与确定用户购买的内容相关,而不是验证购买本身的有效性。
简而言之:不用担心随机数。 IAB API v3 放弃了它,您不必担心它的缺失。
关于android - 如何在应用计费 API V3 中使用 Google 的随机数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15782889/