修正验证吗
This commit is contained in:
+80
-24
@@ -5,6 +5,7 @@ namespace Extend\Ca;
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Exception\BusinessException;
|
||||
use App\Utils\Log;
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
@@ -136,7 +137,7 @@ class Ca
|
||||
'signParam' => $data['sign_param'], // 签章配置,JSON
|
||||
'sealImg' => $data['seal_img'], // 签章图片,base64格式
|
||||
'sealType' => "4",
|
||||
'signTemplate' => "1",
|
||||
'signTemplate' => "0",
|
||||
]
|
||||
];
|
||||
|
||||
@@ -145,11 +146,33 @@ class Ca
|
||||
config("ca.api_url") . '/signature-server/api/open/signature/userSignConfig',
|
||||
$option
|
||||
);
|
||||
if (empty($response)){
|
||||
// 返回值为空
|
||||
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
|
||||
}
|
||||
return $response;
|
||||
|
||||
return true;
|
||||
} catch (GuzzleException $e) {
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除签章配置
|
||||
* @param string $user_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function deleteUserSignConfig(string $user_id): mixed
|
||||
{
|
||||
$option = [
|
||||
'form_params' => [
|
||||
'userId' => $user_id,//用户标识信息(为云证书entityId)
|
||||
'configKey' => $user_id, // 签章配置唯一标识,一张云证书配置一个
|
||||
]
|
||||
];
|
||||
|
||||
try {
|
||||
$this->httpRequest(
|
||||
config("ca.api_url") . '/signature-server/api/open/signature/delSignConfig',
|
||||
$option
|
||||
);
|
||||
return true;
|
||||
} catch (GuzzleException $e) {
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
@@ -188,12 +211,34 @@ class Ca
|
||||
*/
|
||||
public function addSignPdf(string $user_id,array $data){
|
||||
$option = [
|
||||
'form_params' => [
|
||||
'userId' => $user_id,// 用户标识信息
|
||||
'configKey' => $user_id,// 签章配置唯一标识
|
||||
'signParams' => $data['sign_param'],// 签章参数,JSON格式数据,如果不指定,那么以签章配置接口配置为准
|
||||
'pdfFile' => $data['pdf_file'],// 待签章PDF文件(字节流)
|
||||
'cloudCertPass' => $user_id,// 云证书PIN码,云证书签章时使用
|
||||
// 'form_params' => [
|
||||
// 'userId' => $user_id,// 用户标识信息
|
||||
// 'configKey' => $user_id,// 签章配置唯一标识
|
||||
// 'signParams' => $data['sign_param'],// 签章参数,JSON格式数据,如果不指定,那么以签章配置接口配置为准
|
||||
// 'pdfFile' => $data['pdf_file'],// 待签章PDF文件(字节流)
|
||||
// 'cloudCertPass' => $user_id,// 云证书PIN码,云证书签章时使用
|
||||
// ],
|
||||
'multipart' => [
|
||||
[
|
||||
'name' => 'pdfFile',
|
||||
'contents' => $data['pdf_file'],
|
||||
],
|
||||
[
|
||||
'name' => 'userId',
|
||||
'contents' => $user_id, // 用户标识信息
|
||||
],
|
||||
[
|
||||
'name' => 'configKey',
|
||||
'contents' => $user_id, // 签章配置唯一标识
|
||||
],
|
||||
[
|
||||
'name' => 'signParams',
|
||||
'contents' => $data['sign_param'],// 签章参数,JSON格式数据,如果不指定,那么以签章配置接口配置为准
|
||||
],
|
||||
[
|
||||
'name' => 'cloudCertPass',
|
||||
'contents' => $user_id,// 云证书PIN码,云证书签章时使用
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
@@ -213,6 +258,8 @@ class Ca
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取请求签名
|
||||
* @param array $data
|
||||
@@ -220,16 +267,23 @@ class Ca
|
||||
*/
|
||||
protected function getRequestSign(array $data): string
|
||||
{
|
||||
ksort($data['form_params']);
|
||||
foreach ($data['form_params'] as $key => $item){
|
||||
if ($key == "pdfFile"){
|
||||
// pdf进行签章时,此参数为文件流,不参与签名
|
||||
unset($data['form_params'][$key]);
|
||||
}
|
||||
}
|
||||
// pdf进行签章时,此参数为文件流,不参与签名
|
||||
unset($data['form_params']['pdfFile']);
|
||||
|
||||
// signParams参数计算时不进行urlencode处理
|
||||
// if (isset($data['form_params']['signParams'])){
|
||||
// $sign_param = json_decode($data['form_params']['signParams'],true);
|
||||
// $sign_param[0]['sealImg'] = urldecode($sign_param[0]['sealImg']);
|
||||
//
|
||||
// $data['form_params']['signParams'] = json_encode($sign_param);
|
||||
// }
|
||||
|
||||
|
||||
ksort($data['form_params']);
|
||||
$data = implode('&',$data['form_params']);
|
||||
return hash_hmac("sha1",$data,config("ca.secret"));
|
||||
dump($data);
|
||||
$data = hash_hmac("sha1",$data,config("ca.secret"));
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -244,15 +298,17 @@ class Ca
|
||||
$option = [
|
||||
"headers" => [
|
||||
"app_id" => config("ca.app_id"),
|
||||
"signature" => $this->getRequestSign($arg)
|
||||
"signature" => $this->getRequestSign($arg),
|
||||
],
|
||||
];
|
||||
|
||||
$arg = array_merge($arg,$option);
|
||||
|
||||
// dump(json_encode($arg,JSON_UNESCAPED_UNICODE));
|
||||
|
||||
$response = $this->client->post($path, $arg);
|
||||
try {
|
||||
$response = $this->client->post($path, $arg);
|
||||
}catch(\Exception $e){
|
||||
dump($e->getMessage());
|
||||
}
|
||||
|
||||
if ($response->getStatusCode() != '200'){
|
||||
// 请求失败
|
||||
|
||||
Reference in New Issue
Block a user