|
|
@@ -4,6 +4,7 @@ namespace SixShop\AliyunIDCard;
|
|
|
|
|
|
use Symfony\Component\HttpClient\HttpClient;
|
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
+use function SixShop\Core\throw_logic_exception;
|
|
|
|
|
|
class IDCardClient
|
|
|
{
|
|
|
@@ -12,12 +13,18 @@ class IDCardClient
|
|
|
|
|
|
private HttpClientInterface $httpClient;
|
|
|
|
|
|
+ private array $errorMesageMap = [
|
|
|
+ '5' => '身份证和姓名不匹配',
|
|
|
+ '14' => '无此身份证号码',
|
|
|
+ '96' => '验证失败,请稍后重试',
|
|
|
+ ];
|
|
|
+
|
|
|
public function __construct(private Config $config)
|
|
|
{
|
|
|
$this->httpClient = HttpClient::create([
|
|
|
'base_uri' => self::GATEWAY,
|
|
|
'headers' => [
|
|
|
- 'Authorization' => 'APPCODE ' . $this->config->getAppCode(),
|
|
|
+ 'Authorization' => 'APPCODE ' . $this->config->app_code,
|
|
|
]
|
|
|
]);
|
|
|
}
|
|
|
@@ -35,7 +42,7 @@ class IDCardClient
|
|
|
if ($result['resp']['code'] == 0) {
|
|
|
return $result['data'];
|
|
|
} else {
|
|
|
- throw_logic_exception($result['resp']['desc'], $result['resp']['code']);
|
|
|
+ throw new \RuntimeException($this->errorMesageMap[$result['resp']['code']] ?? $result['resp']['desc']);
|
|
|
}
|
|
|
}
|
|
|
}
|