如何验证的Andr​​oid的应用内计费交易我的服务器上? [英] How do I verify Android in-app-billing transactions on MY server?

查看:148
本文介绍了如何验证的Andr​​oid的应用内计费交易我的服务器上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个Android应用程序,其中的项目可以使用在应用内计费购买。当一个项目是购买交易可以很容易地被Android电子市场和手机之间同步 - 要在应用程序中使用。但是,我需要我的服务器要注意购买。提供应用程序特定的数据应做出决策我的服务器上,而不是在客户端应用程序。

I have made an Android app where items can be purchased using in-app-billing. When an item is purchased the transaction can easily be synced between Android Market and the phone - to be used in the app. But, I need MY server to be aware of the purchase. The decision to deliver app-specific data should be made on my server, not in the client app.

例如。

  1. 在用户购买X项从Android Market。
  2. 交易数据Y被发送到客户端。
  3. 在客户端发送Ÿ到我的服务器。
  4. 客户端要求服务器提供对于x的内容。
  5. 服务器提供内容如果Y是有效的。如何实现这一点?
  1. User buys item X from Android Market.
  2. Transaction data Y is sent to the client.
  3. Client sends Y to my server.
  4. Client asks the server to deliver content for X.
  5. Server delivers content if Y is valid. How can this be accomplished?

问:我如何验证交易数据来自Android客户端来了(presumably从谷歌服务器上的文件)是不是假的?即黑客未产生的数据。

Q: How do I verify that transaction data coming from the Android client (presumably originating from Google servers) is not fake? I.e. a hacker didn't generate the data.

谷歌服务器 - > Android客户端 - >我的服务器 - > Android客户端

Google Server -> Android client -> My server -> Android client

也许这更是比什么都一个PHP的问题。为了究竟是什么使我的服务器脚本(PHP)做验证检索到的数据是真实的?

Perhaps this is more of a PHP question than anything else. Exactly what should my server script (PHP) do in order to verify that the retrieved data is real?

推荐答案

使用openssl_verify($数据,$签名,$键)

Use openssl_verify ($data, $signature, $key)

$数据和$签名的变量应该从Android客户端使用https发送到您的PHP服务器。事务包含这两个项目。发送到你的服务器上,确认客户端上的事务之前(见文档在这里 - <一个href="http://developer.android.com/guide/market/billing/billing_integrate.html">http://developer.android.com/guide/market/billing/billing_integrate.html)

The variables $data and $signature should be sent from the android client to your php server using https. The transaction contains both of these items. Send that to your servers before you acknowledge the transaction on the client.(see documentation here - http://developer.android.com/guide/market/billing/billing_integrate.html)

变量$键可从您的出版商帐户的谷歌公共密钥从许可和放大器;在应用程序内付费面板。复制公钥和使用,在你的PHP code,preferably使用台服务器上,而不是实际的PHP code安装配置文件。

The variable $key is your google public key available from your publisher account from the Licensing & In-app Billing panel. Copy the public key and use that in your php code, preferably using a config file you install on your servers rather than in your actual php code.

如果该openssl_verify调用成功,你应该存储的顺序号在服务器上,并确保它们是唯一的,使他们无法重播。要知道,一个单一的数据接收和签名对可能包含许多订单号虽然它通常是一个数量级。

If the openssl_verify call succeeds you should store the order numbers on your servers and ensure they are unique so they cannot be replayed. Be aware that a single data receipt and signature pair could contain many order numbers though its usually one order.

这篇关于如何验证的Andr​​oid的应用内计费交易我的服务器上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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