当前位置: 首页 > 面试题库 >

Google Android应用内购买“内容交付”如何正确交付内容?

毕衡
2023-03-14
问题内容

我目前正在尝试编写应用内购买代码。我一直在寻找有关Google无法解决的某些问题的最佳做法的文档,信息和教程。

到目前为止,我所做的是:

我正在运行一个结算服务,可以处理与Google Play的通话。该服务可以完成“示例”交易,我的应用程序会收到该消息。

我现在想将内容传送到设备。我认为接下来需要发生的事情:

  1. 我的应用程序需要与我的服务器联系,并显示成功交易的证明。做一些Cert的手摇晃或者说些废话。

  2. 然后,我将下载内容并将其放入数据库中。我可能应该使用某种设备唯一的加密来加密数据库

我正在寻找学习如何做上述2件事以及需要做的其他事情。我想要合理数量的安全性/加密。任何文档/教程/示例项目都很棒,我试图搜索这些东西,但是没有找到我想要的东西。


问题答案:

您必须对示例中的计费服务客户端代码进行一些更改。

首先,您应该调用服务器以获取将被用于RestoreTransactions或进行购买的随机数,以使事情尽可能安全。

让我们跟随发生的事情。这是Google Play调用的BillingReceiver:

/**
 * This is called when Android Market sends information about a purchase state
 * change. The signedData parameter is a plaintext JSON string that is
 * signed by the server with the developer's private key. The signature
 * for the signed data is passed in the signature parameter.
 * @param context the context
 * @param signedData the (unencrypted) JSON string
 * @param signature the signature for the signedData
 */
private void purchaseStateChanged(Context context, String signedData, String signature) {
    Intent intent = new Intent(Consts.ACTION_PURCHASE_STATE_CHANGED);
    intent.setClass(context, BillingService.class);
    intent.putExtra(Consts.INAPP_SIGNED_DATA, signedData);
    intent.putExtra(Consts.INAPP_SIGNATURE, signature);
    context.startService(intent);
}

如果查看BillingService.java中的handleCommand,它将处理此意图:

/**
 * The {@link BillingReceiver} sends messages to this service using intents.
 * Each intent has an action and some extra arguments specific to that action.
 * @param intent the intent containing one of the supported actions
 * @param startId an identifier for the invocation instance of this service
 */
public void handleCommand(Intent intent, int startId) {
    String action = intent.getAction();
    if (Consts.DEBUG) {
        Log.i(TAG, "handleCommand() action: " + action);
    }
    if (Consts.ACTION_CONFIRM_NOTIFICATION.equals(action)) {
        String[] notifyIds = intent.getStringArrayExtra(Consts.NOTIFICATION_ID);
        confirmNotifications(startId, notifyIds);
    } else if (Consts.ACTION_GET_PURCHASE_INFORMATION.equals(action)) {
        String notifyId = intent.getStringExtra(Consts.NOTIFICATION_ID);
        getPurchaseInformation(startId, new String[] { notifyId });
    } else if (Consts.ACTION_PURCHASE_STATE_CHANGED.equals(action)) {
        String signedData = intent.getStringExtra(Consts.INAPP_SIGNED_DATA);
        String signature = intent.getStringExtra(Consts.INAPP_SIGNATURE);
        purchaseStateChanged(startId, signedData, signature);
    } else if (Consts.ACTION_RESPONSE_CODE.equals(action)) {
        long requestId = intent.getLongExtra(Consts.INAPP_REQUEST_ID, -1);
        int responseCodeIndex = intent.getIntExtra(Consts.INAPP_RESPONSE_CODE,
                ResponseCode.RESULT_ERROR.ordinal());
        ResponseCode responseCode = ResponseCode.valueOf(responseCodeIndex);
        checkResponseCode(requestId, responseCode);
    }
}

然后调用PurchaseStateChanged函数。该功能应由对服务器的调用代替,以创建用于内容传递的会话。应该将Security.java中的代码移植到服务器端,以验证云中的事务。

/**
 * Verifies that the data was signed with the given signature, and calls
 * {@link ResponseHandler#purchaseResponse(Context, PurchaseState, String, String, long)}
 * for each verified purchase.
 * @param startId an identifier for the invocation instance of this service
 * @param signedData the signed JSON string (signed, not encrypted)
 * @param signature the signature for the data, signed with the private key
 */
private void purchaseStateChanged(int startId, String signedData, String signature) {
    ArrayList<Security.VerifiedPurchase> purchases;
    purchases = Security.verifyPurchase(signedData, signature);
    if (purchases == null) {
        return;
    }

    ArrayList<String> notifyList = new ArrayList<String>();
    for (VerifiedPurchase vp : purchases) {
        if (vp.notificationId != null) {
            notifyList.add(vp.notificationId);
        }
        ResponseHandler.purchaseResponse(this, vp.purchaseState, vp.productId,
                vp.orderId, vp.purchaseTime, vp.developerPayload);
    }
    if (!notifyList.isEmpty()) {
        String[] notifyIds = notifyList.toArray(new String[notifyList.size()]);
        confirmNotifications(startId, notifyIds);
    }
}

确保将公共密钥放在已移植的Security.java文件中的服务器端。



 类似资料:
  • 我已经用这个phonegap插件实现了应用内计费V3。当我购买物品时,google play会返回以下信息: 这很可能是某个地方的设置问题,但我找不到问题所在。 这是我到目前为止所做的: 在google play上创建并以价格活跃的项目 查询的物品ID和google play上的一样 在alpha通道上传了我的apk(也尝试过beta通道),它处于“在Alpha中草稿”状态 等了几个小时(48小时

  • 此内容需要开通VIP会员才能阅读 您在其它地方或许也能找到类似资料,但是需要花费大量的时间,本站所有付费内容都是精心整理,重点应对技能提升和大厂面试。 您可以通过点击下面的按钮开通会员>>

  • 准备工作 付费应用协议 如果你还没有,你需要在 iTunes Connect 签署付费应用协议, 并设置您的银行和税务信息。 iTunes Connect 开发人员帮助: 协议、税务和银行概述 创建您的应用内购买 然后,您需要在iTunes Connect中配置您的应用内购买,并包含名称,定价和说明等详细信息,以突出显示您的应用内购买的功能。 iTunes Connect开发人员帮助:创建应用程序

  • 本文向大家介绍详解iOS应用程序内购/内付费(一),包括了详解iOS应用程序内购/内付费(一)的使用技巧和注意事项,需要的朋友参考一下 很久之前就想出一篇iOS内付费的教程,但是一查网上的教程实在太多了,有的写得真的蛮不错的,就心想算了,于是就保存在草稿箱了。至于为什么写完它呢!真是说来话长,最近公司有个项目经理跑来问我有关苹果内付费相关的细节,跟他聊了半天,从项目对接苹果官方支付接口聊到了如何查

  • 这个问题(Android应用内计费动态产品列表)是3年前问过的。动态的应用内购买项目在Android上还是不可用的吗? 我之所以要实现这种功能,是因为我的应用程序提供了一种让某些用户创建自己的应用内购买的方式,供其他人购买。

  • 我在google play store中有一个应用程序,在添加计费3V以处理订阅时遇到了一些问题。任何新的订阅者在付款和付款完成并出现在谷歌控制台后都无法访问我的应用程序。 我希望能在我的应用程序中帮助我处理应用程序内购买,代码如下: public static void isUserHasSubscription(Context Context,onCheck onCheck){BillingC