Browse Source

车辆进出记录

master
wanghongjun 1 month ago
parent
commit
fb3240f258
  1. 56
      app/Console/Commands/VehicleEntryAndExit.php
  2. 41
      app/Services/Api/BaseApiService.php
  3. 58
      app/Services/Api/CameraApiService.php
  4. 6
      app/Services/Device/BaseService.php
  5. 69
      app/Services/Device/CameraDeviceService.php

56
app/Console/Commands/VehicleEntryAndExit.php

@ -0,0 +1,56 @@
<?php
namespace App\Console\Commands;
use App\Services\Api\CameraApiService;
use App\Services\Device\CameraDeviceService;
use Illuminate\Console\Command;
class VehicleEntryAndExit extends Command
{
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'run:vehicle-entry-and-exit';
/**
* The console command description.
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*/
public function handle()
{
// 获取所有设备车位信息
$data = CameraApiService::query()->getCameraPlateNoBody();
if ($data && isset($data['body']['list'])) {
$list = $data['body']['list'];
// 通过设备信息获取设备状态
$data = [];
foreach ($list as $item) {
$ip = $item['camera_ip'];
try {
$ParkingNo = CameraDeviceService::query($ip)->getParkingNo();
} catch (\Exception $e) {
continue;
}
$data[] = [
'camera_ip' => $ip,
'number' => $item['number'],
'license_plate_number' => $ParkingNo,
'date_time' => date('Y-m-d H:i:s', time()),
];
}
// 返回告诉设备状态情况
CameraApiService::query()->putCameraPlateNoBody(['list' => $data]);
echo 'SUCCESS';
}
echo 'empty';
exit();
}
}

41
app/Services/Api/BaseApiService.php

@ -19,10 +19,10 @@ class BaseApiService
* @param array $query
* @return Response
*/
public function getHttp(string $url, array $query = []): Response
protected function getHttp(string $url, array $query = []): Response
{
$getUrl = $this->hostUrl . $url;
return Http::get($getUrl, $query);
return Http::withOptions(['verify' => false])->get($getUrl, $query);
}
/**
@ -30,9 +30,42 @@ class BaseApiService
* @param array $data
* @return Response
*/
public function putHttp(string $url, array $data): Response
protected function putHttp(string $url, array $data): Response
{
$getUrl = $this->hostUrl . $url;
return Http::put($getUrl, $data);
return Http::withOptions(['verify' => false])->put($getUrl, $data);
}
/**
* @param string $url
* @return array
*/
protected function getBody(string $url): array
{
$Response = $this->getHttp($url);
if ($Response->successful()) {
$body = $Response->body();
if ($body) {
return json_decode($body, true);
}
}
return [];
}
/**
* @param string $url
* @param array $data
* @return array
*/
protected function putBody(string $url, array $data): array
{
$Response = $this->putHttp($url, $data);
if ($Response->successful()) {
$body = $Response->body();
if ($body) {
return json_decode($body, true);
}
}
return [];
}
}

58
app/Services/Api/CameraApiService.php

@ -4,6 +4,12 @@ namespace App\Services\Api;
class CameraApiService extends BaseApiService
{
// 更新车位状态
protected string $CAMERA_STATUS = '/api/device/camera/getStatus';
// 控制车位相机灯光
protected string $CAMERA_COLOR_BODY = '/api/device/camera/getBody';
// 车辆进出车位
protected string $CAMERA_PLATE_NO = '/api/device/camera/vehicleEntry';
/**
* @return CameraApiService
@ -14,46 +20,38 @@ class CameraApiService extends BaseApiService
}
// 获取车位相机设备变更颜色信息
public function getCameraBody()
public function getCameraBody(): array
{
$url = '/api/device/camera/getBody';
$Response = $this->getHttp($url);
if ($Response->successful()) {
return json_decode($Response->body(), true);
}
return [];
return $this->getBody($this->CAMERA_COLOR_BODY);
}
// 返回变更车位相机设备状态接口
public function putCameraBody($data)
public function putCameraBody(array $data): array
{
$url = '/api/device/camera/getBody';
$Response = $this->putHttp($url, $data);
if ($Response->successful()) {
return json_decode($Response->body(), true);
}
return [];
return $this->putBody($this->CAMERA_COLOR_BODY, $data);
}
// 获取车位相机设备信息
public function getCameraStatus()
// 获取车位相机设备状态
public function getCameraStatus(): array
{
$url = '/api/device/camera/getStatus';
$Response = $this->getHttp($url);
if ($Response->successful()) {
return json_decode($Response->body(), true);
}
return [];
return $this->getBody($this->CAMERA_STATUS);
}
// 获取变更车位相机设备状态
public function putCameraStatus($data)
// 返回车位相机设备状态
public function putCameraStatus(array $data): array
{
$url = '/api/device/camera/getStatus';
$Response = $this->putHttp($url, $data);
if ($Response->successful()) {
return json_decode($Response->body(), true);
}
return [];
return $this->putBody($this->CAMERA_STATUS, $data);
}
// 获取车位相机信息
public function getCameraPlateNoBody(): array
{
return $this->getBody($this->CAMERA_PLATE_NO);
}
// 获取车位相机信息
public function putCameraPlateNoBody(array $data): array
{
return $this->putBody($this->CAMERA_PLATE_NO, $data);
}
}

6
app/Services/Device/BaseService.php

@ -60,4 +60,10 @@ class BaseService
$this->device['password']
)->get($url, $query);
}
protected function getBodyArray(string $body): array
{
$xml = simplexml_load_string($body);
return json_decode(json_encode($xml), true);
}
}

69
app/Services/Device/CameraDeviceService.php

@ -7,6 +7,7 @@ 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';
/**
* @param $ip
@ -88,57 +89,19 @@ class CameraDeviceService extends BaseService
return $response->successful();
}
/*
* body 信息
[
"lampType" => "internal",
"VehicleNumber" => [
"VehicleChannelNum" => 1,
"VehicleChannelList" => [
[
"LampSoure" => "internal", // unrelated
"VehicleNoExist" => [
"enabled" => true,
"flashEnabled" => $is_flicker,
"lampColor" => $color_vacant
],
"VehicleExist" => [
"enabled" => true,
"flashEnabled" => $is_flicker,
"lampColor" => $color_occupy
]
]
]
],
"replaceLampCtrl" => [
"enabled" => false,
"ipV4Address" => "0.0.0.0",
"portNo" => 80,
"username" => "admin",
"password" => "dddf4589f3430f7b7395bb9d35e05b27"
],
"lampStatusArr" => [
[
"name" => "内置灯",
"value" => "相机自控",
"\$\$hashKey" => "062"
],
[
"name" => "外置灯1",
"value" => "相机自控",
"\$\$hashKey" => "063"
],
[
"name" => "外置灯2",
"value" => "相机自控",
"\$\$hashKey" => "064"
],
[
"name" => "外置灯3",
"value" => "相机自控",
"\$\$hashKey" => "065"
]
]
]
*/
// 返回车牌号码
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 '';
}
}

Loading…
Cancel
Save