|
@@ -0,0 +1,42 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+declare(strict_types=1);
|
|
|
|
|
+namespace SixShop\AliyunIDCard;
|
|
|
|
|
+
|
|
|
|
|
+use SixShop\Core\Helper;
|
|
|
|
|
+use Symfony\Component\HttpClient\HttpClient;
|
|
|
|
|
+use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
|
|
+
|
|
|
|
|
+class IDCardClient
|
|
|
|
|
+{
|
|
|
|
|
+
|
|
|
|
|
+ private const string GATEWAY = 'https://idcard.market.alicloudapi.com/';
|
|
|
|
|
+
|
|
|
|
|
+ private HttpClientInterface $httpClient;
|
|
|
|
|
+
|
|
|
|
|
+ public function __construct(private Config $config)
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->httpClient = HttpClient::create([
|
|
|
|
|
+ 'base_uri' => self::GATEWAY,
|
|
|
|
|
+ 'headers' => [
|
|
|
|
|
+ 'Authorization' => 'APPCODE ' . $this->config->getAppCode(),
|
|
|
|
|
+ ]
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public function idcard(string $cardno, string $name): array
|
|
|
|
|
+ {
|
|
|
|
|
+ $response = $this->httpClient->request('GET', 'lianzhuo/idcard', [
|
|
|
|
|
+ 'query' => [
|
|
|
|
|
+ 'cardno' => $cardno,
|
|
|
|
|
+ 'name' => $name,
|
|
|
|
|
+ ]
|
|
|
|
|
+ ]);
|
|
|
|
|
+ $result = json_decode($response->getContent(), true);
|
|
|
|
|
+ if ($result['resp']['code'] == 0) {
|
|
|
|
|
+ return $result['data'];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Helper::throw_logic_exception($result['resp']['desc'], $result['resp']['code']);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|