项目作者: ItzNotABug

项目描述 :
Verify your In-App Purchase receipts & protect your Apps from hacking, patching used by Piracy Apps like Lucky Patcher.
高级语言: Kotlin
项目地址: git://github.com/ItzNotABug/CheckoutVerifier.git
创建时间: 2019-01-31T17:02:21Z
项目社区:https://github.com/ItzNotABug/CheckoutVerifier

开源协议:Apache License 2.0

下载


CheckoutVerifier



Codacy Badge

CheckoutVerifier helps you Verify your In-App Purchase receipts & protect your Apps from hacking, patching used by Piracy Apps like Lucky Patcher.

Since I was using these classes in every project, the copy / pasting of classes was annoying so thought of releasing it as a library which might be of help to others too!

How does it work?

Well, the library sends the Signed Json Response & Signature that you receive after a purchase is completed on a specified server url where it checks the signature of that response data with your BASE64 Key provided to you in your Developer Console.

Set Up

* Get Licensing API Key

Navigate to Developer Console & Select your App.

Go to Development Tools > Services & API.

Copy the BASE64 Licensing Key

* Creating a Verifying PHP File

Just a create a File & name it as verify.php or anything you want.

Paste the following code in it & Upload it to your server.

  1. <?php
  2. $data = $_GET['jsonResponse'];
  3. $signature = $_GET['signature'];
  4. $key_64 = "YOUR BASE64 KEY THAT YOU GOT FROM DEVELOPER CONSOLE, THERE SHOULD BE NO SPACES!";
  5. $key = "-----BEGIN PUBLIC KEY-----\n".
  6. chunk_split($key_64, 64,"\n").
  7. "-----END PUBLIC KEY-----";
  8. $key = openssl_get_publickey($key);
  9. $ok = openssl_verify($data, base64_decode($signature), $key, OPENSSL_ALGO_SHA1);
  10. if ($ok == 1) {
  11. echo "verified";
  12. } elseif ($ok == 0) {
  13. echo "unverified";
  14. } else {
  15. die ("fault, error checking signature");
  16. }
  17. openssl_free_key($key);
  18. ?>

* Implementing Library (Gradle)

Note: Add mavenCentral() in repositories block.

  1. dependencies {
  2. // CheckoutVerifier now internally uses Kotlin Coroutines.
  3. implementation 'com.lazygeniouz:checkout-verifier:$library_version'
  4. }

* CheckoutVerifier

Just pass on the required PurchaseBundle in the Constructor & call authenticate();

The authenticate() returns a Result object.



If the connection to the server was successful & a result was returned,

CompletionResult(isVerified: Boolean) is returned,

ErrorResult(exception: Exception) otherwise.


Example:

  1. yourScope.launch {
  2. val purchaseBundle = PurchaseBundle(url, jsonResponse, signature)
  3. when (val result = CheckoutVerifier(purchaseBundle).authenticate()) {
  4. is CompletionResult -> {
  5. val verified = result.isVerified
  6. // Do something
  7. }
  8. is ErrorResult -> Log.d(TAG, result.exception.message)
  9. }
  10. }