From 9897ef76ad35547bd56e8fe387c9a104a9012050 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq.com> Date: Thu, 28 May 2026 15:23:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95-=E4=BF=AE=E6=94=B9=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E6=9B=B4=E6=94=B9=E8=BD=A6=E4=BD=8D=E7=81=AF=E9=A2=9C?= =?UTF-8?q?=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/HikParkingCameraService.php | 190 +++++++++++++++++++++++ app/Services/ParkingSpaceService.php | 24 +++ 2 files changed, 214 insertions(+) create mode 100644 app/Services/HikParkingCameraService.php diff --git a/app/Services/HikParkingCameraService.php b/app/Services/HikParkingCameraService.php new file mode 100644 index 0000000..01cc945 --- /dev/null +++ b/app/Services/HikParkingCameraService.php @@ -0,0 +1,190 @@ +device = [ + 'protocol' => 'http', + 'ip' => '192.168.66.64', + 'port' => '', + 'username' => 'admin', + 'password' => 'Xingtong1124', + ]; + //$this->device = $device; + } + + public function getLight() + { + $url = $this->getUri() . $this->MULTI_PARKING_SPACES_LAMP; + $query = [ + 'format' => $this->format, + 'security' => 1, + 'iv' => md5(rand('000000', '999999')) + ]; + $url .= '?' . http_build_query($query); + + + + $response = Http::timeout(3) + ->withoutVerifying() + ->withDigestAuth($this->device['username'], $this->device['password']) + ->get($url); + //dd($response->json(), $response->body(), $response->object(), $response); + try { + $response = $response->json(); + if ($response->getStatusCode() == '200') { + + } + } catch (\Exception $e) { + throw $e; + } + } + + // 组合 设备ip地址 + protected function getUri() + { + $protocol = $this->device['protocol']; + $ip = $this->device['ip']; + $port = $this->device['port'] ?? ''; + $uri = $protocol . '://' . $ip; + if ($port) { + $uri .= ':' . $port; + } + return $uri; + } + + public function getBody($color_occupy, $color_vacant, $is_flicker) + { + $is_flicker = (bool)$is_flicker; + $body = [ + "lampType" => "internal", + "VehicleNumber" => [ + "VehicleChannelNum" => 1, + "VehicleChannelList" => [ + [ + "LampSoure" => "internal", // unrelated + "VehicleNoExist" => [ + "enabled" => true, + "flashEnabled" => $is_flicker, + "lampColor" => $color_occupy + ], + "VehicleExist" => [ + "enabled" => true, + "flashEnabled" => $is_flicker, + "lampColor" => $color_vacant + ] + ] + ] + ], + "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" + ] + ] + ]; + return $body; + } + + public function updatelight($body) + { + /*$body = [ + "lampType" => "internal", + "VehicleNumber" => [ + "VehicleChannelNum" => 1, + "VehicleChannelList" => [ + [ + "LampSoure" => "internal", // unrelated + "VehicleNoExist" => [ + "enabled" => true, + "flashEnabled" => false, + "lampColor" => "close" + ], + "VehicleExist" => [ + "enabled" => true, + "flashEnabled" => false, + "lampColor" => "close" + ] + ] + ] + ], + "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" + ] + ] + ];*/ + $url = $this->getUri() . $this->MULTI_PARKING_SPACES_LAMP; + $query = [ + 'format' => $this->format, + 'security' => 1, + 'iv' => md5(rand('000000', '999999')) + ]; + $url .= '?' . http_build_query($query); + + $response = Http::timeout(3) + ->withoutVerifying() + ->withDigestAuth($this->device['username'], $this->device['password']) + ->put($url, $body); + //dd($response->json(), $response->body(), $response->object(), $response); + } +} diff --git a/app/Services/ParkingSpaceService.php b/app/Services/ParkingSpaceService.php index a21c095..0cd88b6 100644 --- a/app/Services/ParkingSpaceService.php +++ b/app/Services/ParkingSpaceService.php @@ -7,6 +7,7 @@ use App\Models\ParkingLicensePlate; use App\Models\ParkingSpace; use App\Models\ParkingSpaceAttributes; use App\Models\ParkingSpaceType; +use App\Models\ParkingSpaceTypeAttr; use Exception; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; @@ -327,5 +328,28 @@ class ParkingSpaceService extends BaseService $oldValues, $this->getLogDescription('space_type_id') ); + // 切换车位类型,同步切换车位灯颜色 + $this->changeSpaceCameraColor($oldValues['number'], $type_id, $oldValues['space_attr_id']); + } + + // 切换模式更改车位类型 后 更改车位灯颜色 + protected function changeSpaceCameraColor($number, $space_type_id, $space_attr) + { + if ($number == '1-1') { + $SpaceType = ParkingSpaceType::query()->find($space_type_id); + $SpaceTypeAttr = ParkingSpaceTypeAttr::getSpaceTypeAttrInfo($space_type_id, $space_attr); + + $color_occupy = $SpaceType['default_color_occupy']; + $color_vacant = $SpaceType['default_color_vacant']; + $is_flicker = $SpaceType['default_is_warning']; + if ($SpaceTypeAttr) { + $color_occupy = $SpaceTypeAttr['color_occupy']; + $color_vacant = $SpaceTypeAttr['color_vacant']; + $is_flicker = $SpaceTypeAttr['is_warning']; + } + $HikParkingCameraService = new HikParkingCameraService($this->logService); + $body = $HikParkingCameraService->getBody($color_occupy, $color_vacant, $is_flicker); + $HikParkingCameraService->updatelight($body); + } } }