我目前正在使用局域网上连接的考勤设备进行考勤管理系统的项目,我拥有SC700公司的ZKTeco模型。不幸的是,设备不是用web服务器实现的,所以唯一的交互方式是使用UDP端口4370。这也意味着我不能使用这个很棒的库https://github.com/cobisja/tad-php
该项目是自定义的,用PHP(Codeigniter 3)编写,我使用来自github (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卡来映射一个用户。
以前有人用ZKTeco SC700解决过这个问题吗?
发布于 2022-11-24 12:48:44
这对我有用!
function reverseHex3($hex)
{
$tmp = '';
for ($i = strlen($hex); $i >= 0; $i--) {
$tmp .= substr($hex, $i, 2);
$i--;
}
return $tmp;
}
$cardno = hex2bin(reverseHex3(dechex($card)));
$command_string = implode('', [
$byte1,
$byte2,
chr($role),
str_pad($password, 8, chr(0)),
str_pad($name, 24, chr(0)),
str_pad($cardno, 4, chr(0)),
str_pad(chr(1), 9, chr(0)),
str_pad($userid, 9, chr(0)),
str_repeat(chr(0), 15)
]);https://stackoverflow.com/questions/42907603
复制相似问题