实施应用内结算

时间:2014-08-13 07:55:39

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

我目前正在我的应用程序中购买应用程序,当它启动时我总是在我到达IabHelper.QueryInventoryFinishedListener方法时查询错误代码-1003查询所拥有的项目响应签名验证失败。

我目前使用的是Google“Trivial Drive”的示例版本,我猜我的签名是正确的,因为当我使用android.app.purchassed时,我会购买很多......

关键似乎对我来说是正确的,因为当我点击喜欢购买的产品告诉我出版商无法购买本身正常的产品时(如果我放了任何东西,我还有另一个错误,说产品不存在) 。对于缺点,当我把测试产品“android.test.purchasse”时,我有同样的错误,然后我应该能够测试它。

我在那里用android.test.purchasse进行了购买,如果你已经成功我无法重置我感兴趣。

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

    // load game data
    loadData();

    String base64EncodedPublicKey = "MY_KEY_BASE64";

    PublicKey key = Security.generatePublicKey(base64EncodedPublicKey);
    // Create the helper, passing it our context and the public key to verify signatures with
    Log.d(TAG, "Creating IAB helper.");
    mHelper = new IabHelper(this, base64EncodedPublicKey);

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

    // Start setup. This is asynchronous and the specified listener
    // will be called once setup completes.
    Log.d(TAG, "Starting setup.");
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            Log.d(TAG, "Setup finished.");

            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                complain("Problem setting up in-app billing: " + result);
                return;
            }

            // 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.
            Log.d(TAG, "Setup successful. Querying inventory.");
            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) {
        Log.d(TAG, "Query inventory finished.");

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

        // Is it a failure?
        if (result.isFailure()) {
            complain("Failed to query inventory: " + result);
            return;
        }

        Log.d(TAG, "Query inventory was successful.");

        /*
         * Check for items we own. Notice that for each purchase, we check
         * the developer payload to see if it's correct! See
         * verifyDeveloperPayload().
         */
        if(inventory.hasPurchase(SKU_GAS))
        {
            Toast.makeText(getApplicationContext(),"PREMIUM",Toast.LENGTH_SHORT).show();
        }else{
            Toast.makeText(getApplicationContext(),"NOT PREMIUM", Toast.LENGTH_SHORT).show();
        }


        // Do we have the premium upgrade?
        Purchase premiumPurchase = inventory.getPurchase(SKU_PREMIUM);
        mIsPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
        Log.d(TAG, "User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM"));

        // Do we have the infinite gas plan?
        Purchase infiniteGasPurchase = inventory.getPurchase(SKU_INFINITE_GAS);
        mSubscribedToInfiniteGas = (infiniteGasPurchase != null && verifyDeveloperPayload(infiniteGasPurchase));
        Log.d(TAG, "User " + (mSubscribedToInfiniteGas ? "HAS" : "DOES NOT HAVE")
                    + " infinite gas subscription.");
        if (mSubscribedToInfiniteGas) mTank = TANK_MAX;

        // Check for gas delivery -- if we own gas, we should fill up the tank immediately
        Purchase gasPurchase = inventory.getPurchase(SKU_GAS);
        if (gasPurchase != null && verifyDeveloperPayload(gasPurchase)) {
            Log.d(TAG, "We have gas. Consuming it.");
            mHelper.consumeAsync(inventory.getPurchase(SKU_GAS), mConsumeFinishedListener);
            return;
        }

        updateUi();
        setWaitScreen(false);
        Log.d(TAG, "Initial inventory query finished; enabling main UI.");
    }
};
你有没有担心过?我认为没有办法解决这个错误的帮助你将不胜感激。

谢谢

1 个答案:

答案 0 :(得分:2)

您需要创建一个测试帐户,并将其放在Playstore管理页面中。

相关问题