55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Extend\Ca;
|
|
|
|
use App\Constants\HttpEnumCode;
|
|
use App\Exception\BusinessException;
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
use Hyperf\Snowflake\IdGeneratorInterface;
|
|
|
|
/**
|
|
* 四川ca云证书+电子签章-线下
|
|
*/
|
|
class CaOffline extends Ca
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$offline = config('ca.offline');
|
|
if (empty($offline)){
|
|
throw new BusinessException("缺少ca线下配置");
|
|
}
|
|
$this->app_id = $offline['app_id'];
|
|
$this->api_url = $offline['api_url'];
|
|
$this->secret = $offline['secret'];
|
|
}
|
|
|
|
/**
|
|
* 申请云证书
|
|
* @param array $data
|
|
* @param string $type
|
|
* @return mixed
|
|
*/
|
|
public function getCloudCert(array $data,string $type = "Personal"): mixed
|
|
{
|
|
$option = [
|
|
'form_params' => [
|
|
'entityId' => $data['user_id'], // 用户唯一标识,由业务系统定义
|
|
'entityType' => $type,// 用户类型,可选值[Personal/Organizational]
|
|
'pin' => $data['user_id'], // 证书PIN码
|
|
'cardNumber' => $data['card_num'], // 证件号码(个人身份证;企业统一社会信用代码)
|
|
]
|
|
];
|
|
|
|
try {
|
|
$response = $this->httpRequest($this->api_url . '/cloud-certificate-service' . '/api/cloudCert/open/v2/cert/offlineAuthCertEnroll', $option);
|
|
if (empty($response)) {
|
|
// 返回值为空
|
|
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
|
|
}
|
|
return $response;
|
|
} catch (GuzzleException $e) {
|
|
throw new BusinessException($e->getMessage());
|
|
}
|
|
}
|
|
} |