简体   繁体   中英

How can i verify google play in-app purchase in php?

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?

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. Your app's public key (from Services & APIs in Google Play Developer console)
  2. The original JSON of the purchase
  3. The purchase signature

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() .

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM