修正验证吗

This commit is contained in:
2023-03-22 15:15:33 +08:00
parent 563e5ca7ba
commit 26fc5f5e62
12 changed files with 326 additions and 59 deletions
+4 -4
View File
@@ -68,9 +68,9 @@ class Dysms
* @param string $phone_numbers 手机号
* @param array $template_param 参数
* @param string $template_code 短信模版编码
* @param int $scene_desc 场景
* @param string $scene_desc 场景
*/
public static function sendSms(string $phone_numbers,array $template_param,string $template_code,int $scene_desc): void
public static function sendSms(string $phone_numbers,array $template_param,string $template_code,string $scene_desc = ""): void
{
$config = config("alibaba.dysms");
@@ -116,9 +116,9 @@ class Dysms
$data['phone'] = $phone_numbers;
$data['template_code'] = $template_code;
$data['third_code'] = $result['body']['RequestId'];
$data['scene_desc'] = $scene_desc;
$data['scene_desc'] = $scene_desc ?: "";
$data['remarks'] = json_encode($template_param,JSON_UNESCAPED_UNICODE);
$res = LogSms::addCodeLog($data);
$res = LogSms::LogSms($data);
if (empty($res)){
// 发送成功,记录失败
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::CODE_FAIL));
+6 -1
View File
@@ -110,9 +110,14 @@ class Oss
public function getCusTomObjectToRAM(string $filename,string $style = "image/resize"): string
{
try {
// $download_file = "./runtime/aaa.jpg";
$ossClient = $this->createClient();
$options = array(
OssClient::OSS_PROCESS => $style);
OssClient::OSS_PROCESS => $style,
// OssClient::OSS_FILE_DOWNLOAD => $download_file,
);
$object = $filename;
return $ossClient->getObject($this->config['bucket'], $object,$options);
+80 -24
View File
@@ -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'){
// 请求失败