Full Code of raihanafroz/zkteco for AI

master 6487ac5dfab3 cached
20 files
45.4 KB
14.1k tokens
104 symbols
1 requests
Download .txt
Repository: raihanafroz/zkteco
Branch: master
Commit: 6487ac5dfab3
Files: 20
Total size: 45.4 KB

Directory structure:
gitextract__pwo6lda/

├── CHANGELOG.md
├── README.md
├── composer.json
└── src/
    ├── Lib/
    │   ├── Helper/
    │   │   ├── Attendance.php
    │   │   ├── Connect.php
    │   │   ├── Device.php
    │   │   ├── Face.php
    │   │   ├── Fingerprint.php
    │   │   ├── Os.php
    │   │   ├── Pin.php
    │   │   ├── Platform.php
    │   │   ├── SerialNumber.php
    │   │   ├── Ssr.php
    │   │   ├── Time.php
    │   │   ├── User.php
    │   │   ├── Util.php
    │   │   ├── Version.php
    │   │   └── WorkCode.php
    │   └── ZKTeco.php
    └── Providers/
        └── ZktecoServiceProvider.php

================================================
FILE CONTENTS
================================================

================================================
FILE: CHANGELOG.md
================================================


================================================
FILE: README.md
================================================
# ZKTeco - Laravel Library #

[![Issues](https://img.shields.io/github/issues/raihanafroz/zkteco?style=flat-square)](https://github.com/raihanafroz/zkteco/issues)
[![Forks](https://img.shields.io/github/forks/raihanafroz/zkteco?style=flat-square)](https://github.com/raihanafroz/zkteco/network/members)
[![Stars](https://img.shields.io/github/stars/raihanafroz/zkteco?style=flat-square)](https://github.com/raihanafroz/zkteco/stargazers)
[![Total Downloads](https://img.shields.io/packagist/dt/rats/zkteco?style=flat-square)](https://packagist.org/packages/rats/zkteco)
[![License](https://poser.pugx.org/rats/zkteco/license.svg)](https://packagist.org/packages/rats/zkteco)


The `rats/zkteco` package provides easy to use functions to ZKTeco Device activities.

__Requires:__  **Laravel** >= **6.0**

__License:__ MIT or later

## Installation:
You can install the package via composer:

``` bash
composer require rats/zkteco
```
The package will automatically register itself.

You have to enable your php socket if it is not enable. 


## Usage

1. Create a object of ZKTeco class.

```php
    use Rats\Zkteco\Lib\ZKTeco;

//  1 s't parameter is string $ip Device IP Address
//  2 nd  parameter is integer $port Default: 4370
  
    $zk = new ZKTeco('192.168.1.201');
    
//  or you can use with port
//    $zk = new ZKTeco('192.168.1.201', 8080);
    
```

2. Call ZKTeco methods

* __Connect__ 
```php
//    connect
//    this return bool
    $zk->connect();   
```

* __Disconnect__ 
```php
//    disconnect
//    this return bool

    $zk->disconnect();   
```

* __Enable Device__ 
```php
//    enable
//    this return bool/mixed

    $zk->enableDevice();   
```
> **NOTE**: You have to call after read/write any info of Device.

* __Disable Device__ 
```php
//    disable 
//    this return bool/mixed

    $zk->disableDevice(); 
```
> **NOTE**: You have to call before read/write any info of Device. 


* __Device Version__ 
```php
//    get device version 
//    this return bool/mixed

    $zk->version(); 
```


* __Device Os Version__ 
```php
//    get device os version 
//    this return bool/mixed

    $zk->osVersion(); 
```

* __Power Off__ 
```php
//    turn off the device 
//    this return bool/mixed

    $zk->shutdown(); 
```

* __Restart__ 
```php
//    restart the device 
//    this return bool/mixed

    $zk->restart(); 
```

* __Sleep__ 
```php
//    sleep the device 
//    this return bool/mixed

    $zk->sleep(); 
```

* __Resume__ 
```php
//    resume the device from sleep 
//    this return bool/mixed

    $zk->resume(); 
```

* __Voice Test__ 
```php
//    voice test of the device "Thank you" 
//    this return bool/mixed

    $zk->testVoice(); 
```

* __Platform__ 
```php
//    get platform 
//    this return bool/mixed

    $zk->platform(); 
```

* __Firmware Version__ 
```php
//    get firmware version
//    this return bool/mixed

    $zk->fmVersion(); 
```

* __Work Code__ 
```php
//    get work code
//    this return bool/mixed

    $zk->workCode(); 
```

* __SSR__ 
```php
//    get SSR
//    this return bool/mixed

    $zk->ssr(); 
```

* __Pin Width__ 
```php
//    get  Pin Width
//    this return bool/mixed

    $zk->pinWidth(); 
```

* __Serial Number__ 
```php
//    get device serial number
//    this return bool/mixed

    $zk->serialNumber(); 
```

* __Device Name__ 
```php
//    get device name
//    this return bool/mixed

    $zk->deviceName(); 
```

* __Get Device Time__ 
```php
//    get device time

//    return bool/mixed bool|mixed Format: "Y-m-d H:i:s"

    $zk->getTime(); 
```

* __Set Device Time__ 
```php
//    set device time
//    parameter string $t Format: "Y-m-d H:i:s"
//    return bool/mixed

    $zk->setTime(); 
```

* __Get Users__ 
```php
//    get User
//    this return array[]

    $zk->getUser(); 
```

* __Set Users__ 
```php
//    set user

//    1 s't parameter int $uid Unique ID (max 65535)
//    2 nd parameter int|string $userid ID in DB (same like $uid, max length = 9, only numbers - depends device setting)
//    3 rd parameter string $name (max length = 24)
//    4 th parameter int|string $password (max length = 8, only numbers - depends device setting)
//    5 th parameter int $role Default Util::LEVEL_USER
//    6 th parameter int $cardno Default 0 (max length = 10, only numbers

//    return bool|mixed

    $zk->setUser(); 
```

* __Clear All Admin__ 
```php
//    remove all admin
//    return bool|mixed

    $zk->clearAdmin(); 
```

* __Clear All Users__ 
```php
//    remove all users
//    return bool|mixed

    $zk->clearAdmin(); 
```

* __Remove A User__ 
```php
//    remove a user by $uid
//    parameter integer $uid
//    return bool|mixed

    $zk->removeUser(); 
```

* __Get Attendance Log__ 
```php
//    get attendance log

//    return array[]

//    like as 0 => array:5 [▼
//              "uid" => 1      /* serial number of the attendance */
//              "id" => "1"     /* user id of the application */
//              "state" => 1    /* the authentication type, 1 for Fingerprint, 4 for RF Card etc */
//              "timestamp" => "2020-05-27 21:21:06" /* time of attendance */
//              "type" => 255   /* attendance type, like check-in, check-out, overtime-in, overtime-out, break-in & break-out etc. if attendance type is none of them, it gives  255. */
//              ]

    $zk->getAttendance(); 
```

* __Clear Attendance Log__ 
```php
//    clear attendance log

//    return bool/mixed

    $zk->clearAttendance(); 
```







# end


================================================
FILE: composer.json
================================================
{
    "name": "rats/zkteco",
    "description": "ZKTeco Laravel Library",
    "type": "library",
    "license": "MIT",
    "authors": [
        {
            "name": "Raihan Afroz",
            "email": "raihanafroz9@gmail.com"
        }
    ],
    "autoload": {
      "psr-4":{
          "Rats\\Zkteco\\": "src"
      }
    },
    "minimum-stability": "dev",
    "require": {}
}


================================================
FILE: src/Lib/Helper/Attendance.php
================================================
<?php

namespace Rats\Zkteco\Lib\Helper;

use Rats\Zkteco\Lib\ZKTeco;

class Attendance
{
    /**
     * @param ZKTeco $self
     * @return array [uid, id, state, timestamp]
     */
    static public function get(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_ATT_LOG_RRQ;
        $command_string = '';

        $session = $self->_command($command, $command_string, Util::COMMAND_TYPE_DATA);
        if ($session === false) {
            return [];
        }

        $attData = Util::recData($self);

        $attendance = [];
        if (!empty($attData)) {
            $attData = substr($attData, 10);

            while (strlen($attData) > 40) {
                $u = unpack('H78', substr($attData, 0, 39));

                $u1 = hexdec(substr($u[1], 4, 2));
                $u2 = hexdec(substr($u[1], 6, 2));
                $uid = $u1 + ($u2 * 256);
                $id = hex2bin(substr($u[1], 8, 18));
                $id = str_replace(chr(0), '', $id);
                $state = hexdec(substr($u[1], 56, 2));
                $timestamp = Util::decodeTime(hexdec(Util::reverseHex(substr($u[1], 58, 8))));
                $type = hexdec(Util::reverseHex(substr($u[1], 66, 2 )));
				
                $attendance[] = [
                    'uid' => $uid,
                    'id' => $id,
                    'state' => $state,
                    'timestamp' => $timestamp,
                    'type' => $type
                ];

                $attData = substr($attData, 40);
            }

        }

        return $attendance;
    }

    /**
     * @param ZKTeco $self
     * @return bool|mixed
     */
    static public function clear(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_CLEAR_ATT_LOG;
        $command_string = '';

        return $self->_command($command, $command_string);
    }
}


================================================
FILE: src/Lib/Helper/Connect.php
================================================
<?php

namespace Rats\Zkteco\Lib\Helper;

use Rats\Zkteco\Lib\Helper\Util;
use Rats\Zkteco\Lib\ZKTeco;
use ErrorException;
use Exception;

class Connect
{
    /**
     * @param ZKTeco $self
     * @return bool
     */
    static public function connect(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_CONNECT;
        $command_string = '';
        $chksum = 0;
        $session_id = 0;
        $reply_id = -1 + Util::USHRT_MAX;

        $buf = Util::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);
            if (strlen($self->_data_recv) > 0) {
                $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6', substr($self->_data_recv, 0, 8));

                $session = hexdec($u['h6'] . $u['h5']);
                if (empty($session)) {
                    return false;
                }

                $self->_session_id = $session;
                return Util::checkValid($self->_data_recv);
            } else {
                return false;
            }
        } catch (ErrorException $e) {
            return false;
        } catch (Exception $e) {
            return false;
        }
    }

    /**
     * @param ZKTeco $self
     * @return bool
     */
    static public function disconnect(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_EXIT;
        $command_string = '';
        $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 = Util::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);

            $self->_session_id = 0;
            return Util::checkValid($self->_data_recv);
        } catch (ErrorException $e) {
            return false;
        } catch (Exception $e) {
            return false;
        }
    }
}

================================================
FILE: src/Lib/Helper/Device.php
================================================
<?php

namespace Rats\Zkteco\Lib\Helper;

use Rats\Zkteco\Lib\ZKTeco;

class Device
{
  /**
   * @param ZKTeco $self
   * @return bool|mixed
   */
  static public function name(ZKTeco $self)
  {
    $self->_section = __METHOD__;

    $command = Util::CMD_DEVICE;
    $command_string = '~DeviceName';

    return $self->_command($command, $command_string);
  }

  /**
   * @param ZKTeco $self
   * @return bool|mixed
   */
  static public function enable(ZKTeco $self)
  {
    $self->_section = __METHOD__;

    $command = Util::CMD_ENABLE_DEVICE;
    $command_string = '';

    return $self->_command($command, $command_string);
  }

  /**
   * @param ZKTeco $self
   * @return bool|mixed
   */
  static public function disable(ZKTeco $self)
  {
    $self->_section = __METHOD__;

    $command = Util::CMD_DISABLE_DEVICE;
    $command_string = chr(0) . chr(0);

    return $self->_command($command, $command_string);
  }

  /**
   * @param ZKTeco $self
   * @return bool|mixed *** this will turn off the device
   */
  public static function powerOff(ZKTeco $self)
  {
    $self->_section = __METHOD__;

    $command = Util::CMD_POWEROFF;
    $command_string = chr(0) . chr(0);
    return $self->_command($command, $command_string);
  }


  /**
   * @param ZKTeco $self
   * @return bool|mixed *** this will restart the device
   */
  public static function restart(ZKTeco $self)
  {
    $self->_section = __METHOD__;

    $command = Util::CMD_RESTART;
    $command_string = chr(0) . chr(0);
    return $self->_command($command, $command_string);
  }


  /**
   * @param ZKTeco $self
   * @return bool|mixed *** this will sleep the device
   */
  public static function sleep(ZKTeco $self)
  {
    $self->_section = __METHOD__;

    $command = Util::CMD_SLEEP;
    $command_string = chr(0) . chr(0);
    return $self->_command($command, $command_string);
  }


  /**
   * @param ZKTeco $self
   * @return bool|mixed *** this will resume the device from sleep
   */
  public static function resume(ZKTeco $self)
  {
    $self->_section = __METHOD__;

    $command = Util::CMD_RESUME;
    $command_string = chr(0) . chr(0);
    return $self->_command($command, $command_string);
  }


  /**
   * @param ZKTeco $self
   * @return bool|mixed *** this will play voice "Thank you"
   */
  public static function testVoice(ZKTeco $self)
  {
    $self->_section = __METHOD__;

    $command = Util::CMD_TESTVOICE;
    $command_string = chr(0) . chr(0);
    return $self->_command($command, $command_string);
  }


  /**
   * @param ZKTeco $self
   * @return bool|mixed *** this will clear the LCD screen
   */
  public static function clearLCD(ZKTeco $self)
  {
    $self->_section = __METHOD__;

    $command = Util::CMD_CLEAR_LCD;
    return $self->_command($command, '');
  }


  /**
   * @param ZKTeco $self
   * @param $rank *** Line number of text
   * @param $text *** Text which will display in the LCD screen
   * @return bool|mixed *** this will write text into the LCD
   */
  public static function writeLCD(ZKTeco $self, $rank, $text)
  {
    $self->_section = __METHOD__;

    $command = Util::CMD_WRITE_LCD;
    $byte1 = chr((int)($rank % 256));
    $byte2 = chr((int)($rank >> 8));
    $byte3 = chr(0);
    $command_string = $byte1.$byte2.$byte3.' '.$text;
    return $self->_command($command, $command_string);
  }
}

================================================
FILE: src/Lib/Helper/Face.php
================================================
<?php

namespace Rats\Zkteco\Lib\Helper;

use Rats\Zkteco\Lib\ZKTeco;

class Face
{
    /**
     * @param ZKTeco $self
     * @return bool|mixed
     */
    static public function on(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_DEVICE;
        $command_string = 'FaceFunOn';

        return $self->_command($command, $command_string);
    }
}



================================================
FILE: src/Lib/Helper/Fingerprint.php
================================================
<?php

namespace Rats\Zkteco\Lib\Helper;

use Rats\Zkteco\Lib\ZKTeco;

class Fingerprint
{
    /**
     * TODO: Can get data, but don't know how to parse the data. Need more documentation about it...
     *
     * @param ZKTeco $self
     * @param integer $uid Unique Employee ID in ZK device
     * @return array Binary fingerprint data array (where key is finger ID (0-9))
     */
    static public function get(ZKTeco $self, $uid)
    {
        $self->_section = __METHOD__;

        $data = [];
        //fingers of the hands
        for ($i = 0; $i <= 9; $i++) {
          $finger = new Fingerprint();
            $tmp = $finger->_getFinger($self, $uid, $i);
            if ($tmp['size'] > 0) {
                $data[$i] = $tmp['tpl'];
            }
            unset($tmp);
        }
        return $data;
    }


    /**
     * @param ZKTeco $self
     * @param integer $uid Unique Employee ID in ZK device
     * @param integer $finger Finger ID (0-9)
     * @return array
     */
    private function _getFinger(ZKTeco $self, $uid, $finger)
    {
        $command = Util::CMD_USER_TEMP_RRQ;
        $byte1 = chr((int)($uid % 256));
        $byte2 = chr((int)($uid >> 8));
        $command_string = $byte1 . $byte2 . chr($finger);

        $ret = [
            'size' => 0,
            'tpl' => ''
        ];

        $session = $self->_command($command, $command_string, Util::COMMAND_TYPE_DATA);
        if ($session === false) {
            return $ret;
        }

        $data = Util::recData($self, 10, false);

        if (!empty($data)) {
            $templateSize = strlen($data);
            $prefix = chr($templateSize % 256) . chr(round($templateSize / 256)) . $byte1 . $byte2 . chr($finger) . chr(1);
            $data = $prefix . $data;
            if (strlen($templateSize) > 0) {
                $ret['size'] = $templateSize;
                $ret['tpl'] = $data;
            }
        }

        return $ret;
    }

    /**
     * TODO: Still can not set fingerprint. Need more documentation about it...
     *
     * @param ZKTeco $self
     * @param int $uid Unique Employee ID in ZK device
     * @param array $data Binary fingerprint data array (where key is finger ID (0-9) same like returned array from 'get' method)
     * @return int Count of added fingerprints
     */
    static public function set(ZKTeco $self, $uid, array $data)
    {
        $self->_section = __METHOD__;


        $count = 0;
        foreach ($data as $finger => $item) {
            $allowSet = true;
            $fingerPrint = new Fingerprint();
            if ($fingerPrint->_checkFinger($self, $uid, $finger) === true) {
                $allowSet = $fingerPrint->_removeFinger($self, $uid, $finger);
            }
            if ($allowSet === true && $fingerPrint->_setFinger($self, $item) === true) {
                $count++;
            }
        }

        return $count;
    }

    /**
     * @param ZKTeco $self
     * @param string $data Binary fingerprint data item
     * @return bool|mixed
     */
    private function _setFinger(ZKTeco $self, $data)
    {
        $command = Util::CMD_USER_TEMP_WRQ;
        $command_string = $data;

        return $self->_command($command, $command_string);
    }

    /**
     * @param ZKTeco $self
     * @param int $uid Unique Employee ID in ZK device
     * @param array $data Fingers ID array (0-9)
     * @return int Count of deleted fingerprints
     */
    static public function remove(ZKTeco $self, $uid, array $data)
    {
        $self->_section = __METHOD__;

        $count = 0;
        foreach ($data as $finger) {
          $fingerPrint = new Fingerprint();
            if ($fingerPrint->_checkFinger($self, $uid, $finger) === true) {
                if ($fingerPrint->_removeFinger($self, $uid, $finger) === true) {
                    $count++;
                }
            }
        }

        return $count;
    }

    /**
     * @param ZKTeco $self
     * @param int $uid Unique Employee ID in ZK device
     * @param int $finger Finger ID (0-9)
     * @return bool
     */
    private function _removeFinger(ZKTeco $self, $uid, $finger)
    {
        $command = Util::CMD_DELETE_USER_TEMP;
        $byte1 = chr((int)($uid % 256));
        $byte2 = chr((int)($uid >> 8));
        $command_string = ($byte1 . $byte2) . chr($finger);

        $self->_command($command, $command_string);
        $fingerPrint = new Fingerprint();
        return !($fingerPrint->_checkFinger($self, $uid, $finger));
    }

    /**
     * @param ZKTeco $self
     * @param int $uid Unique Employee ID in ZK device
     * @param int $finger Finger ID (0-9)
     * @return bool Returned true if exist
     */
    private function _checkFinger(ZKTeco $self, $uid, $finger)
    {
      $fingerPrint = new Fingerprint();
        $res = $fingerPrint->_getFinger($self, $uid, $finger);
        return (bool)($res['size'] > 0);
    }
}

================================================
FILE: src/Lib/Helper/Os.php
================================================
<?php

namespace Rats\Zkteco\Lib\Helper;

use Rats\Zkteco\Lib\ZKTeco;

class Os
{
    /**
     * @param ZKTeco $self
     * @return bool|mixed
     */
    static public function get(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_DEVICE;
        $command_string = '~OS';

        return $self->_command($command, $command_string);
    }
}

================================================
FILE: src/Lib/Helper/Pin.php
================================================
<?php

namespace Rats\Zkteco\Lib\Helper;

use Rats\Zkteco\Lib\ZKTeco;

class Pin
{
    /**
     * @param ZKTeco $self
     * @return bool|mixed
     */
    static public function width(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_DEVICE;
        $command_string = '~PIN2Width';

        return $self->_command($command, $command_string);
    }
}

================================================
FILE: src/Lib/Helper/Platform.php
================================================
<?php

namespace Rats\Zkteco\Lib\Helper;

use Rats\Zkteco\Lib\ZKTeco;

class Platform
{
    /**
     * @param ZKTeco $self
     * @return bool|mixed
     */
    static public function get(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_DEVICE;
        $command_string = '~Platform';

        return $self->_command($command, $command_string);
    }

    /**
     * @param ZKTeco $self
     * @return bool|mixed
     */
    static public function getVersion(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_DEVICE;
        $command_string = '~ZKFPVersion';

        return $self->_command($command, $command_string);
    }
}

================================================
FILE: src/Lib/Helper/SerialNumber.php
================================================
<?php

namespace Rats\Zkteco\Lib\Helper;

use Rats\Zkteco\Lib\ZKTeco;

class SerialNumber
{
    /**
     * @param ZKTeco $self
     * @return bool|mixed
     */
    static public function get(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_DEVICE;
        $command_string = '~SerialNumber';

        return $self->_command($command, $command_string);
    }
}

================================================
FILE: src/Lib/Helper/Ssr.php
================================================
<?php

namespace Rats\Zkteco\Lib\Helper;

use Rats\Zkteco\Lib\ZKTeco;

class Ssr
{
    /**
     * @param ZKTeco $self
     * @return bool|mixed
     */
    static public function get(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_DEVICE;
        $command_string = '~SSR';

        return $self->_command($command, $command_string);
    }
}

================================================
FILE: src/Lib/Helper/Time.php
================================================
<?php

namespace Rats\Zkteco\Lib\Helper;

use Rats\Zkteco\Lib\ZKTeco;

class Time
{
    /**
     * @param ZKTeco $self
     * @param string $t Format: "Y-m-d H:i:s"
     * @return bool|mixed
     */
    static public function set(ZKTeco $self, $t)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_SET_TIME;
        $command_string = pack('I', Util::encodeTime($t));

        return $self->_command($command, $command_string);
    }

    /**
     * @param ZKTeco $self
     * @return bool|mixed
     */
    static public function get(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_GET_TIME;
        $command_string = '';

        $ret = $self->_command($command, $command_string);

        if ($ret) {
            return Util::decodeTime(hexdec(Util::reverseHex(bin2hex($ret))));
        } else {
            return false;
        }
    }
}

================================================
FILE: src/Lib/Helper/User.php
================================================
<?php

namespace Rats\Zkteco\Lib\Helper;

use Rats\Zkteco\Lib\ZKTeco;

class User
{
    /**
     * @param ZKTeco $self
     * @param int $uid Unique ID (max 65535)
     * @param int|string $userid (max length = 9, only numbers - depends device setting)
     * @param string $name (max length = 24)
     * @param int|string $password (max length = 8, only numbers - depends device setting)
     * @param int $role Default Util::LEVEL_USER
     * @param int $cardno Default 0 (max length = 10, only numbers)
     * @return bool|mixed
     */
    static public function set(ZKTeco $self, $uid, $userid, $name, $password, $role = Util::LEVEL_USER, $cardno = 0)
    {
        $self->_section = __METHOD__;

        if (
            (int)$uid === 0 ||
            (int)$uid > Util::USHRT_MAX ||
            strlen($userid) > 9 ||
            strlen($name) > 24 ||
            strlen($password) > 8 ||
            strlen($cardno) > 10
        ) {
            return false;
        }

        $command = Util::CMD_SET_USER;
        $byte1 = chr((int)($uid % 256));
        $byte2 = chr((int)($uid >> 8));
        $cardno = hex2bin(Util::reverseHex(dechex($cardno)));

        $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)
        ]);
//        die($command_string);
        return $self->_command($command, $command_string);
    }

    /**
     * @param ZKTeco $self
     * @return array [userid, name, cardno, uid, role, password]
     */
    static public function get(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_USER_TEMP_RRQ;
        $command_string = chr(Util::FCT_USER);

        $session = $self->_command($command, $command_string, Util::COMMAND_TYPE_DATA);
        if ($session === false) {
            return [];
        }

        $userData = Util::recData($self);

        $users = [];
        if (!empty($userData)) {
            $userData = substr($userData, 11);

            while (strlen($userData) > 72) {
                $u = unpack('H144', substr($userData, 0, 72));

                $u1 = hexdec(substr($u[1], 2, 2));
                $u2 = hexdec(substr($u[1], 4, 2));
                $uid = $u1 + ($u2 * 256);
                $cardno = hexdec(substr($u[1], 78, 2) . substr($u[1], 76, 2) . substr($u[1], 74, 2) . substr($u[1], 72, 2)) . ' ';
                $role = hexdec(substr($u[1], 6, 2)) . ' ';
                $password = hex2bin(substr($u[1], 8, 16)) . ' ';
                $name = hex2bin(substr($u[1], 24, 74)) . ' ';
                $userid = hex2bin(substr($u[1], 98, 72)) . ' ';

                //Clean up some messy characters from the user name
                $password = explode(chr(0), $password, 2);
                $password = $password[0];
                $userid = explode(chr(0), $userid, 2);
                $userid = $userid[0];
                $name = explode(chr(0), $name, 3);
                $name = utf8_encode($name[0]);
                $cardno = str_pad($cardno, 11, '0', STR_PAD_LEFT);

                if ($name == '') {
                    $name = $userid;
                }

                $users[$userid] = [
                    'uid' => $uid,
                    'userid' => $userid,
                    'name' => $name,
                    'role' => intval($role),
                    'password' => $password,
                    'cardno' => $cardno,
                ];

                $userData = substr($userData, 72);
            }
        }

        return $users;
    }

    /**
     * @param ZKTeco $self
     * @return bool|mixed
     */
    static public function clear(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_CLEAR_DATA;
        $command_string = '';

        return $self->_command($command, $command_string);
    }

    /**
     * @param ZKTeco $self
     * @return bool|mixed
     */
    static public function clearAdmin(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_CLEAR_ADMIN;
        $command_string = '';

        return $self->_command($command, $command_string);
    }

    /**
     * @param ZKTeco $self
     * @param integer $uid
     * @return bool|mixed
     */
    static public function remove(ZKTeco $self, $uid)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_DELETE_USER;
        $byte1 = chr((int)($uid % 256));
        $byte2 = chr((int)($uid >> 8));
        $command_string = ($byte1 . $byte2);

        return $self->_command($command, $command_string);
    }
}

================================================
FILE: src/Lib/Helper/Util.php
================================================
<?php

namespace Rats\Zkteco\Lib\Helper;

use Rats\Zkteco\Lib\ZKTeco;

class Util
{
  const USHRT_MAX = 65535;

  const CMD_CONNECT = 1000; # Connections requests
  const CMD_EXIT = 1001; # Disconnection requests
  const CMD_ENABLE_DEVICE = 1002; # Ensure the machine to be at the normal work condition
  const CMD_DISABLE_DEVICE = 1003; # Make the machine to be at the shut-down condition, generally demonstrates ‘in the work ...’on LCD

  const CMD_RESTART = 1004; # Restart the machine
  const CMD_POWEROFF = 1005; # Turn Off the machine
  const CMD_SLEEP = 1006; # Sleep the machine
  const CMD_RESUME = 1007; # Resume the machine from Sleep
  const CMD_TEST_TEMP = 1011;
  const CMD_TESTVOICE = 1017; # Voice test to the device
  const CMD_CHANGE_SPEED = 1101;


  const CMD_WRITE_LCD = 66; # Write in LCD
  const CMD_CLEAR_LCD = 67; # Clear LCD

  const CMD_ACK_OK = 2000; # Return value for order perform successfully
  const CMD_ACK_ERROR = 2001; # Return value for order perform failed
  const CMD_ACK_DATA = 2002; # Return data
  const CMD_ACK_UNAUTH = 2005; # Connection unauthorized

  const CMD_PREPARE_DATA = 1500; # Prepares to transmit the data
  const CMD_DATA = 1501; # Transmit a data packet
  const CMD_FREE_DATA = 1502; # Clear machines open buffer

  const CMD_USER_TEMP_RRQ = 9; # Read some fingerprint template or some kind of data entirely
  const CMD_ATT_LOG_RRQ = 13; # Read all attendance record
  const CMD_CLEAR_DATA = 14; # Clear Data
  const CMD_CLEAR_ATT_LOG = 15; # Clear attendance records

  const CMD_GET_TIME = 201; # Obtain the machine time
  const CMD_SET_TIME = 202; # Set machines time

  const CMD_VERSION = 1100; # Obtain the firmware edition
  const CMD_DEVICE = 11; # Read in the machine some configuration parameter

  const CMD_SET_USER = 8; # Upload the user information (from PC to terminal).
  const CMD_USER_TEMP_WRQ = 10; # Upload some fingerprint template
  const CMD_DELETE_USER = 18; # Delete some user
  const CMD_DELETE_USER_TEMP = 19; # Delete some fingerprint template
  const CMD_CLEAR_ADMIN = 20; # Cancel the manager

  const LEVEL_USER = 0; # User level as User
  const LEVEL_ADMIN = 14; # User level as Admin

  const FCT_ATTLOG = 1;
  const FCT_WORKCODE = 8;
  const FCT_FINGERTMP = 2;
  const FCT_OPLOG = 4;
  const FCT_USER = 5;
  const FCT_SMS = 6;
  const FCT_UDATA = 7;

  const COMMAND_TYPE_GENERAL = 'general';
  const COMMAND_TYPE_DATA = 'data';

  const ATT_STATE_FINGERPRINT = 1;
  const ATT_STATE_PASSWORD = 0;
  const ATT_STATE_CARD = 2;

  const ATT_TYPE_CHECK_IN = 0;
  const ATT_TYPE_CHECK_OUT = 1;
  const ATT_TYPE_OVERTIME_IN = 4;
  const ATT_TYPE_OVERTIME_OUT = 5;

  /**
   * Encode a timestamp send at the timeclock
   * copied from zkemsdk.c - EncodeTime
   *
   * @param string $t Format: "Y-m-d H:i:s"
   * @return int
   */
  static public function encodeTime($t)
  {
    $timestamp = strtotime($t);
    $t = (object)[
      'year' => (int)date('Y', $timestamp),
      'month' => (int)date('m', $timestamp),
      'day' => (int)date('d', $timestamp),
      'hour' => (int)date('H', $timestamp),
      'minute' => (int)date('i', $timestamp),
      'second' => (int)date('s', $timestamp),
    ];

    $d = (($t->year % 100) * 12 * 31 + (($t->month - 1) * 31) + $t->day - 1) *
      (24 * 60 * 60) + ($t->hour * 60 + $t->minute) * 60 + $t->second;

    return $d;
  }

  /**
   * Decode a timestamp retrieved from the timeclock
   * copied from zkemsdk.c - DecodeTime
   *
   * @param int|string $t
   * @return false|string Format: "Y-m-d H:i:s"
   */
  static public function decodeTime($t)
  {
    $second = $t % 60;
    $t = $t / 60;

    $minute = $t % 60;
    $t = $t / 60;

    $hour = $t % 24;
    $t = $t / 24;

    $day = $t % 31 + 1;
    $t = $t / 31;

    $month = $t % 12 + 1;
    $t = $t / 12;

    $year = floor($t + 2000);

    $d = date('Y-m-d H:i:s', strtotime(
      $year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $minute . ':' . $second
    ));

    return $d;
  }

  /**
   * @param string $hex
   * @return string
   */
  static public function reverseHex($hex)
  {
    $tmp = '';

    for ($i = strlen($hex); $i >= 0; $i--) {
      $tmp .= substr($hex, $i, 2);
      $i--;
    }

    return $tmp;
  }

  /**
   * Checks a returned packet to see if it returned self::CMD_PREPARE_DATA,
   * indicating that data packets are to be sent
   * Returns the amount of bytes that are going to be sent
   *
   * @param ZKTeco $self
   * @return bool|number
   */
  static public function getSize(ZKTeco $self)
  {
    $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr($self->_data_recv, 0, 8));
    $command = hexdec($u['h2'] . $u['h1']);

    if ($command == self::CMD_PREPARE_DATA) {
      $u = unpack('H2h1/H2h2/H2h3/H2h4', substr($self->_data_recv, 8, 4));
      $size = hexdec($u['h4'] . $u['h3'] . $u['h2'] . $u['h1']);
      return $size;
    } else {
      return false;
    }
  }

  /**
   * This function calculates the chksum of the packet to be sent to the
   * time clock
   * Copied from zkemsdk.c
   *
   * @inheritdoc
   */
  static public function createChkSum($p)
  {
    $l = count($p);
    $chksum = 0;
    $i = $l;
    $j = 1;
    while ($i > 1) {
      $u = unpack('S', pack('C2', $p['c' . $j], $p['c' . ($j + 1)]));

      $chksum += $u[1];

      if ($chksum > self::USHRT_MAX) {
        $chksum -= self::USHRT_MAX;
      }
      $i -= 2;
      $j += 2;
    }

    if ($i) {
      $chksum = $chksum + $p['c' . strval(count($p))];
    }

    while ($chksum > self::USHRT_MAX) {
      $chksum -= self::USHRT_MAX;
    }

    if ($chksum > 0) {
      $chksum = -($chksum);
    } else {
      $chksum = abs($chksum);
    }

    $chksum -= 1;
    while ($chksum < 0) {
      $chksum += self::USHRT_MAX;
    }

    return pack('S', $chksum);
  }

  /**
   * This function puts a the parts that make up a packet together and
   * packs them into a byte string
   *
   * @inheritdoc
   */
  static public function createHeader($command, $chksum, $session_id, $reply_id, $command_string)
  {
    $buf = pack('SSSS', $command, $chksum, $session_id, $reply_id) . $command_string;

    $buf = unpack('C' . (8 + strlen($command_string)) . 'c', $buf);

    $u = unpack('S', self::createChkSum($buf));

    if (is_array($u)) {
      $u = reset($u);
    }
    $chksum = $u;

    $reply_id += 1;

    if ($reply_id >= self::USHRT_MAX) {
      $reply_id -= self::USHRT_MAX;
    }

    $buf = pack('SSSS', $command, $chksum, $session_id, $reply_id);

    return $buf . $command_string;

  }

  /**
   * Checks a returned packet to see if it returned Util::CMD_ACK_OK,
   * indicating success
   *
   * @inheritdoc
   */
  static public function checkValid($reply)
  {
    $u = unpack('H2h1/H2h2', substr($reply, 0, 8));

    $command = hexdec($u['h2'] . $u['h1']);
    /** TODO: Some device can return 'Connection unauthorized' then should check also */
    if ($command == self::CMD_ACK_OK || $command == self::CMD_ACK_UNAUTH) {
      return true;
    } else {
      return false;
    }
  }

  /**
   * Get User Role string
   * @param integer $role
   * @return string
   */
  static public function getUserRole($role)
  {
    switch ($role) {
      case self::LEVEL_USER:
        $ret = 'User';
        break;
      case self::LEVEL_ADMIN:
        $ret = 'Admin';
        break;
      default:
        $ret = 'Unknown';
    }

    return $ret;
  }

  /**
   * Get Attendance State string
   * @param integer $state
   * @return string
   */
  static public function getAttState($state)
  {
    switch ($state) {
      case self::ATT_STATE_FINGERPRINT:
        $ret = 'Fingerprint';
        break;
      case self::ATT_STATE_PASSWORD:
        $ret = 'Password';
        break;
      case self::ATT_STATE_CARD:
        $ret = 'Card';
        break;
      default:
        $ret = 'Unknown';
    }

    return $ret;
  }

  /**
   * Get Attendance Type string
   * @param integer $type
   * @return string
   */
  static public function getAttType($type)
  {
    switch ($type) {
      case self::ATT_TYPE_CHECK_IN:
        $ret = 'Check-in';
        break;
      case self::ATT_TYPE_CHECK_OUT:
        $ret = 'Check-out';
        break;
      case self::ATT_TYPE_OVERTIME_IN:
        $ret = 'Overtime-in';
        break;
      case self::ATT_TYPE_OVERTIME_OUT:
        $ret = 'Overtime-out';
        break;
      default:
        $ret = 'Undefined';
    }

    return $ret;
  }

  /**
   * Receive data from device
   * @param ZKTeco $self
   * @param int $maxErrors
   * @param bool $first if 'true' don't remove first 4 bytes for first row
   * @return string
   */
  static public function recData(ZKTeco $self, $maxErrors = 10, $first = true)
  {
    $data = '';
    $bytes = self::getSize($self);

    if ($bytes) {
      $received = 0;
      $errors = 0;

      while ($bytes > $received) {
        $ret = @socket_recvfrom($self->_zkclient, $dataRec, 1032, 0, $self->_ip, $self->_port);

        if ($ret === false) {
          if ($errors < $maxErrors) {
            //try again if false
            $errors++;
            sleep(1);
            continue;
          } else {
            //return empty if has maximum count of errors
            self::logReceived($self, $received, $bytes);
            unset($data);
            return '';
          }
        }

        if ($first === false) {
          //The first 4 bytes don't seem to be related to the user
          $dataRec = substr($dataRec, 8);
        }

        $data .= $dataRec;
        $received += strlen($dataRec);

        unset($dataRec);
        $first = false;
      }

      //flush socket
      @socket_recvfrom($self->_zkclient, $dataRec, 1024, 0, $self->_ip, $self->_port);
      unset($dataRec);
    }

    return $data;
  }

  /**
   * @param ZKTeco $self
   * @param int $received
   * @param int $bytes
   */
  static private function logReceived(ZKTeco $self, $received, $bytes)
  {
    self::logger($self, 'Received: ' . $received . ' of ' . $bytes . ' bytes');
  }

  /**
   * Write log
   * @param ZKTeco $self
   * @param string $str
   */
  static private function logger(ZKTeco $self, $str)
  {
    if (defined('ZK_LIB_LOG')) {
      //use constant if defined
      $log = ZK_LIB_LOG;
    } else {
      $dir = dirname(dirname(__FILE__));
      $log = $dir . '/logs/error.log';
    }

    $row = '<' . $self->_ip . '> [' . date('d.m.Y H:i:s') . '] ';
    $row .= (empty($self->_section) ? '' : '(' . $self->_section . ') ');
    $row .= $str;
    $row .= PHP_EOL;

    file_put_contents($log, $row, FILE_APPEND);
  }
}


================================================
FILE: src/Lib/Helper/Version.php
================================================
<?php

namespace Rats\Zkteco\Lib\Helper;;

use Rats\Zkteco\Lib\Helper\Util;
use Rats\Zkteco\Lib\ZKTeco;

class Version
{
    /**
     * @param ZKTeco $self
     * @return bool|mixed
     */
    static public function get(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_VERSION;
        $command_string = '';

        return $self->_command($command, $command_string);
    }
}

================================================
FILE: src/Lib/Helper/WorkCode.php
================================================
<?php

namespace Rats\Zkteco\Lib\Helper;

use Rats\Zkteco\Lib\ZKTeco;

class WorkCode
{
    /**
     * @param ZKTeco $self
     * @return bool|mixed
     */
    static public function get(ZKTeco $self)
    {
        $self->_section = __METHOD__;

        $command = Util::CMD_DEVICE;
        $command_string = 'WorkCode';

        return $self->_command($command, $command_string);
    }
}


================================================
FILE: src/Lib/ZKTeco.php
================================================
<?php

namespace Rats\Zkteco\Lib;

use ErrorException;
use Exception;
use Rats\Zkteco\Lib\Helper\Attendance;
use Rats\Zkteco\Lib\Helper\Device;
use Rats\Zkteco\Lib\Helper\Face;
use Rats\Zkteco\Lib\Helper\Fingerprint;
use Rats\Zkteco\Lib\Helper\Os;
use Rats\Zkteco\Lib\Helper\Pin;
use Rats\Zkteco\Lib\Helper\Platform;
use Rats\Zkteco\Lib\Helper\SerialNumber;
use Rats\Zkteco\Lib\Helper\Ssr;
use Rats\Zkteco\Lib\Helper\Time;
use Rats\Zkteco\Lib\Helper\User;
use Rats\Zkteco\Lib\Helper\Util;
use Rats\Zkteco\Lib\Helper\Connect;
use Rats\Zkteco\Lib\Helper\Version;
use Rats\Zkteco\Lib\Helper\WorkCode;


class ZKTeco{
  public $_ip;
  public $_port;
  public $_zkclient;

  public $_data_recv = '';
  public $_session_id = 0;
  public $_section = '';

  /**
   * ZKLib constructor.
   * @param string $ip Device IP
   * @param integer $port Default: 4370
   */
  public function __construct($ip, $port = 4370)
  {
    $this->_ip = $ip;
    $this->_port = $port;

    $this->_zkclient = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

    $timeout = array('sec' => 60, 'usec' => 500000);
    socket_set_option($this->_zkclient, SOL_SOCKET, SO_RCVTIMEO, $timeout);

  }

  /**
   * Create and send command to device
   *
   * @param string $command
   * @param string $command_string
   * @param string $type
   * @return bool|mixed
   */
  public function _command($command, $command_string, $type = Util::COMMAND_TYPE_GENERAL)
  {
    $chksum = 0;
    $session_id = $this->_session_id;

    $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr($this->_data_recv, 0, 8));
    $reply_id = hexdec($u['h8'] . $u['h7']);

    $buf = Util::createHeader($command, $chksum, $session_id, $reply_id, $command_string);

    socket_sendto($this->_zkclient, $buf, strlen($buf), 0, $this->_ip, $this->_port);

    try {
      @socket_recvfrom($this->_zkclient, $this->_data_recv, 1024, 0, $this->_ip, $this->_port);

      $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6', substr($this->_data_recv, 0, 8));

      $ret = false;
      $session = hexdec($u['h6'] . $u['h5']);

      if ($type === Util::COMMAND_TYPE_GENERAL && $session_id === $session) {
        $ret = substr($this->_data_recv, 8);
      } else if ($type === Util::COMMAND_TYPE_DATA && !empty($session)) {
        $ret = $session;
      }

      return $ret;
    } catch (ErrorException $e) {
      return false;
    } catch (Exception $e) {
      return false;
    }
  }

  /**
   * Connect to device
   *
   * @return bool
   */
  public function connect()
  {
    return Connect::connect($this);
  }

  /**
   * Disconnect from device
   *
   * @return bool
   */
  public function disconnect()
  {
    return Connect::disconnect($this);
  }

  /**
   * Get device version
   *
   * @return bool|mixed
   */
  public function version()
  {
    return Version::get($this);
  }

  /**
   * Get OS version
   *
   * @return bool|mixed
   */
  public function osVersion()
  {
    return Os::get($this);
  }

  /**
   * Get platform
   *
   * @return bool|mixed
   */
  public function platform()
  {
    return Platform::get($this);
  }

  /**
   * Get firmware version
   *
   * @return bool|mixed
   */
  public function fmVersion()
  {
    return Platform::getVersion($this);
  }

  /**
   * Get work code
   *
   * @return bool|mixed
   */
  public function workCode()
  {
    return WorkCode::get($this);
  }

  /**
   * Get SSR
   *
   * @return bool|mixed
   */
  public function ssr()
  {
    return Ssr::get($this);
  }

  /**
   * Get pin width
   *
   * @return bool|mixed
   */
  public function pinWidth()
  {
    return Pin::width($this);
  }

  /**
   * @return bool|mixed
   */
  public function faceFunctionOn()
  {
    return Face::on($this);
  }

  /**
   * Get device serial number
   *
   * @return bool|mixed
   */
  public function serialNumber()
  {
    return SerialNumber::get($this);
  }

  /**
   * Get device name
   *
   * @return bool|mixed
   */
  public function deviceName()
  {
    return Device::name($this);
  }

  /**
   * Disable device
   *
   * @return bool|mixed
   */
  public function disableDevice()
  {
    return Device::disable($this);
  }

  /**
   * Enable device
   *
   * @return bool|mixed
   */
  public function enableDevice()
  {
    return Device::enable($this);
  }

  /**
   * Get users data
   *
   * @return array [userid, name, cardno, uid, role, password]
   */
  public function getUser()
  {
    return User::get($this);
  }

  /**
   * Set user data
   *
   * @param int $uid Unique ID (max 65535)
   * @param int|string $userid ID in DB (same like $uid, max length = 9, only numbers - depends device setting)
   * @param string $name (max length = 24)
   * @param int|string $password (max length = 8, only numbers - depends device setting)
   * @param int $role Default Util::LEVEL_USER
   * @param int $cardno Default 0 (max length = 10, only numbers)
   * @return bool|mixed
   */
  public function setUser($uid, $userid, $name, $password, $role = Util::LEVEL_USER, $cardno = 0)
  {
    return User::set($this, $uid, $userid, $name, $password, $role, $cardno);
  }



  /**
   * Remove All users
   *
   * @return bool|mixed
   */
  public function clearUsers()
  {
    return User::clear($this);
  }

  /**
   * Remove admin
   *
   * @return bool|mixed
   */
  public function clearAdmin()
  {
    return User::clearAdmin($this);
  }

  /**
   * Remove user by UID
   *
   * @param integer $uid
   * @return bool|mixed
   */
  public function removeUser($uid)
  {
    return User::remove($this, $uid);
  }



  /**
   * Get fingerprint data array by UID
   * TODO: Can get data, but don't know how to parse the data. Need more documentation about it...
   *
   * @param integer $uid Unique ID (max 65535)
   * @return array Binary fingerprint data array (where key is finger ID (0-9))
   */
  public function getFingerprint($uid)
  {
    return Fingerprint::get($this, $uid);
  }

  /**
   * Set fingerprint data array
   * TODO: Still can not set fingerprint. Need more documentation about it...
   *
   * @param integer $uid Unique ID (max 65535)
   * @param array $data Binary fingerprint data array (where key is finger ID (0-9) same like returned array from 'getFingerprint' method)
   * @return int Count of added fingerprints
   */
  public function setFingerprint($uid, array $data)
  {
    return Fingerprint::set($this, $uid, $data);
  }

  /**
   * Remove fingerprint by UID and fingers ID array
   *
   * @param integer $uid Unique ID (max 65535)
   * @param array $data Fingers ID array (0-9)
   * @return int Count of deleted fingerprints
   */
  public function removeFingerprint($uid, array $data)
  {
    return Fingerprint::remove($this, $uid, $data);
  }


  /**
   * Get attendance log
   *
   * @return array [uid, id, state, timestamp]
   */
  public function getAttendance()
  {
    return Attendance::get($this);
  }

  /**
   * Clear attendance log
   *
   * @return bool|mixed
   */
  public function clearAttendance()
  {
    return Attendance::clear($this);
  }

  /**
   * Set device time
   *
   * @param string $t Format: "Y-m-d H:i:s"
   * @return bool|mixed
   */
  public function setTime($t)
  {
    return Time::set($this, $t);
  }

  /**
   * Get device time
   *
   * @return bool|mixed Format: "Y-m-d H:i:s"
   */
  public function getTime()
  {
    return Time::get($this);
  }


  /**
   * turn off the device
   *
   * @return bool|mixed
   */
  public function shutdown()
  {
    return Device::powerOff($this);
  }

  /**
   * restart the device
   *
   * @return bool|mixed
   */
  public function restart()
  {
    return Device::restart($this);
  }


  /**
   * make sleep mood the device
   *
   * @return bool|mixed
   */
  public function sleep()
  {
    return Device::sleep($this);
  }


  /**
   * resume the device from sleep
   *
   * @return bool|mixed
   */
  public function resume()
  {
    return Device::resume($this);
  }


  /**
   * voice test Sound will "Thank you"
   *
   * @return bool|mixed
   */
  public function testVoice()
  {
    return Device::testVoice($this);
  }


  public function clearLCD()
  {
    return Device::clearLCD($this);
  }


  public function writeLCD()
  {
    return Device::writeLCD($this, 2, "RAIHAN Afroz Topu");
  }
}

================================================
FILE: src/Providers/ZktecoServiceProvider.php
================================================
<?php

namespace Rats\Zkteco\Providers;

use Illuminate\Support\ServiceProvider;

class ZktecoServiceProvider extends ServiceProvider {

  public function boot(){
//    dd("Zkteco is running");
  }

  public function register(){

  }
}
Download .txt
gitextract__pwo6lda/

├── CHANGELOG.md
├── README.md
├── composer.json
└── src/
    ├── Lib/
    │   ├── Helper/
    │   │   ├── Attendance.php
    │   │   ├── Connect.php
    │   │   ├── Device.php
    │   │   ├── Face.php
    │   │   ├── Fingerprint.php
    │   │   ├── Os.php
    │   │   ├── Pin.php
    │   │   ├── Platform.php
    │   │   ├── SerialNumber.php
    │   │   ├── Ssr.php
    │   │   ├── Time.php
    │   │   ├── User.php
    │   │   ├── Util.php
    │   │   ├── Version.php
    │   │   └── WorkCode.php
    │   └── ZKTeco.php
    └── Providers/
        └── ZktecoServiceProvider.php
Download .txt
SYMBOL INDEX (104 symbols across 17 files)

FILE: src/Lib/Helper/Attendance.php
  class Attendance (line 7) | class Attendance
    method get (line 13) | static public function get(ZKTeco $self)
    method clear (line 63) | static public function clear(ZKTeco $self)

FILE: src/Lib/Helper/Connect.php
  class Connect (line 10) | class Connect
    method connect (line 16) | static public function connect(ZKTeco $self)
    method disconnect (line 56) | static public function disconnect(ZKTeco $self)

FILE: src/Lib/Helper/Device.php
  class Device (line 7) | class Device
    method name (line 13) | static public function name(ZKTeco $self)
    method enable (line 27) | static public function enable(ZKTeco $self)
    method disable (line 41) | static public function disable(ZKTeco $self)
    method powerOff (line 55) | public static function powerOff(ZKTeco $self)
    method restart (line 69) | public static function restart(ZKTeco $self)
    method sleep (line 83) | public static function sleep(ZKTeco $self)
    method resume (line 97) | public static function resume(ZKTeco $self)
    method testVoice (line 111) | public static function testVoice(ZKTeco $self)
    method clearLCD (line 125) | public static function clearLCD(ZKTeco $self)
    method writeLCD (line 140) | public static function writeLCD(ZKTeco $self, $rank, $text)

FILE: src/Lib/Helper/Face.php
  class Face (line 7) | class Face
    method on (line 13) | static public function on(ZKTeco $self)

FILE: src/Lib/Helper/Fingerprint.php
  class Fingerprint (line 7) | class Fingerprint
    method get (line 16) | static public function get(ZKTeco $self, $uid)
    method _getFinger (line 40) | private function _getFinger(ZKTeco $self, $uid, $finger)
    method set (line 80) | static public function set(ZKTeco $self, $uid, array $data)
    method _setFinger (line 105) | private function _setFinger(ZKTeco $self, $data)
    method remove (line 119) | static public function remove(ZKTeco $self, $uid, array $data)
    method _removeFinger (line 142) | private function _removeFinger(ZKTeco $self, $uid, $finger)
    method _checkFinger (line 160) | private function _checkFinger(ZKTeco $self, $uid, $finger)

FILE: src/Lib/Helper/Os.php
  class Os (line 7) | class Os
    method get (line 13) | static public function get(ZKTeco $self)

FILE: src/Lib/Helper/Pin.php
  class Pin (line 7) | class Pin
    method width (line 13) | static public function width(ZKTeco $self)

FILE: src/Lib/Helper/Platform.php
  class Platform (line 7) | class Platform
    method get (line 13) | static public function get(ZKTeco $self)
    method getVersion (line 27) | static public function getVersion(ZKTeco $self)

FILE: src/Lib/Helper/SerialNumber.php
  class SerialNumber (line 7) | class SerialNumber
    method get (line 13) | static public function get(ZKTeco $self)

FILE: src/Lib/Helper/Ssr.php
  class Ssr (line 7) | class Ssr
    method get (line 13) | static public function get(ZKTeco $self)

FILE: src/Lib/Helper/Time.php
  class Time (line 7) | class Time
    method set (line 14) | static public function set(ZKTeco $self, $t)
    method get (line 28) | static public function get(ZKTeco $self)

FILE: src/Lib/Helper/User.php
  class User (line 7) | class User
    method set (line 19) | static public function set(ZKTeco $self, $uid, $userid, $name, $passwo...
    method get (line 58) | static public function get(ZKTeco $self)
    method clear (line 121) | static public function clear(ZKTeco $self)
    method clearAdmin (line 135) | static public function clearAdmin(ZKTeco $self)
    method remove (line 150) | static public function remove(ZKTeco $self, $uid)

FILE: src/Lib/Helper/Util.php
  class Util (line 7) | class Util
    method encodeTime (line 84) | static public function encodeTime($t)
    method decodeTime (line 109) | static public function decodeTime($t)
    method reverseHex (line 139) | static public function reverseHex($hex)
    method getSize (line 159) | static public function getSize(ZKTeco $self)
    method createChkSum (line 180) | static public function createChkSum($p)
    method createHeader (line 226) | static public function createHeader($command, $chksum, $session_id, $r...
    method checkValid (line 257) | static public function checkValid($reply)
    method getUserRole (line 275) | static public function getUserRole($role)
    method getAttState (line 296) | static public function getAttState($state)
    method getAttType (line 320) | static public function getAttType($type)
    method recData (line 349) | static public function recData(ZKTeco $self, $maxErrors = 10, $first =...
    method logReceived (line 400) | static private function logReceived(ZKTeco $self, $received, $bytes)
    method logger (line 410) | static private function logger(ZKTeco $self, $str)

FILE: src/Lib/Helper/Version.php
  class Version (line 8) | class Version
    method get (line 14) | static public function get(ZKTeco $self)

FILE: src/Lib/Helper/WorkCode.php
  class WorkCode (line 7) | class WorkCode
    method get (line 13) | static public function get(ZKTeco $self)

FILE: src/Lib/ZKTeco.php
  class ZKTeco (line 24) | class ZKTeco{
    method __construct (line 38) | public function __construct($ip, $port = 4370)
    method _command (line 58) | public function _command($command, $command_string, $type = Util::COMM...
    method connect (line 97) | public function connect()
    method disconnect (line 107) | public function disconnect()
    method version (line 117) | public function version()
    method osVersion (line 127) | public function osVersion()
    method platform (line 137) | public function platform()
    method fmVersion (line 147) | public function fmVersion()
    method workCode (line 157) | public function workCode()
    method ssr (line 167) | public function ssr()
    method pinWidth (line 177) | public function pinWidth()
    method faceFunctionOn (line 185) | public function faceFunctionOn()
    method serialNumber (line 195) | public function serialNumber()
    method deviceName (line 205) | public function deviceName()
    method disableDevice (line 215) | public function disableDevice()
    method enableDevice (line 225) | public function enableDevice()
    method getUser (line 235) | public function getUser()
    method setUser (line 251) | public function setUser($uid, $userid, $name, $password, $role = Util:...
    method clearUsers (line 263) | public function clearUsers()
    method clearAdmin (line 273) | public function clearAdmin()
    method removeUser (line 284) | public function removeUser($uid)
    method getFingerprint (line 298) | public function getFingerprint($uid)
    method setFingerprint (line 311) | public function setFingerprint($uid, array $data)
    method removeFingerprint (line 323) | public function removeFingerprint($uid, array $data)
    method getAttendance (line 334) | public function getAttendance()
    method clearAttendance (line 344) | public function clearAttendance()
    method setTime (line 355) | public function setTime($t)
    method getTime (line 365) | public function getTime()
    method shutdown (line 376) | public function shutdown()
    method restart (line 386) | public function restart()
    method sleep (line 397) | public function sleep()
    method resume (line 408) | public function resume()
    method testVoice (line 419) | public function testVoice()
    method clearLCD (line 425) | public function clearLCD()
    method writeLCD (line 431) | public function writeLCD()

FILE: src/Providers/ZktecoServiceProvider.php
  class ZktecoServiceProvider (line 7) | class ZktecoServiceProvider extends ServiceProvider {
    method boot (line 9) | public function boot(){
    method register (line 13) | public function register(){
Condensed preview — 20 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (50K chars).
[
  {
    "path": "CHANGELOG.md",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "README.md",
    "chars": 5499,
    "preview": "# ZKTeco - Laravel Library #\n\n[![Issues](https://img.shields.io/github/issues/raihanafroz/zkteco?style=flat-square)](htt"
  },
  {
    "path": "composer.json",
    "chars": 380,
    "preview": "{\n    \"name\": \"rats/zkteco\",\n    \"description\": \"ZKTeco Laravel Library\",\n    \"type\": \"library\",\n    \"license\": \"MIT\",\n "
  },
  {
    "path": "src/Lib/Helper/Attendance.php",
    "chars": 1887,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Lib\\Helper;\n\nuse Rats\\Zkteco\\Lib\\ZKTeco;\n\nclass Attendance\n{\n    /**\n     * @param ZKTeco $"
  },
  {
    "path": "src/Lib/Helper/Connect.php",
    "chars": 2349,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Lib\\Helper;\n\nuse Rats\\Zkteco\\Lib\\Helper\\Util;\nuse Rats\\Zkteco\\Lib\\ZKTeco;\nuse ErrorExceptio"
  },
  {
    "path": "src/Lib/Helper/Device.php",
    "chars": 3324,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Lib\\Helper;\n\nuse Rats\\Zkteco\\Lib\\ZKTeco;\n\nclass Device\n{\n  /**\n   * @param ZKTeco $self\n   "
  },
  {
    "path": "src/Lib/Helper/Face.php",
    "chars": 387,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Lib\\Helper;\n\nuse Rats\\Zkteco\\Lib\\ZKTeco;\n\nclass Face\n{\n    /**\n     * @param ZKTeco $self\n "
  },
  {
    "path": "src/Lib/Helper/Fingerprint.php",
    "chars": 4884,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Lib\\Helper;\n\nuse Rats\\Zkteco\\Lib\\ZKTeco;\n\nclass Fingerprint\n{\n    /**\n     * TODO: Can get "
  },
  {
    "path": "src/Lib/Helper/Os.php",
    "chars": 378,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Lib\\Helper;\n\nuse Rats\\Zkteco\\Lib\\ZKTeco;\n\nclass Os\n{\n    /**\n     * @param ZKTeco $self\n   "
  },
  {
    "path": "src/Lib/Helper/Pin.php",
    "chars": 388,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Lib\\Helper;\n\nuse Rats\\Zkteco\\Lib\\ZKTeco;\n\nclass Pin\n{\n    /**\n     * @param ZKTeco $self\n  "
  },
  {
    "path": "src/Lib/Helper/Platform.php",
    "chars": 702,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Lib\\Helper;\n\nuse Rats\\Zkteco\\Lib\\ZKTeco;\n\nclass Platform\n{\n    /**\n     * @param ZKTeco $se"
  },
  {
    "path": "src/Lib/Helper/SerialNumber.php",
    "chars": 398,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Lib\\Helper;\n\nuse Rats\\Zkteco\\Lib\\ZKTeco;\n\nclass SerialNumber\n{\n    /**\n     * @param ZKTeco"
  },
  {
    "path": "src/Lib/Helper/Ssr.php",
    "chars": 380,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Lib\\Helper;\n\nuse Rats\\Zkteco\\Lib\\ZKTeco;\n\nclass Ssr\n{\n    /**\n     * @param ZKTeco $self\n  "
  },
  {
    "path": "src/Lib/Helper/Time.php",
    "chars": 905,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Lib\\Helper;\n\nuse Rats\\Zkteco\\Lib\\ZKTeco;\n\nclass Time\n{\n    /**\n     * @param ZKTeco $self\n "
  },
  {
    "path": "src/Lib/Helper/User.php",
    "chars": 4799,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Lib\\Helper;\n\nuse Rats\\Zkteco\\Lib\\ZKTeco;\n\nclass User\n{\n    /**\n     * @param ZKTeco $self\n "
  },
  {
    "path": "src/Lib/Helper/Util.php",
    "chars": 10533,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Lib\\Helper;\n\nuse Rats\\Zkteco\\Lib\\ZKTeco;\n\nclass Util\n{\n  const USHRT_MAX = 65535;\n\n  const "
  },
  {
    "path": "src/Lib/Helper/Version.php",
    "chars": 415,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Lib\\Helper;;\n\nuse Rats\\Zkteco\\Lib\\Helper\\Util;\nuse Rats\\Zkteco\\Lib\\ZKTeco;\n\nclass Version\n{"
  },
  {
    "path": "src/Lib/Helper/WorkCode.php",
    "chars": 390,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Lib\\Helper;\n\nuse Rats\\Zkteco\\Lib\\ZKTeco;\n\nclass WorkCode\n{\n    /**\n     * @param ZKTeco $se"
  },
  {
    "path": "src/Lib/ZKTeco.php",
    "chars": 8237,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Lib;\n\nuse ErrorException;\nuse Exception;\nuse Rats\\Zkteco\\Lib\\Helper\\Attendance;\nuse Rats\\Zk"
  },
  {
    "path": "src/Providers/ZktecoServiceProvider.php",
    "chars": 235,
    "preview": "<?php\n\nnamespace Rats\\Zkteco\\Providers;\n\nuse Illuminate\\Support\\ServiceProvider;\n\nclass ZktecoServiceProvider extends Se"
  }
]

About this extraction

This page contains the full source code of the raihanafroz/zkteco GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 20 files (45.4 KB), approximately 14.1k tokens, and a symbol index with 104 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!