2011-11-12 52 views
2

我在编码付款时遇到问题。Android上的应用内结算(购买确认,json字符串)

这是一款网络游戏,以下是我希望如何使用付款的方法。

您必须去某个网站并点击某个按钮(购买)。您被重定向到一个网站,该网站会将购买的信息发送到服务器,并将购买的商品添加到您的帐户中。在这之前,我们有一个WebViewClient来检查所有的URL。如果他找到一个用于购买的网址,他会发送购买请求。现在,如果我们从安卓市场获得一个消息,说明它很成功,他将继续进行重定向。

我对此很陌生,无法理解这些付款的概念。我用地牢的例子写了我的代码。我试图根据自己的需要进行调整。我会很感激有人可以指出我正确的方向。 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); 
     } 

我需要获取数据了JSON字符串,我的应用程序将在Android Market获得的。任何人有一个想法如何做到这一点?

+0

那么....你的问题是什么? –

+0

如何从android市场获得购买请求成功的响应? –

+0

您是否定义了您的发展账户的公钥?(在Security.java类中的某处,如果您使用的是Android开发人员的官方示例)没有它,您将无法确认任何购买。 – yugidroid

回答

0

从上在应用内结算的Android文档:

...当所请求的交易改变状态(例如,购买成功收取信用卡或用户取消购买),该Android电子市场应用程序发送IN_APP_NOTIFY广播意图。此消息包含通知ID,您可以使用该ID来检索REQUEST_PURCHASE请求的事务处理详细信息。

here得到。

+0

好的,我读了所有这些,但我仍然不明白如何从中得到实际的信息。 在ResponsHandler文件中有一个方法“purchaseResponse”,应该由结算服务调用并获取我需要的信息。现在我该怎么做才能从方法中获得它? –

+0

不知道该怎么告诉你。这就是我所知道的所有信息。 –

+0

更新了我的问题。 –

2

11月17 '11于21时56 @Grzegorz“盖兹” Siennicki写道:

我需要获取数据了JSON字符串,我的应用程序将获得 从Android Market的。任何人有一个想法如何做到这一点?

看那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()方法的字段名的常量串生成是“硬编码”(即你不能真正命名他们任何你想要的)。