kamshory / ZKLibrary

ZKLibrary is PHP library for reading and writing data to attendance device using UDP protocol. This library useful to comunicate between web server and attendance device directly without addition program. This library is implemented in the form of class. So that you can create an object and use it functions.
GNU General Public License v2.0
194 stars 176 forks source link

Get finger prints #11

Open RahamSher opened 6 years ago

RahamSher commented 6 years ago

Dears @kamshory @junaidranjha how I can get the finger prints of a user.Please guide me.

kamshory commented 6 years ago

I am sorry. The function "getUserTemplate" is not define yet. I hope someone can help me to get the user template. May be you can do this?

RahamSher commented 6 years ago

Will try it must.

kamshory commented 6 years ago
<?php
public function getUserTemplate($uid, $finger)
    {
        $this->user_data = array();
        $command = CMD_USERTEMP_RRQ;
        $byte1 = chr((int)($uid % 256));
        $byte2 = chr((int)($uid >> 8));
        $command_string = $byte1.$byte2.chr($finger);

        $chksum = 0;
        $session_id = $this->session_id;
        $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr( $this->received_data, 0, 8) );
        $reply_id = hexdec( $u['h8'].$u['h7'] );
        $buf = $this->createHeader($command, $chksum, $session_id, $reply_id, $command_string);
        socket_sendto($this->socket, $buf, strlen($buf), 0, $this->ip, $this->port);
        try
        {
            socket_recvfrom($this->socket, $this->received_data, 1024, 0, $this->ip, $this->port);
            $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6', substr( $this->received_data, 0, 8 ) );
            $bytes = $this->getSizeTemplate();
            if($bytes)
            {
                while($bytes > 0)
                {
                    socket_recvfrom($this->socket, $received_data, 1032, 0, $this->ip, $this->port);
                    array_push( $this->user_data, $received_data);
                    $bytes -= 1024;                 
                }
                $this->session_id =  hexdec( $u['h6'].$u['h5'] );
                socket_recvfrom($this->socket, $received_data, 1024, 0, $this->ip, $this->port);
            }
            $template_data = array();
            if(count($this->user_data) > 0)
            {
                for($x=0; $x<count($this->user_data); $x++)
                {
                    if ($x == 0)
                    {
                        $this->user_data[$x] = substr($this->user_data[$x], 8);
                    }
                    else
                    {
                        $this->user_data[$x] = substr($this->user_data[$x], 8);
                    }
                }
                $user_data = implode('', $this->user_data);
                $template_size = strlen($user_data)+6;
                $prefix = chr($template_size%256).chr(round($template_size/256)).$byte1.$byte2.chr($finger).chr(1);
                $user_data = $prefix.substr($user_data, 0);

                if(strlen($user_data) > 6)
                {
                    $valid = 1;
                    $template_data = array($template_size, $uid, $finger, $valid, $user_data);
                }
            }
            return $template_data;
        } 
        catch(ErrorException $e) 
        {
            return FALSE;
        } 
        catch(exception $e) 
        {
            return FALSE;
        }
    }
?>
kmkmahesh commented 6 years ago

can you please tell me will both types(v9 and v10) works with this?

kamshory commented 6 years ago

Sir, I have only one fingerprint device. So I can't develop more than I have.

kmkmahesh commented 6 years ago

i am asking about fingerprint template

kamshory commented 6 years ago

I already write a function to get the user template. But when I try to write it to other device, it is failed. I don't have any documentation about it from the vendor.

This library focus to read time attendance. So, when you can read the time attendance from the device, it was enough for you.