如何在 php 中验证 google play 应用内购买? [英] How can i verify google play in-app purchase in php?

查看:35
本文介绍了如何在 php 中验证 google play 应用内购买?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用 php 页面通过 google play 验证应用内购买的收据.我该怎么做?

I wish to verify a receipt of in-app purchase in an app through google play using a php page. How should i do it?

推荐答案

我不是 PHP 专家,所以我不会发布任何代码,但整个过程非常直截了当移植到 PHP 应该很容易.您需要三件事来验证购买:

I'm no PHP expert so I'm not going to post any code, but the overall process is very straight forward and it should be dead easy to port to PHP. You need three things to verify a purchase:

  1. 您应用的公钥(来自 Google Play Developer 中的服务和 API控制台)
  2. 购买的原始 JSON
  3. 购买签名

如果您在 Android 上使用 IabHelper 类 你会得到一个 购买 对象在您成功购买或查询库存时.Purchase 对象包含您需要的两个方法:Purchase.getOriginalJson()Purchase.getSignature().

If you implement in-app billing on Android using the IabHelper classes you'll get a Purchase object when you make a successful purchase or when you query the inventory. The Purchase object contains two methods that you need: Purchase.getOriginalJson() and Purchase.getSignature().

将您应用的公钥安全地存储在您的服务器上,并将签名和原始 JSON(在发送之前对其进行 base64 编码)发布到您的服务器.从 $_POST 中检索签名和 json 并参考 Google 的 如何验证购买的Java实现.好像可以使用openssl_verify函数内置的PHP.

Securely store your app's public key on your server and POST the signature and the original JSON (base64 encode it before you send it) to you server. Retrieve the signature and json from $_POST and refer to Google's Java implementation of how to verify a purchase. It seems as though you can use PHPs built in openssl_verify function.

这篇关于如何在 php 中验证 google play 应用内购买?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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