2 changed files with 214 additions and 0 deletions
@ -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); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue