java– 谷歌Android应用程序内购买“内容交付”如何正确传递内容?

java– 谷歌Android应用程序内购买“内容交付”如何正确传递内容?,第1张

概述我目前正在尝试编写应用内购买代码.我正在寻找有关谷歌无法处理的一些东西的最佳实践的文档,信息和教程.到目前为止我做了什么:我有一个运行结算服务来处理与GooglePlay的通话.此服务可以完成“示例”事务,我的应用程序会收到消息.我现在要将内容传送到设备.我认为接下来需要发

我目前正在尝试编写应用内购买代码.我正在寻找有关谷歌无法处理的一些东西的最佳实践的文档,信息和教程.

到目前为止我做了什么:

我有一个运行结算服务来处理与Google Play的通话.此服务可以完成“示例”事务,我的应用程序会收到消息.

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

>我的应用程序需要联系我的服务器并显示成功交易的一些证据.做一些证书手摇或一些这样的废话.
>然后我将下载内容并将该内容放入数据库.我应该使用某种设备唯一的加密来加密数据库.

我正在寻找学习如何做上述事情和其他任何需要做的事情.我想要一个合理数量的安全/加密.任何文档/教程/示例项目都会很棒,我已经尝试过搜索这些东西并且找不到我想要的东西.

解决方法:

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

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

让我们来看看会发生什么.以下是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);    }}

然后调用thePurchaseStateChanged函数.应该通过调用服务器来替换此功能,以便为内容交付创建会话.应将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文件中的服务器端.

总结

以上是内存溢出为你收集整理的java – 谷歌Android应用程序内购买“内容交付”如何正确传递内容?全部内容,希望文章能够帮你解决java – 谷歌Android应用程序内购买“内容交付”如何正确传递内容?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1118865.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存