-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,26 @@ | ||
# googe-iap-php | ||
# google-iap-php | ||
|
||
Google支付验证 | ||
|
||
## install | ||
```bash | ||
composer require sn01615/google-iap-php | ||
``` | ||
|
||
## use | ||
```php | ||
|
||
use sn01615\iap\google\Verify; | ||
|
||
include "../vendor/autoload.php"; | ||
|
||
$cc = new Verify(); | ||
|
||
# 通过setPublicKey设置public key,然后输入data和sign,返回验证结果 | ||
$vv = $cc->setPublicKey('key')->verify('data', 'signature'); | ||
|
||
# Returns 1 if the signature is correct, 0 if it is incorrect, and -1 on error. | ||
# 如果$vv 等于1代表成功 0 代表失败 -1 表示错误 | ||
var_dump($vv); | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "sn01615/google-iap-php", | ||
"description": "Google iap verify", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "YangLong", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"sn01615\\": "src/" | ||
} | ||
}, | ||
"require": { | ||
"ext-openssl": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
|
||
namespace sn01615\iap\google; | ||
|
||
|
||
class Verify | ||
{ | ||
|
||
private $public_key; | ||
|
||
public function __construct($public_key = null) | ||
{ | ||
$this->setPublicKey($public_key); | ||
} | ||
|
||
public function setPublicKey($public_key) | ||
{ | ||
$this->public_key = $public_key; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $data 客户端回传的 INAPP_PURCHASE_DATA 对应的数据 | ||
* @param string $signature 客户端回传的 INAPP_DATA_SIGNATURE 对应的数据 | ||
* @return int | ||
*/ | ||
public function verify($data, $signature) | ||
{ | ||
$google_public_key = $this->public_key; | ||
$public_key = "-----BEGIN PUBLIC KEY-----\n" . chunk_split($google_public_key, 64, "\n") . "-----END PUBLIC KEY-----"; | ||
$public_key_handle = openssl_get_publickey($public_key); | ||
$result = openssl_verify($data, base64_decode($signature), $public_key_handle, OPENSSL_ALGO_SHA1); | ||
return $result; | ||
} | ||
} |