Browse Source

测试-修改模式更改车位灯颜色

master
wanghongjun 3 weeks ago
parent
commit
9897ef76ad
  1. 190
      app/Services/HikParkingCameraService.php
  2. 24
      app/Services/ParkingSpaceService.php

190
app/Services/HikParkingCameraService.php

@ -0,0 +1,190 @@
<?php
namespace App\Services;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Http;
class HikParkingCameraService
{
public array $device;
public string $format = 'json';
protected string $MULTI_PARKING_SPACES_LAMP = '/ISAPI/Parking/parkingSpace/multiParkingSpacesLamp';
public function __construct($device)
{
$this->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);
}
}

24
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);
}
}
}

Loading…
Cancel
Save