我目前正在使用连接在 LAN 上的考勤设备进行考勤管理系统项目,我拥有 ZKTeco 公司的型号 SC700。不幸的是,该设备没有使用 Web 服务器实现,因此唯一的交互方式是使用 UDP 端口 4370。这也意味着我不能使用这个美妙的库https://github.com/cobisja/tad- php
该项目是自定义的,用 PHP(Codeigniter 3)编写,我使用了来自 github(https://github.com/dnaextrim/php_zklib)的 dnaextrim 库与设备进行交互。到目前为止一切顺利,除了 SetUser 功能外,一切都很好。我可以从我的应用程序中为设备设置一个具有 ID、姓名、密码、角色的新用户,但我无法设置他将要使用的卡的 RFID。
该函数构建一个 74 字符长的字符串并将其发送到设备,如下所示
function zksetuser($self, $uid, $userid, $name, $password, $role, $card) {
$command = CMD_SET_USER;
//$command_string = str_pad(chr( $uid ), 2, chr(0)).chr($role).str_pad($password, 8, chr(0)).str_pad($name, 28, chr(0)).str_pad(chr(1), 9, chr(0)).str_pad($userid, 8, chr(0)).str_repeat(chr(0),16);
$byte1 = chr((int) ($uid % 256));
$byte2 = chr((int) ($uid >> 8));
$command_string = $byte1 . $byte2 . chr($role) . str_pad($password, 8, chr(0)) . str_pad($name, 24, chr(0)) . str_pad($card, 13, chr(0)) . str_pad($userid, 8, chr(0)) . str_repeat(chr(0), 16);
$chksum = 0;
$session_id = $self->session_id;
$u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr($self->data_recv, 0, 8));
$reply_id = hexdec($u['h8'] . $u['h7']);
$buf = $self->createHeader($command, $chksum, $session_id, $reply_id, $command_string);
socket_sendto($self->zkclient, $buf, strlen($buf), 0, $self->ip, $self->port);
try {
@socket_recvfrom($self->zkclient, $self->data_recv, 1024, 0, $self->ip, $self->port);
$u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6', substr($self->data_recv, 0, 8));
$self->session_id = hexdec($u['h6'] . $u['h5']);
return substr($self->data_recv, 8);
} catch (ErrorException $e) {
return FALSE;
} catch (exception $e) {
return False;
}
}
参数 $card 由我实现,所以我可以传递卡的 RFID 编号,但问题是设备将我发送的 RFID“转换”为另一个编号!我不知道它对这种转换做了什么操作,或者我应该怎么做才能用他的 RFID 卡映射用户。
有没有人用 PHP 用 ZKTeco SC700 解决过这个问题?