haomingming 1bd00bdcea
Some checks failed
Build Docker / build (push) Has been cancelled
ca认证 V2
2026-04-27 15:26:42 +08:00

153 lines
4.7 KiB
PHP

<?php
namespace Extend\Ca_V2;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use GuzzleHttp\Exception\GuzzleException;
class CaOnline extends Ca
{
public function __construct()
{
parent::__construct();
$this->initConfig('ca.v2.online', 'ca_v2_online');
}
public function getCloudCert(array $data, string $type = 'Personal'): mixed
{
$option = [
'form_params' => [
'entityId' => $data['user_id'],
'entityType' => $type,
'personalPhone' => (string) $data['mobile'],
'personalName' => $data['card_name'] ?? '',
'personalIdNumber' => $data['card_num'] ?? '',
'orgName' => $data['org_name'] ?? '',
'orgNumber' => $data['org_number'] ?? '',
'pin' => $data['user_id'],
'province' => '四川省',
'locality' => '成都市',
'authType' => '实人认证',
'authTime' => $this->getAuthTime(),
'authResult' => '认证通过',
'authNoticeType' => '数字证书申请告知',
],
];
try {
$response = $this->httpRequest(
$this->api_url . '/cloud-certificate-service/api/cloudCert/open/v2/cert/certEnroll',
$option
);
if (empty($response)) {
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
}
return $response;
} catch (GuzzleException $e) {
throw new BusinessException($e->getMessage());
}
}
public function removeCloudCert(array $data): mixed
{
$option = [
'form_params' => [
'entityId' => $data['user_id'],
'pin' => $data['user_id'],
'authType' => '实人认证',
'authTime' => $this->getAuthTime(),
'authResult' => '认证通过',
'authNoticeType' => '数字证书吊销告知',
],
];
try {
$response = $this->httpRequest(
$this->api_url . '/cloud-certificate-service/api/cloudCert/open/v2/cert/certRevoke',
$option
);
if (empty($response)) {
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
}
return $response;
} catch (GuzzleException $e) {
throw new BusinessException($e->getMessage());
}
}
public function renewCloudCert(array $data): mixed
{
$option = [
'form_params' => [
'entityId' => $data['user_id'],
'pin' => $data['user_id'],
'authType' => '实人认证',
'authTime' => $this->getAuthTime(),
'authResult' => '认证通过',
'authNoticeType' => '数字证书更新告知',
],
];
try {
$response = $this->httpRequest(
$this->api_url . '/cloud-certificate-service/api/cloudCert/open/v2/cert/certRenew',
$option
);
if (empty($response)) {
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
}
return $response;
} catch (GuzzleException $e) {
throw new BusinessException($e->getMessage());
}
}
public function getServiceUrl(array $data): mixed
{
$option = [
'form_params' => $data,
];
try {
return $this->httpRequest($this->api_url . '/open/api/data/getServiceUrl', $option);
} catch (GuzzleException $e) {
throw new BusinessException($e->getMessage());
}
}
public function getPasswordLessSignInfo(string $entityId): mixed
{
$option = [
'form_params' => [
'entityId' => $entityId,
],
];
try {
return $this->httpRequest($this->api_url . '/open/api/data/passwordLessSignInfo', $option);
} catch (GuzzleException $e) {
throw new BusinessException($e->getMessage());
}
}
protected function resolveCertSerialnumber(string $entityId, array $response): string
{
$serialNumber = parent::resolveCertSerialnumber($entityId, $response);
if ($serialNumber !== '') {
return $serialNumber;
}
$signInfo = $this->getPasswordLessSignInfo($entityId);
return (string) ($signInfo['certSn'] ?? '');
}
protected function getAuthTime(): string
{
return (string) round(microtime(true) * 1000);
}
}