|
|
|
@ -2,191 +2,72 @@ |
|
|
|
|
|
|
|
namespace App\Services; |
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Http; |
|
|
|
use Illuminate\Support\Facades\Redis; |
|
|
|
use App\Models\ParkingCameraSendLog; |
|
|
|
|
|
|
|
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() |
|
|
|
/** |
|
|
|
* 创建变更设备信息 |
|
|
|
* @param $camera_ip |
|
|
|
* @param $color_occupy |
|
|
|
* @param $color_vacant |
|
|
|
* @param $is_flicker |
|
|
|
* @return void |
|
|
|
*/ |
|
|
|
public static function setBody($camera_ip, $color_occupy, $color_vacant, $is_flicker) |
|
|
|
{ |
|
|
|
$url = $this->getUri() . $this->MULTI_PARKING_SPACES_LAMP; |
|
|
|
$query = [ |
|
|
|
'format' => $this->format, |
|
|
|
'security' => 1, |
|
|
|
'iv' => md5(rand('000000', '999999')) |
|
|
|
$body = [ |
|
|
|
'camera_ip' => $camera_ip, |
|
|
|
'color_occupy' => $color_occupy, |
|
|
|
'color_vacant' => $color_vacant, |
|
|
|
'is_flicker' => $is_flicker ? 1 : 0, |
|
|
|
]; |
|
|
|
$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; |
|
|
|
$exists = ParkingCameraSendLog::query()->where($body)->where( |
|
|
|
'status', |
|
|
|
0 |
|
|
|
)->exists(); |
|
|
|
if (!$exists) { |
|
|
|
$body['created_at'] = get_datetime(); |
|
|
|
ParkingCameraSendLog::query()->create($body); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 组合 设备ip地址 |
|
|
|
protected function getUri() |
|
|
|
/** |
|
|
|
* 返回需要变更设备信息 |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
public static function getBody(): array |
|
|
|
{ |
|
|
|
$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_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" |
|
|
|
] |
|
|
|
] |
|
|
|
$columns = [ |
|
|
|
'id', |
|
|
|
'camera_ip as ip', |
|
|
|
'color_occupy', |
|
|
|
'color_vacant', |
|
|
|
'is_flicker', |
|
|
|
]; |
|
|
|
return $body; |
|
|
|
$body = ParkingCameraSendLog::query()->where('status', 0)->select( |
|
|
|
$columns |
|
|
|
)->get()->each(function ($item) { |
|
|
|
$item['is_flicker'] = (bool)$item['is_flicker'] == 1; |
|
|
|
return $item; |
|
|
|
})->toArray(); |
|
|
|
if (!$body) { |
|
|
|
return []; |
|
|
|
} |
|
|
|
return ['list' => $body]; |
|
|
|
} |
|
|
|
|
|
|
|
public function updatelight($body) |
|
|
|
/** |
|
|
|
* 变更成功回调 |
|
|
|
* @param $id |
|
|
|
* @return void |
|
|
|
*/ |
|
|
|
public static function sendSuccessful($id): void |
|
|
|
{ |
|
|
|
/*$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); |
|
|
|
|
|
|
|
Redis::set('camera_body', json_encode($body), 300); |
|
|
|
//dd($response->json(), $response->body(), $response->object(), $response); |
|
|
|
$model = ParkingCameraSendLog::query()->find($id); |
|
|
|
$model->update([ |
|
|
|
'status' => 1, |
|
|
|
'updated_at' => get_datetime() |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
|