修正退出登录

This commit is contained in:
wucongxing 2023-03-17 09:00:51 +08:00
parent 21320b3ea4
commit f9e86d27b7
4 changed files with 92 additions and 11 deletions

View File

@ -6,6 +6,7 @@ use App\Amqp\Producer\PrescriptionDistributePhProducer;
use App\Constants\HttpEnumCode; use App\Constants\HttpEnumCode;
use App\Exception\BusinessException; use App\Exception\BusinessException;
use App\Model\DoctorInquiryTime; use App\Model\DoctorInquiryTime;
use App\Model\DoctorPharmacistCert;
use App\Model\OrderInquiry; use App\Model\OrderInquiry;
use App\Model\UserDoctor; use App\Model\UserDoctor;
use App\Request\UserRequest; use App\Request\UserRequest;
@ -297,5 +298,56 @@ class UserController extends AbstractController
// //
// $RecentContact = new RecentContact(); // $RecentContact = new RecentContact();
// $result = $RecentContact->getRecentContactPage(); // $result = $RecentContact->getRecentContactPage();
$ca = new Ca();
// 获取云证书
$data = array();
$data['user_id'] = "491925054435950592";
$data['card_num'] = "410323199603261241";
$result = $ca->getCloudCert($data);
$data = array();
$data['user_id'] = "491925054435950592";
$data['cert_base64'] = $result['certBase64'];
$data['cert_chain_p7'] = $result['certP7'];
$data['cert_serial_number'] = $result['certSerialnumber'];
$data['ca_pin'] = "491925054435950592";
$doctor_pharmacist_cert = DoctorPharmacistCert::addDoctorPharmacistCert($data);
if (empty($doctor_pharmacist_cert)){
return fail();
}
// 获取用户云证书数据
$params = array();
$params['user_id'] = "491925054435950592";
$doctor_pharmacist_cert = DoctorPharmacistCert::getOne($params);
if (empty($doctor_pharmacist_cert)){
return fail(HttpEnumCode::HTTP_ERROR,"用户数据错误");
}
// 获取云证书签名
$data = array();
$data['created_at'] = date('Y-m-d H:i:s',time());
$data['department_custom_name'] = "外科";
$data['user_name'] = "测试用户1";
$data['sex'] = "";
$data['age'] = 19;
$data['allergy_history'] = "";
$data['icd_name'] = "感冒";
$data['doctor_advice'] = "多吃药";
$data['product'] = [
[
"product_name" => "感冒药",
"product_name" => "感冒药",
]
];
$result = $ca->getCertSign($data);
} }
} }

View File

@ -66,4 +66,14 @@ class DoctorPharmacistCert extends Model
{ {
return self::where($params)->get($fields); return self::where($params)->get($fields);
} }
/**
* 新增
* @param array $data
* @return \Hyperf\Database\Model\Model|DoctorPharmacistCert
*/
public static function addDoctorPharmacistCert(array $data = []): \Hyperf\Database\Model\Model|DoctorPharmacistCert
{
return self::create($data);
}
} }

View File

@ -254,11 +254,14 @@ class UserService extends BaseService
} }
$token = explode(' ', $bearer_token[0]); $token = explode(' ', $bearer_token[0]);
if (!isset($token[1])){
return fail();
}
$redis = $this->container->get(Redis::class); $redis = $this->container->get(Redis::class);
// 旧token加入黑名单 5天有效期5天内无法继续进行访问 // 旧token加入黑名单 5天有效期5天内无法继续进行访问
$res = $redis->set('jwt_black_' . $token, time(), 60*60*24*5); $res = $redis->set('jwt_black_' . $token[1], time(), 60*60*24*5);
if (!$res) { if (!$res) {
return fail(HttpEnumCode::SERVER_ERROR); return fail(HttpEnumCode::SERVER_ERROR);
} }

View File

@ -54,24 +54,42 @@ class Ca
} }
} }
// 获取云证书签名 /**
public function getCertSign(array $data){ * 获取云证书签名
* @param array $data
* @return mixed
*/
public function getCertSign(array $data): mixed
{
$option = [ $option = [
'form_params' => [ 'form_params' => [
'entityId' => $data['user_id'], // 用户唯一标识,由业务系统定义 'entityId' => $data['user_id'], // 用户唯一标识,由业务系统定义
'entityType' => "Personal",// 用户类型,可选值[Personal/Organizational] 'toSign' => $this->getRequestSign($data),
'pin' => $data['user_id'], // 证书PIN码 'pin' => $data['user_id'], // 证书PIN码
'cardNumber' => $data['card_num'], // 证件号码(个人身份证;企业统一社会信用代码)
] ]
]; ];
try {
$response = $this->httpRequest(
config("ca.api_url") . '/cloud-certificate-service' . '/api/cloudCert/open/cert/sign',
$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 array $data
* @return string * @return string
*/ */
protected function getSign(array $data): string protected function getRequestSign(array $data): string
{ {
ksort($data['form_params']); ksort($data['form_params']);
@ -86,19 +104,17 @@ class Ca
* @return mixed * @return mixed
* @throws GuzzleException * @throws GuzzleException
*/ */
public function httpRequest(string $path,array $arg = []): mixed protected function httpRequest(string $path,array $arg = []): mixed
{ {
$option = [ $option = [
"headers" => [ "headers" => [
"app_id" => config("ca.app_id"), "app_id" => config("ca.app_id"),
"signature" => $this->getSign($arg) "signature" => $this->getRequestSign($arg)
], ],
]; ];
$arg = array_merge($arg,$option); $arg = array_merge($arg,$option);
dump($arg);
dump($path);
$response = $this->client->post($path, $arg); $response = $this->client->post($path, $arg);
if ($response->getStatusCode() != '200'){ if ($response->getStatusCode() != '200'){
// 请求失败 // 请求失败