127 lines
5.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Extend\Ca;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use GuzzleHttp\Exception\GuzzleException;
use Hyperf\Snowflake\IdGeneratorInterface;
/**
* ca-四川ca云证书+电子签章-线上
*/
class CaOnline extends Ca
{
public function __construct()
{
parent::__construct();
$offline = config('ca.online');
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]
'personalPhone' => (string)$data['mobile'], // 联系人电话
'personalName' => $data['card_name'] ?? "", // 个人姓名类型为Personal时必填
'personalIdNumber' => $data['card_num'] ?? "", // 个人证件号类型为Personal时必填
'orgName' => $data['org_name'] ?? "", // 组织机构名称信用代码类型为Organizational时必填
'orgNumber' => $data['org_number'] ?? "", // 组织机构代码信用代码类型为Organizational时必填
'pin' => $data['user_id'], // 证书PIN码
'province' => "四川省", // 卫生证书:省、州
'locality' => "成都市", // 卫生证书:城市
'authType' => "实人认证", // 委托鉴证方式[实人认证、线下认证、其它方式认证]
'authTime' => time(), // 委托鉴证时间(鉴证完成的时间戳)单位:秒
'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());
}
}
/**
* 吊销云证书
* @param array $data
* @param string $type
* @return mixed
*/
public function removeCloudCert(array $data): mixed
{
$option = [
'form_params' => [
'entityId' => $data['user_id'], // 用户唯一标识,由业务系统定义
'pin' => $data['user_id'], // 证书PIN码
'authType' => "实人认证", // 委托鉴证方式[实人认证、线下认证、其它方式认证]
'authTime' => time(), // 委托鉴证时间(鉴证完成的时间戳)单位:秒
'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());
}
}
/**
* 更新云证书
* @param array $data
* @param string $type
* @return mixed
*/
public function renewCloudCert(array $data): mixed
{
$option = [
'form_params' => [
'entityId' => $data['user_id'], // 用户唯一标识,由业务系统定义
'pin' => $data['user_id'], // 证书PIN码
'authType' => "实人认证", // 委托鉴证方式[实人认证、线下认证、其它方式认证]
'authTime' => time(), // 委托鉴证时间(鉴证完成的时间戳)单位:秒
'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());
}
}
}