【问题标题】:Google IAP response: -1003:Purchase signature verification failedGoogle IAP 响应:-1003:购买签名验证失败
【发布时间】:2015-09-07 21:08:15
【问题描述】:

我的目标是在我的应用中实现应用内购买,并在每次应用启动时检查用户是否拥有一个项目。以下是我迄今为止尝试过的以及我看到的问题。

这是我的主要LAUNCHER Activity 中的代码。我使用 android.test.purchased 作为我的 ITEM_SKU(这是一个问题吗?)在本地测试应用内购买。它最初确实工作过一次,因为它们我在onQueryInventoryFinished 中收到此错误:无法查询库存:IabResult:刷新库存时出错(查询拥有的物品)。 (响应:-1003:购买签名验证失败)

// Does the user have the premium upgrade?
boolean mIsaddFree = false;
private AdView adView;

private static final String TAG = "com.example.inappbilling";
IabHelper mHelper;
static final String ITEM_SKU = "android.test.purchased";

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();
        }

    }
};


IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener
        = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result,
                                         Inventory inventory) {

        mLog.printToLog(className + " -> " + MethodName.methodName() + ": Query inventory finished.");
        // Have we been disposed of in the meantime? If so, quit.
        if (mHelper == null) return;

        if (result.isFailure()) {
            mLog.printToLog(className + " -> " + MethodName.methodName() + "Failed to query inventory: " + result);
        } else {


            if (inventory.hasPurchase(ITEM_SKU)) {mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU),mConsumeFinishedListener);
            } else {
            }

        }

        // Do we have the addFree upgrade?
        Purchase premiumPurchase = inventory.getPurchase(ITEM_SKU);
        mIsaddFree = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));

    }
};

IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
        new IabHelper.OnConsumeFinishedListener() {
            public void onConsumeFinished(Purchase purchase,
                                          IabResult result) {


                if (result.isSuccess()) {
                } else {
                    // handle error
                }
            }
        };

/**
 * Verifies the developer payload of a purchase.
 */
boolean verifyDeveloperPayload(Purchase p) {
    String payload = p.getDeveloperPayload();
    return true;
}

public void consumeItem() {
    mHelper.queryInventoryAsync(mReceivedInventoryListener);
}

private void setupIAB() {
    String base64EncodedPublicKey =
            "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgQEbYA2GEYavRb1oZz9aMyn86Wj09NCqFRbD936uKLJHKSDFdsfsdfklndfHKJHJKAHFKJDSFskdsfkjnsdfjkKJNJKSDF9ZclxWM3EuZTMM3kWDUfOnS0+u8c/Uq727cLBRqnRJy5pfWFZtPqXwAN4yaeCgxGka6eofn0jj7RxPEFJZLkFw2Ijvxl2uMIHSlxIvl+6ZwMtOKJHSDKJFHNDSllkadndfkasdlkasdlkasBOaBLKWFYY2to8g3aRx1HVTxLSi9Ms3KPMM3uPbbElCbKoIiqcNwIDAQAB";

    // Create the helper, passing it our context and the public key to verify signatures with
    mLog.printToLog(className + " -> " + MethodName.methodName() + ": Creating IAB helper.");
    mHelper = new IabHelper(this, base64EncodedPublicKey);

    // enable debug logging (for a production application, you should set this to false).
    mHelper.enableDebugLogging(!Constants.C_PRODUCTION_MODE);

    mHelper.startSetup(new
                               IabHelper.OnIabSetupFinishedListener() {
                                   public void onIabSetupFinished(IabResult result) {
                                       if (!result.isSuccess()) {
                                           return;
                                       } else {
                                           mLog.printToLog(className + " -> " + MethodName.methodName() + ": Passed, result.isSuccess() = TRUE");


                                           // Have we been disposed of in the meantime? If so, quit.
                                           if (mHelper == null) return;

                                           // IAB is fully set up. Now, let's get an inventory of stuff we own.
                                           mHelper.queryInventoryAsync(mGotInventoryListener);
                                       }
                                   }
                               });


}


/**
 * 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.
        if (mHelper == null) return;

        // Is it a failure?
        if (result.isFailure()) {
            return;
        }

        // Do we have the premium upgrade?
        Purchase adFreePurchase = inventory.getPurchase(ITEM_SKU);
        mIsaddFree = (adFreePurchase != null && verifyDeveloperPayload(adFreePurchase));


    }
};


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setupIAB();
}

我已经按照this thread更改了Security.java中的函数verifyPurchase(String base64PublicKey, String signedData, String signature)

【问题讨论】:

  • 您使用的是哪种构建类型?您只能从 PlayStore 签名的 apk 中获取项目,而不是调试一个
  • Buildtype i DEBUG 当前,但我在 Play 商店中没有商品。我正在开发一个新的应用程序。使用 android.test.purchased 作为 SKU 是否有问题?

标签: android in-app-purchase in-app-billing billing android-billing


【解决方案1】:

您需要在测试期间跳过验证过程或从验证签名方法发送 true,因为一旦您使用未签名的测试 ID 购买,就会出现此错误

【讨论】:

    猜你喜欢
    • 2014-07-18
    • 2020-04-08
    • 2013-01-14
    • 2023-03-22
    • 2016-12-06
    • 1970-01-01
    • 2014-01-31
    • 1970-01-01
    • 2013-11-12
    相关资源
    最近更新 更多