master
lion 6 days ago
parent 0dc4ecb718
commit f1fe296d49

@ -16,6 +16,7 @@ class DoorRepository
public $key;
public $dptNo;
public $profix;
public $httpTimeout = 30;
public function __construct()
{
@ -103,18 +104,23 @@ class DoorRepository
$params['sign'] = $this->sign($params);
$result = [];
$finally = 0;
$resultJson = '';
try {
$params = json_encode($params);
$result = httpCurl($url, 'POST', $params, $header);
$result = json_decode($result, true);
if (empty($result['code'])) {
$resultJson = httpCurl($url, 'POST', $params, $header, $this->httpTimeout);
$result = json_decode($resultJson, true);
if (!is_array($result) || !array_key_exists('code', $result)) {
$out = is_string($resultJson) && $resultJson !== '' ? $resultJson : '门禁同步人员超时或返回异常';
$result = $out;
return false;
}
if ((int) $result['code'] === 0) {
$finally = 1;
return true;
} else {
$out = $result['msg'];
return false;
}
} catch (\Exception $e) {
$out = $result['msg'] ?? '门禁同步人员失败';
return false;
} catch (\Throwable $e) {
$out = $e->getMessage();
return false;
} finally {
@ -155,25 +161,23 @@ class DoorRepository
$params['sign'] = $this->sign($params);
$result = [];
$finally = 0;
$resultJson = '';
try {
$params = json_encode($params);
$resultJson = httpCurl($url, 'POST', $params, $header);
$resultJson = httpCurl($url, 'POST', $params, $header, $this->httpTimeout);
$result = json_decode($resultJson, true);
if (empty($result['code']) && ($result['msg'] == '执行成功' || str_contains($result['msg'], '已有权限'))) {
$msg = is_array($result) ? (string) ($result['msg'] ?? '') : '';
if (is_array($result) && array_key_exists('code', $result) && (int) $result['code'] === 0 && ($msg === '执行成功' || str_contains($msg, '已有权限'))) {
$finally = 1;
// 写日志
ThirdAppointmentLog::add($model->id, 0, $model->user_id, $url, $params, $result, $finally, '门禁预约', $door['doorName'], $endTime);
return true;
} else {
$out = $result['msg'];
// 写日志
ThirdAppointmentLog::add($model->id, 0, $model->user_id, $url, $params, $result, $finally, '门禁预约', $door['doorName'], $endTime);
return false;
}
} catch (\Exception $e) {
$out = $msg !== '' ? $msg : (is_string($resultJson) && $resultJson !== '' ? $resultJson : '门禁下发超时或返回异常');
ThirdAppointmentLog::add($model->id, 0, $model->user_id, $url, $params, is_array($result) ? $result : $out, $finally, '门禁预约', $door['doorName'], $endTime);
return false;
} catch (\Throwable $e) {
$out = $e->getMessage();
// 写日志
ThirdAppointmentLog::add($model->id, 0, $model->user_id, $url, $params, $result, $finally, '门禁预约', $door['doorName'], $endTime);
ThirdAppointmentLog::add($model->id, 0, $model->user_id, $url, $params, $result ?: $resultJson, $finally, '门禁预约', $door['doorName'], $endTime);
return false;
}
}
@ -268,18 +272,23 @@ class DoorRepository
$params['sign'] = $this->sign($params);
$result = [];
$finally = 0;
$resultJson = '';
try {
$params = json_encode($params);
$result = httpCurl($url, 'POST', $params, $header);
$result = json_decode($result, true);
if (empty($result['code'])) {
$resultJson = httpCurl($url, 'POST', $params, $header, $this->httpTimeout);
$result = json_decode($resultJson, true);
if (!is_array($result) || !array_key_exists('code', $result)) {
$out = is_string($resultJson) && $resultJson !== '' ? $resultJson : '门禁同步人员超时或返回异常';
$result = $out;
return false;
}
if ((int) $result['code'] === 0) {
$finally = 1;
return true;
} else {
$out = $result['msg'];
return false;
}
} catch (\Exception $e) {
$out = $result['msg'] ?? '门禁同步人员失败';
return false;
} catch (\Throwable $e) {
$out = $e->getMessage();
return false;
} finally {
@ -327,16 +336,19 @@ class DoorRepository
$finally = 0;
try {
$params = json_encode($params, JSON_UNESCAPED_UNICODE);
$resultJson = httpCurl($url, 'POST', $params, $header);
$resultJson = httpCurl($url, 'POST', $params, $header, $this->httpTimeout);
$result = json_decode($resultJson, true);
if (empty($result['code'])) {
$msg = is_array($result) ? (string) ($result['msg'] ?? '') : '';
if (is_array($result) && array_key_exists('code', $result) && (int) $result['code'] === 0) {
$finally = 1;
return true;
} else {
$out = $result['msg'];
return false;
}
} catch (\Exception $e) {
$out = $msg !== '' ? $msg : (is_string($resultJson) && $resultJson !== '' ? $resultJson : '门禁下发超时或返回异常');
if (!is_array($result)) {
$result = $out;
}
return false;
} catch (\Throwable $e) {
$out = $e->getMessage();
return false;
} finally {

@ -14,6 +14,7 @@ class MeetRepository
public $account;
public $password;
public $companyId;
public $httpTimeout = 30;
public function __construct()
{
@ -37,14 +38,13 @@ class MeetRepository
'password' => $this->password
];
try {
$result = httpCurl($url, 'GET', $params, $header);
$result = httpCurl($url, 'GET', $params, $header, $this->httpTimeout);
$result = json_decode($result, true);
if ($result['success']) {
if (is_array($result) && !empty($result['success'])) {
return $result['companyId'];
} else {
return false;
}
} catch (\Exception $e) {
return false;
} catch (\Throwable $e) {
return false;
}
}
@ -62,7 +62,7 @@ class MeetRepository
'password' => md5($this->password)
];
try {
$resultJson = httpCurl($url, 'GET', $params, $header, 30);
$resultJson = httpCurl($url, 'GET', $params, $header, $this->httpTimeout);
$result = json_decode($resultJson, true);
if (!is_array($result) || empty($result['success']) || empty($result['data'])) {
return false;
@ -93,7 +93,13 @@ class MeetRepository
$startDateTime = new \DateTime($model->start_time);
$endDateTime = new \DateTime($model->end_time);
$meetOther = json_decode($appointmentConfig->room, true);
$meetOther = is_array($appointmentConfig->room)
? $appointmentConfig->room
: json_decode($appointmentConfig->room, true);
if (!is_array($meetOther) || empty($meetOther['code']) || empty($meetOther['address'])) {
$out = '会议室信息不完整,缺少 code 或 address';
return false;
}
$url = $this->baseUrl . '/services/api/BookingService.aspx';
$header[] = 'Content-Type: application/json';
@ -132,24 +138,25 @@ class MeetRepository
$result = [];
$finally = 0;
$resultJson = '';
try {
$resultJson = httpCurl($url, 'GET', $params, $header);
$resultJson = httpCurl($url, 'GET', $params, $header, $this->httpTimeout);
$result = json_decode($resultJson, true);
if ($result['success']) {
if (is_array($result) && !empty($result['success'])) {
$finally = 1;
$allMeetIds[] = $result['data'];
$allResults[] = $result;
ThirdAppointmentLog::add($model->id, 0, $model->user_id, $url, $params, $result, $finally, '会议室预约-' . $currentDate->format('Y-m-d'));
} else {
$out = $resultJson;
ThirdAppointmentLog::add($model->id, 0, $model->user_id, $url, $params, $result, $finally, '会议室预约-' . $currentDate->format('Y-m-d'));
$out = is_string($resultJson) && $resultJson !== '' ? $resultJson : '爱预约请求超时或返回异常';
ThirdAppointmentLog::add($model->id, 0, $model->user_id, $url, $params, is_array($result) ? $result : $out, $finally, '会议室预约-' . $currentDate->format('Y-m-d'));
return false;
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
$out = $e->getMessage();
ThirdAppointmentLog::add($model->id, 0, $model->user_id, $url, $params, $result, $finally, '会议室预约-' . $currentDate->format('Y-m-d'));
ThirdAppointmentLog::add($model->id, 0, $model->user_id, $url, $params, $result ?: $resultJson, $finally, '会议室预约-' . $currentDate->format('Y-m-d'));
return false;
}
@ -187,17 +194,16 @@ class MeetRepository
$result = [];
$finally = 0;
try {
$resultJson = httpCurl($url, 'GET', $params, $header);
$resultJson = httpCurl($url, 'GET', $params, $header, $this->httpTimeout);
$out = $resultJson;
$result = json_decode($resultJson, true);
if ($result['success']) {
if (is_array($result) && !empty($result['success'])) {
$finally = 1;
return true;
} else {
$out = $resultJson;
return false;
}
} catch (\Exception $e) {
$out = is_string($resultJson) && $resultJson !== '' ? $resultJson : '爱预约取消请求超时或返回异常';
return false;
} catch (\Throwable $e) {
$out = $e->getMessage();
return false;
} finally {
@ -223,17 +229,16 @@ class MeetRepository
'end' => $endDate,
];
try {
$resultJson = httpCurl($url, 'GET', $params, $header);
$resultJson = httpCurl($url, 'GET', $params, $header, $this->httpTimeout);
$out = $resultJson;
$result = json_decode($resultJson, true);
if ($result['success']) {
if (is_array($result) && !empty($result['success'])) {
$out = $result['data'];
return true;
} else {
$out = $resultJson;
return false;
}
} catch (\Exception $e) {
$out = is_string($resultJson) && $resultJson !== '' ? $resultJson : '爱预约查询超时或返回异常';
return false;
} catch (\Throwable $e) {
$out = $e->getMessage();
return false;
}

Loading…
Cancel
Save