Google Play应用内结算V3 - 错误 - 需要进行身份验证

时间:2015-08-22 17:04:35

标签: android in-app-purchase google-play payment in-app-billing

关于同样的问题,我在SO上看过其他类似的问题,并且都指向同一点。检查产品的ID。我是第一次实现应用内购买,我想我在代码中使用了正确的产品ID。我正在关注TrivialDrive示例。

所以,错误如下:

enter image description here

我的Google Play产品ID:

enter image description here

我的代码如下:

package com.xx.xxx;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.xx.xxx.util.IabHelper;
import com.xx.xxx.util.IabResult;
import com.xx.xxx.util.Inventory;
import com.xx.xxx.util.Purchase;

public class UpgradeDonateActivity extends AppCompatActivity {

    private String base64EncodedPublicKey = "PUBLIC_KEY_REPLACED";
    private static final int PURCHASE_RESPONSE = 1;
    private static final String PURCHASE_TOKEN = "purchase_token";


    private static final String SKU_UPGRADE_2 = "test";
    //private static final String SKU_UPGRADE = "Upgrade";
    private static final String SKU_DONATE_10 = "donate_10";
    private static final String SKU_DONATE_5 = "donate_5";
    private static final String SKU_DONATE_3 = "donate_3";
    private static final String SKU_DONATE_2 = "donate_2";

    private boolean mIsUpgraded = false;

    private Toolbar toolbar;
    private TextView title;

    private IabHelper mIabHelper;
    private Button btnUpgrade;


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

            Log.d(Const.DEBUG, "Query inventory finished");

            if (mIabHelper == null) return;

            if (result.isFailure()) {
                // Handle failure
                Toast.makeText(UpgradeDonateActivity.this, "onQueryInventoryFinished Failed", Toast.LENGTH_LONG).show();
                return;
            }

            Log.d(Const.DEBUG, "Query inventory successful");

            Purchase upgradePurchase = inventory.getPurchase(SKU_UPGRADE_2);
            mIsUpgraded = (upgradePurchase != null && verifyDeveloperPayload(upgradePurchase));
            Log.d(Const.DEBUG, "User is " + (mIsUpgraded ? "Upgraded" : "Not Upgraded"));
        }
    };


    boolean verifyDeveloperPayload(Purchase p) {
        String payload = p.getDeveloperPayload();
        return true;
    }


    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
            = new IabHelper.OnIabPurchaseFinishedListener() {
        public void onIabPurchaseFinished(IabResult result,
                                          Purchase purchase) {


            Log.d(Const.DEBUG, "Purchase finished: " + result + ", purchase: " + purchase);

            if(mIabHelper == null) return;

            if (result.isFailure()) {
                // Handle error
                Log.d(Const.DEBUG, "Error Purchasing: "+result);
                return;
            }

            if(!verifyDeveloperPayload(purchase)) {
                Log.d(Const.DEBUG, "Error purchasing. Authenticity verification failed.");
                return;
            }

            Log.d(Const.DEBUG, "Purchase successful.");

            if(purchase.getSku().equals(SKU_UPGRADE_2)) {
                Log.d(Const.DEBUG, "Purchase is upgrade. Congratulating user.");
                mIsUpgraded = true;
            }

        }
    };


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

                    if (result.isSuccess()) {
                        //clickButton.setEnabled(true);
                        Toast.makeText(UpgradeDonateActivity.this, "", Toast.LENGTH_LONG).show();
                    } else {
                        // handle error
                        Toast.makeText(UpgradeDonateActivity.this, "Error", Toast.LENGTH_LONG).show();
                    }
                }
            };


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

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        title = (TextView) toolbar.findViewById(R.id.toolbar_title);
        title.setText("");

        setSupportActionBar(toolbar);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);


        btnUpgrade = (Button) findViewById(R.id.button_upgrade);
        btnUpgrade.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                mIabHelper = new IabHelper(UpgradeDonateActivity.this, base64EncodedPublicKey);
                mIabHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
                    @Override
                    public void onIabSetupFinished(IabResult result) {
                        if (!result.isSuccess()) {
                            Log.d(Const.DEBUG, "In-app Billing setup Failed");
                        } else {
                            Log.d(Const.DEBUG, "In-app Billing setup OK");
                            Toast.makeText(UpgradeDonateActivity.this, "In-app Billing setup OK", Toast.LENGTH_SHORT).show();

                            mIabHelper.launchPurchaseFlow(UpgradeDonateActivity.this, SKU_UPGRADE_2, PURCHASE_RESPONSE, mPurchaseFinishedListener, PURCHASE_TOKEN);
                        }
                    }
                });
            }
        });
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d(Const.DEBUG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
        if (mIabHelper == null) return;

        // Pass on the activity result to the helper for handling
        if (!mIabHelper.handleActivityResult(requestCode, resultCode, data)) {
            // not handled, so handle it ourselves (here's where you'd
            // perform any handling of activity results not related to in-app
            // billing...
            super.onActivityResult(requestCode, resultCode, data);
        } else {
            Log.d(Const.DEBUG, "onActivityResult handled by IABUtil.");
        }
    }


    public void consumeItem() {
        mIabHelper.queryInventoryAsync(mGotInventoryListener);
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mIabHelper != null) mIabHelper.dispose();
        mIabHelper = null;
    }
}

有谁能告诉我在这种情况下我做错了什么?我该如何解决?

2 个答案:

答案 0 :(得分:1)

确保您的.apk具有适当的结算(和正确的权限)已发布(是alpha)并允许Google Play吸收新的.apk一段时间,可能是几个小时。

此外,请确保当前开发版本中的应用程序版本代码与已发布的已启用结算的版本中的应用程序版本代码相同。

答案 1 :(得分:1)

在ALPHA TESTING中的上传APK页面上有一个链接"选择加入URL"。去那里接受使用测试帐户成为测试人员。 麻生太郎,这是一个有用的清单https://stackoverflow.com/a/22469253/1819570