Android 上的应用内计费(购买确认,json 字符串)

发布于 2024-12-15 01:50:38 字数 1504 浏览 2 评论 0原文

我在编码付款方面遇到问题。

这是一款网页游戏,我希望付款方式如下。

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

我对此很陌生,只是无法理解这些付款的概念。我使用地牢示例编写了代码。我尝试根据我的需要调整它。如果有人能指出我正确的方向,我将不胜感激。 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 字符串中获取数据。有人知道如何做到这一点吗?

I'm having problems with coding payments.

This is a web game and here's how I would like the payments to work.

You got to a site and click a button(buy). You are redirected to a site that will send the information of a purchase to the server adding the bought item to your account. Before that happens we have a WebViewClient that checks all the urls. If he find an url that is meant for purchases he will send the purchase request. Now if we will get a message back from android market that it was successful he will proceed with the redirect.

I'm quite new to this and just can't grasp the concept of these payments. I wrote my code using the dungeon example. I tried to adjust it to my needs. I would be grateful is someone could point me in the right direction. Atm I'm trying to figure out how to get the response of a successful purchase. Assuming that the rest of my code is ok it should be working (I hope).

I have in my project files BillingReciver.java, BillingSerivce.java, PurchaseObserver.java, ResponseHandler.java, Consts.java and Security.java that were in the example. If need be I can provice the code of these but there is a lot of it, so I'm hoping someone who already seen the example will be able to help.


After some research and consulting with some people I found what I need:

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

I need to get the data out of the JSON string that my app will get from android market. Anyone have an idea how to do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一身仙ぐ女味 2024-12-22 01:50:38

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

我需要从我的应用程序将获取的 JSON 字符串中获取数据
来自安卓市场。有人知道如何做到这一点吗?

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

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() 方法中的名称是“硬编码”的(即您不能真正将它们命名为您想要的任何名称)。

On Nov 17 '11 at 21:56 @Grzegorz 'Gatz' Siennicki wrote:

I need to get the data out of the JSON string that my app will get
from android market. Anyone have an idea how to do that?

Look at the verifyPurchase() method in Security.java module in the sample:

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);

Note that since the JSON is generated by the Android Market, those const-strings that specify the field names in the JSONObject.getXXX() methods are "hard coded" (i.e. you can't really name them anything you want).

尐籹人 2024-12-22 01:50:38

来自应用程序内计费的 android 文档:

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

此处获取。

From the android documentation on In App Billing:

...when the requested transaction changes state (for example, the purchase is successfully charged to a credit card or the user cancels the purchase), the Android Market application sends an IN_APP_NOTIFY broadcast intent. This message contains a notification ID, which you can use to retrieve the transaction details for the REQUEST_PURCHASE request.

Got that from here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文