jot/hf-hkvsn

SDK for HikVision devices

v0.1.0 2025-03-17 15:54 UTC

This package is auto-updated.

Last update: 2025-03-17 15:58:10 UTC


README

SDK for HikVision face recognition devices, with Hyperf 3.1 compatibility.

Features

  • Device information and capabilities retrieval
  • User management
  • Face recognition management
  • Card management
  • Door control
  • Event monitoring
  • Full Hyperf 3.1 compatibility

Requirements

  • PHP 8.1 or higher
  • Hyperf 3.1 framework (for Hyperf integration)
  • GuzzleHTTP 7.8 or higher
  • Various PHP extensions (see composer.json)

Installation

composer require jot/HikVision

Usage with Hyperf 3.1

<?php

use Jot\HikVision\Device\DSK1T673DWX\Device;

// Create device instance
$device = new Device([
    'protocol' => 'http',
    'ip_address' => '192.168.1.100',
    'port' => 80,
    'username' => 'admin',
    'password' => 'admin',
]);

// Get device information
$info = $device->info()->toArray();

// Get device capabilities
$capabilities = $device->capabilities()->toArray();

// Update device configuration
$result = $device->update([
    'name' => 'My Device',
    'ntp' => [
        'ip_address' => '200.186.125.195',
        'port' => 123,
        'interval' => 1,
    ],
])->toArray();

Hyperf 3.1 Integration

This library provides Hyperf 3.1 compatible classes for integration with the Hyperf framework:

Configuration

Create a configuration file in your Hyperf project:

// 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;
    },
];

Using with Dependency Injection

Create a service class to encapsulate device operations:

<?php

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...
}

Use the service in your controller:

<?php

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...
}

License

Proprietary - All rights reserved