日期 2016年12月 下的文章

PHP中控考勤机读取人员信息

thinkphp 3.2 代码如下:

public function view($ip,$port)
    {    
        $zk = new \COM("zkemkeeper.ZKEM.1") or die("Unable to instanciate ZK"); 
        if ($zk->Connect_Net($ip,$port)==false)
        {
            header("Content-Type:text/html;charset=UTF-8");
            echo "设备连接失败!";
            return;
        }
        else
        {
            $year=0;
            $month=0;
            $day=0;
            $hour=0;
            $minter=0;
            $second=0;
            $zk->GetDeviceTime(1,$year,$month,$day,$hour,$minter,$second);
            $dtime="设备时间:{$year}-{$month}-{$day} {$hour}:{$minter}:{$second}";
            $SerialNumber="";
            $zk->GetSerialNumber(1,$SerialNumber);
            
            $idwErrorCode="";
            $bRead = $zk->ReadAllUserID(1);
            If( $bRead == False )
            {
                $zk->GetLastError($idwErrorCode);
                echo "人员信息下载失败,ErrorCode={$idwErrorCode}";
                $zk->Disconnect();
                Return;
            }
            $dwEnrollNumber='';
            $dwName='';
            $dwPassword='';
            $dwPrivilege=1;
            $dwEnabled=true;
            $i=0;
            $data=array();
            $bUser = $zk->SSR_GetAllUserInfo(1,$dwEnrollNumber,$dwName,$dwPassword,$dwPrivilege,$dwEnabled);
            While ($bUser == True)
            {
                $name=$text=iconv("GB2312","UTF-8",$dwName);
                $data[$i]['workcode']=$dwEnrollNumber;
                $data[$i]['name']=$name;
                $data[$i]['password']=$dwPassword;
                If ($dwPrivilege == 3) 
                {
                    $data[$i]['privilege']="管理员";
                }
                Else
                {
                    $data[$i]['privilege']="普通用户";
                }  
                $i++;
                $bUser = $zk->SSR_GetAllUserInfo(1, $dwEnrollNumber, $dwName, $dwPassword, $dwPrivilege, $dwEnabled);
            }
            $zk->Disconnect();
        }
        $rst = array();
        foreach ($data as $rowdata)
        {
            $rst[] = $rowdata['workcode'];
        }
        array_multisort($rst, SORT_ASC, $data);
        
        $date=date("Y年m月d日",time());
        $this->assign("date",$date);
        $this->assign('dtime',$dtime);
        $this->assign('serial',$SerialNumber);
        $this->assign('list',$data);
        $this->display();
    }

模板文件:

{$dtime}
序列号:{$serial}
签到号 用户名 密码 权限
{$vo.workcode} {$vo.name} {$vo.password} {$vo.privilege}

PHP连接中控考勤机

测试环境:Thinkphp 3.2

1、安装中考sdk,根据系统选择安装32位或64位。(下载地址:http://cn.zkteco.com/download_list/downloadcategoryid=8&isMode=false.html

2、修改php.ini设置

com.allow_dcom =true

extension=php_com_dotnet.dll

allow_call_time_pass_reference=on

3、代码

public function view($ip,$port)
    {
        header("Content-Type:text/html;charset=UTF-8");
        $zk = new COM("zkemkeeper.ZKEM.1") or die("Unable to instanciate ZK"); 
        if ($zk->Connect_Net($ip,$port)==false)
        {
            echo "设备连接失败!";
        }
        else
        {
            $year=0;
            $month=0;
            $day=0;
            $hour=0;
            $minter=0;
            $second=0;
            $zk->GetDeviceTime(1,&$year,&$month,&$day,&$hour,&$minter,&$second);
            echo "设备时间:{$year}-{$month}-{$day} {$hour}:{$minter}:{$second}
";
            $SerialNumber="";
            $zk->GetSerialNumber(1,&$SerialNumber);
            echo "设备序列号:{$SerialNumber}n";
            $zk->Disconnect();
        }
    }

4、运行效果

设备时间:2016-11-9 22:5:54
设备序列号:3142143700318

注意:在PHP5.4以后版本这一句allow_call_time_pass_reference=on不用去改。

public function view($ip,$port)

{

header("Content-Type:text/html;charset=UTF-8");

$zk = new \COM("zkemkeeper.ZKEM.1") or die("Unable to instanciate ZK");

if ($zk->Connect_Net($ip,$port)==false)

{

echo "设备连接失败!";

}

else

{

$year=0;

$month=0;

$day=0;

$hour=0;

$minter=0;

$second=0;

$zk->GetDeviceTime(1,$year,$month,$day,$hour,$minter,$second);

echo "设备时间:{$year}-{$month}-{$day} {$hour}:{$minter}:{$second}<br />";

$SerialNumber="";

$zk->GetSerialNumber(1,$SerialNumber);

echo "设备序列号:{$SerialNumber}n";

$zk->Disconnect();

}

}