-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rightrun/dev
Dev
- Loading branch information
Showing
20 changed files
with
1,944 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,4 @@ | ||
.idea | ||
.git | ||
vendor | ||
composer.lock |
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,38 @@ | ||
# proof-identity | ||
### 安装 | ||
```shell | ||
composer require rightrun/proof-identity | ||
``` | ||
|
||
### 一、 实名认证库 | ||
#### 1. 工宣部实名 | ||
|
||
|
||
#### 2. 阿里实名 | ||
阿里二要素 | ||
https://market.aliyun.com/products/57000002/cmapi029454.html | ||
|
||
|
||
|
||
### 二、实名测试 | ||
#### 1. 安装phpunit | ||
```shell | ||
|
||
|
||
$ curl -LO https://phar.phpunit.de/phpunit-9.6.phar | ||
$ chmod +x phpunit-9.6.phar | ||
$ sudo mv phpunit-9.6.phar /usr/local/bin/phpunit | ||
$ phpunit --version | ||
``` | ||
|
||
#### 2. 运行单元测试 | ||
```shell | ||
|
||
#单个测试 | ||
#工宣部 | ||
phpunit --bootstrap tests/bootstrap.php tests/Cases/WlcnppaProofTest.php | ||
|
||
|
||
#阿里 | ||
phpunit --bootstrap tests/bootstrap.php tests/Cases/AliyunProofTest.php | ||
|
||
``` |
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,40 @@ | ||
{ | ||
"name": "rightrun/proof-identity", | ||
"minimum-stability": "dev", | ||
"type": "library", | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=7.4", | ||
"spomky-labs/php-aes-gcm": "~1.2", | ||
"guzzlehttp/guzzle": ">=7.5.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/php-file-iterator": "~3.0.5", | ||
"phpunit/phpunit": "9.6.8", | ||
"phpunit/php-invoker": "~3.1" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "rightrun", | ||
"email": "rightrun@163.com", | ||
"homepage": "https://github.com/rightrun/proof-identity", | ||
"role": "Developer" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Onetrue\\ProofIdentity\\": "src/", | ||
"ProofTest\\": "tests/" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "phpunit ./tests/bootstrap.php -c phpunit.xml --colors=always" | ||
}, | ||
"suggest": { | ||
"ext-openssl": "Required to use HTTPS.", | ||
"ext-json": "*" | ||
}, | ||
"config": { | ||
"preferred-install": "dist" | ||
} | ||
} |
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,21 @@ | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="./tests/bootstrap.php" | ||
colors="false" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="proof-identify"> | ||
<directory suffix="Test.php">.</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist addUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./tests</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
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,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of a07sky/proof-identify | ||
* | ||
* @link https://github.com/a07sky/proof-identify | ||
* @contact a07sky@126.com | ||
* @license https://github.com/proof-identify/blob/master/LICENSE | ||
*/ | ||
|
||
namespace Onetrue\ProofIdentity\Aliyun; | ||
|
||
use Onetrue\ProofIdentity\Contracts\ConfigInterface; | ||
|
||
class AliyunProofConfig implements ConfigInterface | ||
{ | ||
|
||
protected $verifyKey = ""; | ||
|
||
protected $appCode = ''; | ||
|
||
|
||
public function __construct($verifyKey, $appCode) | ||
{ | ||
$this->verifyKey = $verifyKey; | ||
$this->appCode = $appCode; | ||
} | ||
|
||
|
||
public function getVerifyKey() | ||
{ | ||
return $this->verifyKey; | ||
} | ||
|
||
public function getAppCode() | ||
{ | ||
return $this->appCode; | ||
} | ||
} |
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,100 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of a07sky/proof-identify | ||
* | ||
* @link https://github.com/a07sky/proof-identify | ||
* @contact a07sky@126.com | ||
* @license https://github.com/proof-identify/blob/master/LICENSE | ||
*/ | ||
|
||
namespace Onetrue\ProofIdentity\Aliyun; | ||
|
||
|
||
use Onetrue\ProofIdentity\Contracts\ResultInterface; | ||
use Onetrue\ProofIdentity\Exception\ProofIdentifyException; | ||
use Onetrue\ProofIdentity\ProofIdentifyResult; | ||
use Onetrue\ProofIdentity\Provider\ProofIdentifyProvider; | ||
use Onetrue\ProofIdentity\Utils\IdCardParser; | ||
use GuzzleHttp\Client; | ||
|
||
|
||
/** | ||
* https://market.aliyun.com/products/56928004/cmapi00062284.html?spm=5176.730005.result.22.56ca123eheH5pJ&innerSource=search#sku=yuncode5628400005 | ||
*/ | ||
class AliyunProofIdentify extends ProofIdentifyProvider | ||
{ | ||
/** | ||
* 获取阿进而配置 | ||
* @return \Onetrue\ProofIdentity\Aliyun\AliyunProofConfig | ||
*/ | ||
public function getConfig(): AliyunProofConfig | ||
{ | ||
return $this->config; | ||
} | ||
|
||
|
||
public function behaviorLoginout($authPi, $behaviorType, $time, $deviceImei): bool | ||
{ | ||
// TODO: Implement behaviorLoginout() method. | ||
} | ||
|
||
|
||
public function verify(string $realname, string $idcard): ?ResultInterface | ||
{ | ||
$this->validIdCard($idcard); | ||
$config = $this->getConfig(); | ||
|
||
$verifyKey = $config->getVerifyKey(); | ||
$appCode = $config->getAppCode(); | ||
|
||
$requestUrl = "https://sxidcheck.market.alicloudapi.com/idcard/check"; | ||
$headers = [ | ||
'Content-Type' => 'application/x-www-form-urlencoded', | ||
"Authorization" => "APPCODE " . $appCode, | ||
]; | ||
try { | ||
//http | ||
$client = new Client([ | ||
'timeout' => 3, | ||
'headers' => $headers, | ||
'http_errors' => false, | ||
]); | ||
//发送请求 | ||
$requestData = [ | ||
'idCard' => $idcard, | ||
'name' => $realname, | ||
]; | ||
$response = $client->post($requestUrl . '?' . http_build_query($requestData), []); | ||
$statusCode = $response->getStatusCode(); | ||
$proofResult = new ProofIdentifyResult(); | ||
$proofResult->setStatusCode($statusCode); | ||
$proofResult->setErrorMessage('阿里云网络异常!'); | ||
$respBody = $response->getBody()->getContents(); | ||
$respBody = json_decode($respBody, true); | ||
if ($statusCode == 200) { | ||
//{"code":"0","msg":"成功","isFee":1,"seqNo":"ktsxu8zpuvoutb3nptg727pkl8q6lna7","data":{"birthday":"19581028","gender":1,"age":64,"province":"四川","result":1}}" | ||
$proofResult->setStatusCode(intval($respBody['code'])); | ||
$proofResult->setErrorMessage($respBody['msg']); | ||
//"result": 2 //核查结果(1:一致,2:不一致,3:无记录) | ||
if (!empty($respBody['data']) && $respBody['data']['result'] == 1) { | ||
$proofResult->setStatusCode(0); //成功状态 | ||
$idCardParser = new IdCardParser($idcard); | ||
$idCardParser->setPi($authResult['pi'] ?? ''); | ||
$proofResult->setIdCardParser($idCardParser); | ||
} else if (!empty($respBody['data'])) { | ||
$proofResult->setStatusCode($respBody['body']['result']); | ||
} | ||
} else { | ||
$proofResult->setStatusCode(intval($respBody['code'])); | ||
$proofResult->setErrorMessage($respBody['msg']); | ||
} | ||
return $proofResult; | ||
} catch (\Throwable $exception) { | ||
print_r(get_class($exception)); | ||
throw new ProofIdentifyException($exception->getMessage()); | ||
} | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of a07sky/proof-identify | ||
* | ||
* @link https://github.com/a07sky/proof-identify | ||
* @contact a07sky@126.com | ||
* @license https://github.com/proof-identify/blob/master/LICENSE | ||
*/ | ||
|
||
namespace Onetrue\ProofIdentity\Contracts; | ||
|
||
interface ConfigInterface | ||
{ | ||
|
||
} |
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,27 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of a07sky/proof-identify | ||
* | ||
* @link https://github.com/a07sky/proof-identify | ||
* @contact a07sky@126.com | ||
* @license https://github.com/proof-identify/blob/master/LICENSE | ||
*/ | ||
|
||
namespace Onetrue\ProofIdentity\Contracts; | ||
|
||
interface ProofIdentifyProviderInterface | ||
{ | ||
public function verify(string $realname, string $idcard): ?ResultInterface; | ||
|
||
|
||
/** | ||
* @param string $authPi 实名认证pi值,工宣部独有 | ||
* @param integer $behaviorType 行为类型: 上线和下线的标记( 0:下线 1:上线) | ||
* @param integer $time 上线和下线的时间截( 秒数) | ||
* @param string $deviceImei 设备号,游客模式下需要传设备号 | ||
* @return bool | ||
*/ | ||
public function behaviorLoginout($authPi, $behaviorType, $time, $deviceImei): bool; | ||
} |
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,59 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of a07sky/proof-identify | ||
* | ||
* @link https://github.com/a07sky/proof-identify | ||
* @contact a07sky@126.com | ||
* @license https://github.com/proof-identify/blob/master/LICENSE | ||
*/ | ||
|
||
namespace Onetrue\ProofIdentity\Contracts; | ||
|
||
|
||
use Onetrue\ProofIdentity\Utils\IdCardParser; | ||
|
||
/** | ||
* 实名认证结果 | ||
*/ | ||
interface ResultInterface | ||
{ | ||
|
||
|
||
/** | ||
* 设置解析器 | ||
* @param $parser | ||
* @return mixed | ||
*/ | ||
public function setIdCardParser($parser); | ||
|
||
/** | ||
* 身份证解析器 | ||
* @return IdCardParser|null | ||
*/ | ||
public function getIdCardParser(); | ||
|
||
/** | ||
* 设置状态码 | ||
* @param int $statusCode | ||
* @return mixed | ||
*/ | ||
public function setStatusCode($statusCode); | ||
|
||
/** | ||
* 实名状态码 | ||
* @return int | ||
*/ | ||
public function getStatusCode(); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getErrorMessage(): string; | ||
|
||
/** | ||
* @param string $errorMessage | ||
*/ | ||
public function setErrorMessage(string $errorMessage); | ||
} |
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,18 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of hyperf-ext/jwt | ||
* | ||
* @link https://github.com/a07sky/proof-identify | ||
* @contact a07sky@126.com | ||
* @license https://github.com/proof-identify/blob/master/LICENSE | ||
*/ | ||
|
||
|
||
namespace Onetrue\ProofIdentity\Exception; | ||
|
||
class ProofIdentifyException extends \RuntimeException | ||
{ | ||
|
||
} |
Oops, something went wrong.