简体   繁体   English

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

[英]Google IAP response: -1003:Purchase signature verification failed

My goal here is to implement an In-app purchase in my app and also to check if Users owns an item as each app launch. 我的目标是在应用中实施应用内购买,并在每次启动应用时检查用户是否拥有商品。 Below is what I have tried so far and the issue I am seeing. 以下是到目前为止我已经尝试过的以及正在遇到的问题。

This is the code in my main LAUNCHER Activity. 这是我主要的LAUNCHER活动中的代码。 I am using android.test.purchased as my ITEM_SKU (is this a problem?) to test the in-app purchase locally. 我使用android.test.purchased作为我的ITEM_SKU(这是问题吗?)在本地测试应用内购买。 It did work once initially and since them I am getting this error inside onQueryInventoryFinished : Failed to query inventory: IabResult: Error refreshing inventory (querying owned items). 最初它确实工作过一次,并且由于它们,我在onQueryInventoryFinished遇到此错误: 无法查询库存:IabResult:刷新库存(查询拥有的物品)时出错。 (response: -1003:Purchase signature verification failed) (响应:-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();
}

I have changed the function verifyPurchase(String base64PublicKey, String signedData, String signature) in Security.java as per this thread 我已经根据此线程Security.java更改了函数verifyPurchase(String base64PublicKey, String signedData, String signature)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM