Google InApp结算测试购买

登山则情满于山,观海则意溢于海。这篇文章主要讲述Google InApp结算测试购买相关的知识,希望能为你提供帮助。
无法在测试购买模式下购买任何东西这是代码。当我在DialogFragment中单击YES时没有任何变化。但如果我尝试在发布APK购买一切都好。男人有什么问题?

public void StupidLogic(){ ITEM_SKU = "android.test.purchased"; mHelper.launchPurchaseFlow(getActivity(), ITEM_SKU, 10001, mPurchaseFinishedListener, "mytoken"); }IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() { public void onIabPurchaseFinished(IabResult result, Purchase purchase) { if (result.isFailure()) { // Handle error return; } else if (purchase.getSku().equals(ITEM_SKU)) { consumeItem(); }} }; public void consumeItem() { mHelper.queryInventoryAsync(mReceivedInventoryListener); }IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener = new IabHelper.QueryInventoryFinishedListener() { public void onQueryInventoryFinished(IabResult result, Inventory inventory) {if (result.isFailure()) { Log.d("Billing"," Such Failure! WOW!"); } else { mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU), mConsumeFinishedListener); } } }; IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() { public void onConsumeFinished(Purchase purchase, IabResult result) {if (result.isSuccess()) { //Приходящий ответ!!!!!-------------------------------------------------------------------------------------------- //String URL = "http://cybergenesis.ru/egor/add_service?ontime=" + ontimeString + "& offtime=" + offtimeString + "& user_id=" + info_id + "& service=" + Integer.toString(position + 1) + "& balance=" + String.valueOf(balance); Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://cybergenesis.ru/egor/") .addConverterFactory(GsonConverterFactory.create()) .build(); APIService service = retrofit.create(APIService.class); Call< Post> call = service.addService(ontimeString, offtimeString, info_id, positionStr, Balance); call.enqueue(new Callback< Post> () { @Override public void onResponse(Call< Post> call, retrofit2.Response< Post> response) {}@Override public void onFailure(Call< Post> call, Throwable t) {} }); } else { // handle error } } }; @Override public void onDestroy() { super.onDestroy(); if (mHelper != null) mHelper.dispose(); mHelper = null; }

}
如果我不在Dialog购买,那一切都好。
答案如果IAB在apk的签名发布版本中工作但在调试中没有,那么这可能是您的问题:
您应该修改Security.java文件以激活调试模式。这允许该方法在unsigned apks中工作。这仅用于调试,请记住在发布之前将其还原。
public static boolean verifyPurchase(String base64PublicKey, String signedData, String signature) { if (TextUtils.isEmpty(signedData) || TextUtils.isEmpty(base64PublicKey) || TextUtils.isEmpty(signature)) { Log.e(TAG, "Purchase verification failed: missing data."); if (BuildConfig.DEBUG) { return true; } return false; }PublicKey key = Security.generatePublicKey(base64PublicKey); return Security.verify(key, signedData, signature); }

Take a look at this
另一答案InApp仅购买并且仅适用于生产应用程序,因此您必须获得已签名的apk并将其上传到播放控制台上的alpha测试。
这些步骤可以帮助您:
【Google InApp结算测试购买】https://stackoverflow.com/a/47899233/2813804

    推荐阅读