Android 上的应用内计费(购买确认,json 字符串)
我在编码付款方面遇到问题。
这是一款网页游戏,我希望付款方式如下。
您进入一个网站并单击按钮(购买)。您将被重定向到一个网站,该网站会将购买信息发送到服务器,并将购买的商品添加到您的帐户。在此之前,我们有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
2011 年 11 月 17 日 21:56 @Grzegorz 'Gatz' Siennicki 写道:
查看示例中
Security.java
模块中的verifyPurchase()
方法:请注意,由于 JSON 是由 Android Market 生成的,因此指定字段的那些常量字符串
JSONObject.getXXX()
方法中的名称是“硬编码”的(即您不能真正将它们命名为您想要的任何名称)。On Nov 17 '11 at 21:56 @Grzegorz 'Gatz' Siennicki wrote:
Look at the
verifyPurchase()
method inSecurity.java
module in the sample: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).来自应用程序内计费的 android 文档:
从此处获取。
From the android documentation on In App Billing:
Got that from here.