如何使用base64进行应用内结算?

时间:2019-07-01 11:03:09

标签: java android android-pay android-billing

几天来我一直在尝试对工作车间系统进行编程,但是我发现Billing Client未连接。 此处的Toast消息是连接到结算时出错。

错误在哪里?

我需要帮助课程吗?在许多说明中,据说您可以使用帮助类,但不必这样做。

如果购买了Aktikel,则有可能在每篇文章中执行另一种代码吗?

我想提供六种用户可以购买的数字产品。

感谢您的帮助。

这是我的ShopActivity.class代码:

public class ShopActivity extends AppCompatActivity implements PurchasesUpdatedListener {

    private BillingClient billingClient;
    Button loadProdukt;
    RecyclerView recyclerProdukt;
    // IabHelper mHelper;

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

        // String base64EncodedPublicKey = "_BASE64_KEY_";
        // mHelper = new IabHelper(this, base64EncodedPublicKey);
        // TODO 01.07.2019 IabHelper?

        setupBillingClient();

        loadProdukt = findViewById(R.id.btn_load_produkt);
        recyclerProdukt = findViewById(R.id.recycler_view_paket);
        recyclerProdukt.setHasFixedSize(true);
        recyclerProdukt.setLayoutManager(new LinearLayoutManager(this));

        // event
        loadProdukt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(billingClient.isReady()){
                    SkuDetailsParams params = SkuDetailsParams.newBuilder()
                            .setSkusList(Arrays.asList("10_coins","20_coins","30_coins","40_coins","80_coins","200_coins"))
                            .setType(BillingClient.SkuType.INAPP)
                            .build();

                    billingClient.querySkuDetailsAsync(params, new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {

                            if (billingResult.getResponseCode() == BilllingResonse.OK) {
                                loadProduktToRecyclerView(skuDetailsList);
                            }else{
                                Toast.makeText(ShopActivity.this, "Cannot query product", Toast.LENGTH_SHORT).show();
                            }
                        }
                    });

                }else{
                    Toast.makeText(ShopActivity.this, "Billing not ready", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    private void loadProduktToRecyclerView(List<SkuDetails> skuDetailsList) {
        ProduktAdapter adapter = new ProduktAdapter(this, skuDetailsList,billingClient);
        recyclerProdukt.setAdapter(adapter);
    }

    private void setupBillingClient() {

        // billingClient = BillingClient.newBuilder(this).enablePendingPurchases().setListener(this).build();
        billingClient = BillingClient.newBuilder(this).setListener(this).build();
        billingClient.startConnection(new BillingClientStateListener() {
            @Override
            public void onBillingSetupFinished(BillingResult billingResult) {

                if (billingResult.getResponseCode() == BilllingResonse.OK) {
                    Toast.makeText(ShopActivity.this, "Success to connect Billing", Toast.LENGTH_SHORT).show();
                }
                else {
                    Toast.makeText(ShopActivity.this, "Error not connect to Billing", Toast.LENGTH_SHORT).show();
                }
            }


            @Override
            public void onBillingServiceDisconnected() {
                Toast.makeText(ShopActivity.this, "You are disconnect.", Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public void onPurchasesUpdated(BillingResult billingResult, @Nullable List<Purchase> purchases) {
    // if user click Buy, we will retrieve data here
        Toast.makeText(this, "Purchase item: "+purchases.size(), Toast.LENGTH_SHORT).show();

        if (billingResult.getResponseCode() == BillingResponse.OK && purchases != null) {
            for ( Purchase purchases : purchases) {
                handlePurchase (purchases);
            }
        }else if (billingResult.getResponseCode() == BillingResponse.USER_CANCELED) {

        }else{

        }
    }
}

1 个答案:

答案 0 :(得分:1)

AIDL 已被弃用,Google Play Billing Library