栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

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

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

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,它将处理此意图:

public void handleCommand(Intent intent, int startId) {    String action = intent.getAction();    if (Consts.DEBUG) {        Log.i(TAG, "handleCommand() action: " + action);    }    if (Consts.ACTION_/confirm/i_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中的代码移植到服务器端,以验证云中的事务。

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文件中的服务器端。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/454462.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号