2

我在编码付款时遇到问题。

这是一个网页游戏,这就是我希望付款的方式。

你到了一个网站,然后点击一个按钮(购买)。您将被重定向到一个站点,该站点会将购买信息发送到服务器,并将购买的物品添加到您的帐户中。在此之前,我们有一个 WebViewClient 来检查所有的 url。如果他找到一个用于购买的 url,他将发送购买请求。现在,如果我们从 android 市场收到一条成功的消息,他将继续进行重定向。

我对此很陌生,只是无法理解这些付款的概念。我使用地牢示例编写了我的代码。我试图根据我的需要调整它。如果有人能指出我正确的方向,我将不胜感激。Atm 我试图弄清楚如何获得成功购买的响应。假设我的其余代码没问题,它应该可以工作(我希望)。

我的项目文件中包含示例中的 BillingReciver.java、BillingSerivce.java、PurchaseObserver.java、ResponseHandler.java、Consts.java 和 Security.java。如果需要,我可以提供这些代码,但其中有很多,所以我希望已经看过该示例的人能够提供帮助。


在与一些人进行一些研究和咨询后,我发现了我需要的东西:

     /**
     * 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);
       }

我需要从我的应用程序将从 android 市场获得的 JSON 字符串中获取数据。任何人都知道如何做到这一点?

4

2 回答 2

2

2011 年 11 月 17 日 21:56 @Grzegorz 'Gatz' Siennicki 写道:

我需要从我的应用程序将从 android 市场获得的 JSON 字符串中获取数据。任何人都知道如何做到这一点?

查看示例verifyPurchase()中模块中的方法:Security.java

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;
if (jElement.has("notificationId")) {
  notifyId = jElement.getString("notificationId");
}
String developerPayload = jElement.optString("developerPayload", null);

请注意,由于 JSON 是由 Android Market 生成的,那些在JSONObject.getXXX()方法中指定字段名称的 const-strings 是“硬编码的”(即,您不能真正为它们命名您想要的任何名称)。

于 2012-02-07T23:51:58.617 回答
0

来自 In App Billing 的 android 文档:

...当请求的交易改变状态时(例如,购买成功通过信用卡支付或用户取消购买),Android Market 应用程序发送一个 IN_APP_NOTIFY 广播意图。此消息包含一个通知 ID,您可以使用它来检索 REQUEST_PURCHASE 请求的交易详细信息。

这里得到。

于 2011-11-12T23:42:06.783 回答