停车场系统数据中间件
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

150 lines
5.1 KiB

<?php
namespace App\Services\Device;
use JetBrains\PhpStorm\ArrayShape;
class CameraDeviceService extends BaseService
{
protected string $MULTI_PARKING_SPACES_LAMP = '/ISAPI/Parking/parkingSpace/multiParkingSpacesLamp';
protected string $SYSTEM_STATUS = '/ISAPI/System/status';
protected string $PARKING_STATUS = '/ISAPI/Parking/channels/?/ParkingStatus';
protected string $TRAFFIC_MNPR = '/ISAPI/Traffic/MNPR/channels/';
/**
* @param $ip
* @return CameraDeviceService
*/
public static function query($ip): CameraDeviceService
{
return new self($ip);
}
/**
* 更新车位相机灯光颜色
* @param string $color_occupy
* @param string $color_vacant
* @param bool $is_flicker
* @return array
*/
public function setColor(
string $color_occupy,
string $color_vacant,
bool $is_flicker
): array {
$url = $this->getUrl($this->MULTI_PARKING_SPACES_LAMP);
$body = $this->getColorBody($color_occupy, $color_vacant, $is_flicker);
if (!$body) {
return [];
}
$response = $this->putHttp($url, $body);
return json_decode($response->body(), true);
}
/**
* 获取车位相机信息
* @param $color_occupy
* @param $color_vacant
* @param $is_flicker
* @return array
*/
public function getColorBody(
$color_occupy,
$color_vacant,
$is_flicker
): array {
$is_flicker = (bool)$is_flicker;
$url = $this->getUrl($this->MULTI_PARKING_SPACES_LAMP);
$response = $this->getHttp($url);
$body = json_decode($response->body(), true);
if ($body) {
if (isset($body['VehicleNumber']['VehicleChannelList'][0])) {
$VehicleChannelList
= $body['VehicleNumber']['VehicleChannelList'][0];
if (isset($VehicleChannelList['VehicleNoExist'])) {
// 是否闪烁
$body['VehicleNumber']['VehicleChannelList'][0]['VehicleNoExist']['flashEnabled']
= $is_flicker;
// 无车显示颜色
$body['VehicleNumber']['VehicleChannelList'][0]['VehicleNoExist']['lampColor']
= $color_vacant;
}
if (isset($VehicleChannelList['VehicleExist'])) {
// 是否闪烁
$body['VehicleNumber']['VehicleChannelList'][0]['VehicleExist']['flashEnabled']
= $is_flicker;
// 有车显示颜色
$body['VehicleNumber']['VehicleChannelList'][0]['VehicleExist']['lampColor']
= $color_occupy;
}
}
} else {
return [];
}
return $body;
}
// 获取车位状态
public function getStatus(): bool
{
$url = $this->getUrl($this->SYSTEM_STATUS);
$response = $this->getHttp($url);
return $response->successful();
}
// 返回车牌号码
public function getParkingNo($channels_id = 1)
{
$url = $this->getUrl(str_replace('?', $channels_id, $this->PARKING_STATUS));
$response = $this->getHttp($url);
$body = $response->body();
$bodyArr = $this->getBodyArray($body);
if (isset($bodyArr['ParkingStatusList']['ParkingStatus'])) {
$parkingStatus = $bodyArr['ParkingStatusList']['ParkingStatus'];
if ($parkingStatus['carStatus'] == 'true') {
return $parkingStatus['plateNo'];
}
}
return '';
}
// 抓拍车位车牌及现场图片
#[ArrayShape([
'licensePlate' => "mixed|string", // 车牌号码
'images_data' => "mixed|string", // 场景图
'confidenceLevel' => "mixed|string", // 识别度
'dateTime' => "mixed|string" //
])] public function getTrafficMNPR(int $channels_id = 1): array
{
$url = $this->getUrl($this->TRAFFIC_MNPR . $channels_id);
$response = $this->getHttp($url);
$body = $response->body();
$parsed = CommonService::parseMultipart($body);
$data = [
'licensePlate' => '',
'images_data' => '',
'confidenceLevel' => '',
'dateTime' => ''
];
if ($parsed['xml'] && is_array($parsed['xml'])) {
if (isset($parsed['xml']['ANPR']['licensePlate'])) {
$licensePlate = $parsed['xml']['ANPR']['licensePlate'];
if ($licensePlate != '无车牌') {
$data['licensePlate'] = $licensePlate;
}
$data['confidenceLevel'] = $parsed['xml']['ANPR']['confidenceLevel'];
}
if (isset($parsed['xml']['dateTime'])) {
$data['dateTime'] = $parsed['xml']['dateTime'];
}
}
if ($data['licensePlate'] && $parsed['images'] && is_array($parsed['images'])) {
$endData = end($parsed['images']);
if (isset($endData['data'])) {
$data['images_data'] = $endData['data'];
}
}
return $data;
}
}