1. Go to this page and download the library: Download jot/hf-hkvsn library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// config/autoload/dependencies.php
use Hyperf\Guzzle\ClientFactory;
use Jot\HikVision\HyperfDevice;
return [
// Register the ClientFactory as a singleton in the container
ClientFactory::class => ClientFactory::class,
// Register a device with default configuration
'device.default' => function(ClientFactory $clientFactory) {
$config = [
'protocol' => 'http',
'ip_address' => '192.168.1.100',
'port' => 80,
'username' => 'admin',
'password' => 'admin',
];
$device = new HyperfDevice($config);
// Manually inject the ClientFactory since we're not using annotations here
$device->clientFactory = $clientFactory;
return $device;
},
];
declare(strict_types=1);
namespace App\Service;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Guzzle\ClientFactory;
use Jot\HikVision\HyperfDevice;
class DeviceService
{
/**
* @Inject
* @var ClientFactory
*/
protected ClientFactory $clientFactory;
public function createDevice(array $config): HyperfDevice
{
$device = new HyperfDevice($config);
// Manually inject the ClientFactory
$device->clientFactory = $this->clientFactory;
return $device;
}
public function getDeviceInfo(array $config): array
{
$device = $this->createDevice($config);
return $device->info()->toArray();
}
// Add more methods as needed...
}
declare(strict_types=1);
namespace App\Controller;
use App\Service\DeviceService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
/**
* @Controller(prefix="/api/device")
*/
class DeviceController
{
/**
* @Inject
* @var RequestInterface
*/
protected RequestInterface $request;
/**
* @Inject
* @var ResponseInterface
*/
protected ResponseInterface $response;
/**
* @Inject
* @var DeviceService
*/
protected DeviceService $deviceService;
/**
* @RequestMapping(path="info", methods="get")
*/
public function info(): ResponseInterface
{
$config = [
'protocol' => $this->request->input('protocol', 'http'),
'ip_address' => $this->request->input('ip', '192.168.1.100'),
'port' => (int) $this->request->input('port', 80),
'username' => $this->request->input('username', 'admin'),
'password' => $this->request->input('password', 'admin'),
];
$info = $this->deviceService->getDeviceInfo($config);
return $this->response->json($info);
}
// Add more endpoints as needed...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.