认购示例中缺少purchaseToken的JSON解析 [英] Subscription sample missing JSON parsing of purchaseToken

查看:382
本文介绍了认购示例中缺少purchaseToken的JSON解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近已经研究code的应用内账单V2。并发现它的一些问题。 我刚才实现应用内账单,但希望升级到订阅。在我的研究,我发现,购买令牌是:收到沿对成功购买认购的JSON(签名数据)。

I have been recently studying code for In-App-Billing v2. And have found some issues with it. I have earlier implemented In-App-Billing but wish to upgrade to subscription. On my research I found that Purchase token is recieved along with the JSON(Signed data) on successful purchase for subscription.

该演示的 Security.java 标签上的签名验证成功解析的Json但元购买令牌是在这里失踪的解析。

The demo's Security.java on successful verification of signature parses Json however the parsing of element Purchase-token is missing here.

            JSONObject jElement = jTransactionsArray.getJSONObject(i);
            int response = jElement.getInt("purchaseState");
            PurchaseState purchaseState = PurchaseState.valueOf(response);
            String productId = jElement.getString("productId");
            String packageName = jElement.getString("packageName");
            long purchaseTime = jElement.getLong("purchaseTime");
            String orderId = jElement.optString("orderId", "");
            String notifyId = null;
//          purchaseToken part that I have added
            String purchaseToken = jElement.optString("purchaseToken", "");

我还没有运行code由于认购不具备测试产品ID和需要实际purchase.What我想知道的是这个道理在这里分析或者是提供的样品code的这部分正确实施。

I haven't yet run the code since subscription doesn't have test product-ids and requires actual purchase.What I want to know is this token be parsed here or is the sample code provided has this part correctly implemented.

推荐答案

文森特,这是正确的。您必须修改Security.java以及BillingService.java和ResponseHandler.java如果你需要purhcaseToken进行验证。

Vincent, that is correct. You have to modify Security.java as well as BillingService.java and ResponseHandler.java if you need the purhcaseToken to be validated.

这是:

Security.java:

Security.java:

public PurchaseState    purchaseState;
public String           notificationId;
public String           productId;
public String           orderId;
public long             purchaseTime;
public String           developerPayload;
public String           purchaseToken;
public String           packageName;

public VerifiedPurchase(PurchaseState purchaseState, String notificationId, String productId, String orderId, long purchaseTime,
        String developerPayload, String purchaseToken, String packageName) {
    this.purchaseState = purchaseState;
    this.notificationId = notificationId;
    this.productId = productId;
    this.orderId = orderId;
    this.purchaseTime = purchaseTime;
    this.developerPayload = developerPayload;
    this.purchaseToken = purchaseToken;
    this.packageName = packageName;
    }
}

现在在VerifyPurchase:

Now in VerifyPurchase:

String developerPayload = jElement.optString("developerPayload", null);
// VK: Changes to parse the purchaseToken
String purchaseToken = jElement.optString("purchaseToken", null);

BillingService.java:

BillingService.java:

在purchaseStateChanged,修改

In purchaseStateChanged, modify:

ResponseHandler.purchaseResponse(this, vp.purchaseState, vp.productId, vp.orderId, vp.purchaseTime, vp.developerPayload, vp.purchaseToken, vp.packageName);

ResponseHandler.java:

ResponseHandler.java:

最后,更改为purchaseResponse的定义:

Finally, change the definition of purchaseResponse to:

public static void purchaseResponse(final Context context, final PurchaseState purchaseState, final String productId, final String orderId, final long purchaseTime, final String developerPayload, final String purchaseToken,final String packageName)

在这里,你可以让你的应用程序相关的逻辑变化,你在这里将有purchaseToken。

Here you can make your app related logic changes as you here will have the purchaseToken.

如果一切正常,请收下!

If everything works, please accept!

这篇关于认购示例中缺少purchaseToken的JSON解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆