diff --git a/app/Console/Commands/VehicleEntryAndExit.php b/app/Console/Commands/VehicleEntryAndExit.php new file mode 100644 index 0000000..789d327 --- /dev/null +++ b/app/Console/Commands/VehicleEntryAndExit.php @@ -0,0 +1,56 @@ +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(); + } +} diff --git a/app/Services/Api/BaseApiService.php b/app/Services/Api/BaseApiService.php index a26cdbb..f7789b1 100644 --- a/app/Services/Api/BaseApiService.php +++ b/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 []; } } diff --git a/app/Services/Api/CameraApiService.php b/app/Services/Api/CameraApiService.php index 51c5db1..eb9fbfc 100644 --- a/app/Services/Api/CameraApiService.php +++ b/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); } } diff --git a/app/Services/Device/BaseService.php b/app/Services/Device/BaseService.php index 0e008e8..8e2b563 100644 --- a/app/Services/Device/BaseService.php +++ b/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); + } } diff --git a/app/Services/Device/CameraDeviceService.php b/app/Services/Device/CameraDeviceService.php index 955bbc2..a9822d7 100644 --- a/app/Services/Device/CameraDeviceService.php +++ b/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 ''; + } }