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

后端 未结 1 1295
天命终不由人
天命终不由人 2020-12-28 11:40

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?

相关标签:
1条回答
  • 2020-12-28 12:23

    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.

    0 讨论(0)
提交回复
热议问题