Google InApp结算测试购买
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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);
}
另一答案
InApp仅购买并且仅适用于生产应用程序,因此您必须获得已签名的apk并将其上传到播放控制台上的alpha测试。
这些步骤可以帮助您:
https://stackoverflow.com/a/47899233/2813804
以上是关于Google InApp结算测试购买的主要内容,如果未能解决你的问题,请参考以下文章
如何解决 iTunes/InApp 购买的错误代码 -1202?
使用Google Play计费库和系统会在3天之内退还Inapp产品的退款