Google IAP响应:-1003:购买签名验证失败

时间:2015-09-07 21:08:15

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

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

这是我的主LAUNCHER活动中的代码。我使用 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更改了verifyPurchase(String base64PublicKey, String signedData, String signature)中的Security.java功能

1 个答案:

答案 0 :(得分:0)

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