Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
sn01615 committed Jun 3, 2019
1 parent 3bff7c1 commit 4728518
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
27 changes: 26 additions & 1 deletion README.md
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);

```
20 changes: 20 additions & 0 deletions composer.json
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": "*"
}
}
36 changes: 36 additions & 0 deletions src/iap/google/Verify.php
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;
}
}

0 comments on commit 4728518

Please sign in to comment.