当我尝试获取订阅时,出现以下错误:
签名认证失败。签名与数据不匹配。应用内计费警告:购买签名验证失败。不添加项目。
我的代码是:
String base64EncodedPublicKey = MY_KEY;
// compute your public key and store it in base64EncodedPublicKey
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh noes, there was a problem.
MyDialogFragment alertDialog_generalError = MyDialogFragment.newInstance(getString(R.string.dialog_alert),getString(R.string.error_general));
alertDialog_generalError.show(getSupportFragmentManager(), DIALOG_GENERALERROR);
} //End if
mHelper.queryInventoryAsync(mGotInventoryListener);
}
});
//*************************************************
//Get App price
IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if (result.isFailure()) {
// handle error
MyDialogFragment alertDialog_generalError = MyDialogFragment.newInstance(getString(R.string.dialog_alert),getString(R.string.error_general));
alertDialog_generalError.show(getSupportFragmentManager(), DIALOG_GENERALERROR);
return;
}//End if
String premiumPrice = inventory.getSkuDetails(SKU_PREMIUM).getPrice();
btnPrice.setText(getResources().getString(R.string.btn_suscription) + " " + premiumPrice);
myProfile.setPriceApp(premiumPrice);
}
};
// //************************************
@Override
public void inapp() {
//myProfile.getGUID()
//mHelper.launchPurchaseFlow(this, SKU_PREMIUM, RC_REQUEST, mPurchaseFinishedListener, myProfile.getGUID() );
mHelper.launchSubscriptionPurchaseFlow(this, SKU_PREMIUM, RC_REQUEST, mPurchaseFinishedListener, myProfile.getGUID() );
}
//************************************
@Override
public void getPrice(Button btnPrice) {
Log.i(LOGTAG, "getPrice");
this.btnPrice = btnPrice;
List additionalSkuList = new ArrayList();
additionalSkuList.add(SKU_PREMIUM);
mHelper.queryInventoryAsync(true, additionalSkuList, mQueryFinishedListener);
}
//************************************************
// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
// if we were disposed of in the meantime, quit.
if (mHelper == null) return;
if (result.isFailure()) {
if (result.getResponse() != -1005){
MyDialogFragment alertDialog_errorInApp = MyDialogFragment.newInstance(getString(R.string.dialog_alert),getString(R.string.error_inApp));
alertDialog_errorInApp.show(getSupportFragmentManager(), DIALOG_GENERALERROR);
}
return;
}
if (!verifyDeveloperPayload(purchase)) {
MyDialogFragment alertDialog_errorInApp = MyDialogFragment.newInstance(getString(R.string.dialog_alert),getString(R.string.error_inApp));
alertDialog_errorInApp.show(getSupportFragmentManager(), DIALOG_GENERALERROR);
return;
}
myProfile.setIsPremium(1);
loginPrefsEditor.putInt("IsPremium", 1);
}
};
//**********************************
//User PREMIUM or NOT PREMIUM
// Listener that's called when we finish querying the items and subscriptions we own
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
// Have we been disposed of in the meantime? If so, quit.
Log.i(LOGTAG, result.getMessage());
//if (mHelper == null) return;
//Is it a failure?
if (result.isFailure()) {
MyDialogFragment alertDialog_generalError = MyDialogFragment.newInstance(getString(R.string.dialog_alert),getString(R.string.error_general));
alertDialog_generalError.show(getSupportFragmentManager(), DIALOG_GENERALERROR);
return;
}
/*
* Check for items we own. Notice that for each purchase, we check
* the developer payload to see if it's correct! See
* verifyDeveloperPayload().
*/
// Do we have the premium upgrade?
Purchase premiumPurchase = inventory.getPurchase(SKU_PREMIUM);
mIsPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
if (mIsPremium == true){
myProfile.setIsPremium(1);
loginPrefsEditor.putInt("IsPremium", 1);
}else{
loginPrefsEditor.putInt("IsPremium", 0);
myProfile.setIsPremium(0);
}//End if-else
}
};
//****************************************
/** Verifies the developer payload of a purchase. */
boolean verifyDeveloperPayload(Purchase p) {
String payload = p.getDeveloperPayload();
if (!payload.equals(myProfile.getGUID())){
return false;
}else{
return true;
}//End if-else
}
我从控制台开发人员那里获得了 base64EncodedPublicKey,并使用导出向导签署了我的项目。