【问题标题】:Implementing In-app Billing实施应用内结算
【发布时间】:2014-08-13 07:55:39
【问题描述】:

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

我目前使用的是谷歌“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.");
    }
};

你有没有担心过?我认为您的此错误帮助没有出路,我们将不胜感激。

谢谢

【问题讨论】:

  • 上述问题你找到解决办法了吗?

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    • 2016-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多