You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
48 lines
1.1 KiB
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
class BaseService
|
|
{
|
|
protected array $device;
|
|
protected array $username;
|
|
protected array $password;
|
|
public string $format = 'json';
|
|
|
|
public function __construct($ip)
|
|
{
|
|
$this->device = [
|
|
'protocol' => 'http',
|
|
'ip' => $ip,
|
|
'port' => '',
|
|
'username' => env('device_username', 'admin'),
|
|
'password' => env('device_password', 'Xingtong1124'),
|
|
];
|
|
}
|
|
|
|
protected function getUri()
|
|
{
|
|
$protocol = $this->device['protocol'];
|
|
$ip = $this->device['ip'];
|
|
$port = $this->device['port'] ?? '';
|
|
$uri = $protocol . '://' . $ip;
|
|
if ($port) {
|
|
$uri .= ':' . $port;
|
|
}
|
|
return $uri;
|
|
}
|
|
|
|
|
|
protected function getUrl($uri)
|
|
{
|
|
$url = $this->getUri() . $uri;
|
|
$query = [
|
|
'format' => $this->format,
|
|
'security' => 1,
|
|
'iv' => md5(rand('000000', '999999'))
|
|
];
|
|
return $url . '?' . http_build_query($query);
|
|
}
|
|
}
|
|
|