<?php
declare(strict_types=1);

error_reporting(E_ALL);
ini_set('display_errors', '1');

function hikRequestJson(
    string $host,
    int $port,
    string $user,
    string $pass,
    string $path,
    array $payload
): array {
    $url = "http://{$host}:{$port}{$path}";

    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPAUTH       => CURLAUTH_DIGEST | CURLAUTH_BASIC,
        CURLOPT_USERPWD        => "{$user}:{$pass}",
        CURLOPT_CONNECTTIMEOUT => 8,
        CURLOPT_TIMEOUT        => 20,
        CURLOPT_POST           => true,
        CURLOPT_HTTPHEADER     => [
            'Content-Type: application/json',
            'Accept: application/json',
        ],
        CURLOPT_POSTFIELDS     => json_encode($payload, JSON_UNESCAPED_UNICODE),
    ]);

    $resp = curl_exec($ch);
    $err  = curl_error($ch);
    $code = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);

    curl_close($ch);

    return [
        'code' => $code,
        'body' => $resp,
        'err'  => $err,
        'url'  => $url,
    ];
}

$host = '192.168.100.254';
$port = 80;
$user = 'admin';
$pass = '28251714.';

$payload = [
    'UserInfoSearchCond' => [
        'searchID' => '1',
        'searchResultPosition' => 0,
        'maxResults' => 50,
    ]
];

$r = hikRequestJson(
    $host,
    $port,
    $user,
    $pass,
    '/ISAPI/AccessControl/UserInfo/Search?format=json',
    $payload
);

header('Content-Type: text/plain; charset=utf-8');
echo "URL: {$r['url']}\n";
echo "HTTP CODE: {$r['code']}\n";
echo "CURL ERROR: {$r['err']}\n\n";
echo $r['body'];