我想一遍又一遍地买同样的物品,但是当试图第二次买时,代码给我空指针异常。
这是代码;
session_start();
if (isset($_GET['hash']) && isset($_SESSION['hash']) &&
$_GET['hash'] == $_SESSION['hash']) {
header("Content-type: image/jpeg");
echo file_get_contents('your hidden image.jpg');
}
当此代码脚本再次运行时,pendinIntent将为null。
如果用户已购买上述代码
,我们可以要求谷歌try {
Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(), "ucret", "inapp", "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
} catch (RemoteException e) {
e.printStackTrace();
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
但是每当我打开屏幕时,我都想卖掉同样的物品。
感谢您的帮助。
答案 0 :(得分:1)
Google阻止用户购买相同的商品。所以,如果你这样做,你必须告诉谷歌"让我"。这被命名为#34;消费"。
这是所有消费方法
private void consumeBilling() {
try {
Bundle ownedItems = iInAppBillingService.getPurchases(3, getPackageName(), "inapp", null);
int response = ownedItems.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
ArrayList<String> purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
ArrayList<String> signatureList = ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE_LIST");
String continuationToken = ownedItems.getString("INAPP_CONTINUATION_TOKEN");
for (int i = 0; i < purchaseDataList.size(); ++i) {
String purchaseData = purchaseDataList.get(i);
// String signature = signatureList.get(i);
// String sku = ownedSkus.get(i);
// RDALogger.info("purchaseData " + purchaseData + " signature " + signature + " sku " + sku);
RDALogger.info("purchaseData " + purchaseData);
String purchaseTokenString = new JSONObject(purchaseData).getString("purchaseToken");
int responsee = iInAppBillingService.consumePurchase(3, getPackageName(), purchaseTokenString);
RDALogger.info("Consuming response " + responsee);
}
}
} catch (Exception e) {
e.printStackTrace();
ErrorHandlers.handle(PaymentActivity.this, new HoustonWeGotAProblemException());
}
}
来自purchaseData的PurschaseToken将转到此代码
int responsee = iInAppBillingService.consumePurchase(3, getPackageName(), purchaseTokenString);
之后你告诉谷歌,这个项目可以再次购买。