Tuesday, November 7, 2017

Membaca Log Absensi dari Mesin Fingerprint (Attendance System) Menggunakan PHP

Mesin Fingerprint yang sudah mendukung pertukaran data dengan SOAP memungkinkan untuk membaca log absensi menggunakan PHP. Untuk mengetahui apakah mesin fingerprint sudah mendukung SOAP hanya dengan mengakses IP Address mesin melalui web broswer. Jika saat diakses muncul halaman login, artinya mesin tersebut sudah mendukung SOAP.

Selanjutnya, berikut script PHP untuk membaca log absensi dari mesin :

<?php
set_time_limit(500);
$IP  = "192.168.5.98"; //isi dengan ip fingerprint
$Key = "0";  // key di mesin fingerprint, nol adalah nilai default

$Connect = fsockopen($IP, "80", $errno, $errstr, 1);
if ($Connect) {
  $soap_request = "<GetAttLog>
    <ArgComKey xsi:type=\"xsd:integer\">".$Key."</ArgComKey>
    <Arg><PIN xsi:type=\"xsd:integer\">ALL</PIN></Arg>
  </GetAttLog>";

  $newLine = "\r\n";
  fputs($Connect, "POST /iWsService HTTP/1.0".$newLine);
  fputs($Connect, "Content-Type: text/xml".$newLine);
  fputs($Connect, "Content-Length: ".strlen($soap_request).$newLine.$newLine);
  fputs($Connect, $soap_request.$newLine);
  $buffer = "";
  while($Response = fgets($Connect, 1024)) {
    $buffer = $buffer.$Response;
  }
} else echo "Koneksi Gagal";

$buffer = Parse_Data($buffer,"<GetAttLogResponse>","</GetAttLogResponse>");
$buffer = explode("\r\n",$buffer);

$c=0;
for ($a=1; $a<count($buffer)-1; $a++) {
    $data=Parse_Data($buffer[$a],"<Row>","</Row>");    
    $export[$c]['pin'] = Parse_Data($data,"<PIN>","</PIN>");
    $export[$c]['date'] = substr(Parse_Data($data,"<DateTime>","</DateTime>"),0,10) ;
    $export[$c]['time'] = substr(Parse_Data($data,"<DateTime>","</DateTime>"),11,8) ;
    $export[$c]['verif'] = Parse_Data($data,"<Verified>","</Verified>");
    $export[$c]['state'] = Parse_Data($data,"<Status>","</Status>");
    $export[$c]['wrkcode'] = Parse_Data($data,"<WorkCode>","</WorkCode>");
    $c++;
}

echo json_encode($export);

function Parse_Data ($data,$p1,$p2) {
  $data = " ".$data;
  $hasil = "";
  $awal = strpos($data,$p1);
  if ($awal != "") {
    $akhir = strpos(strstr($data,$p1),$p2);
    if ($akhir != ""){
      $hasil=substr($data,$awal+strlen($p1),$akhir-strlen($p1));
    }
  }
  return $hasil;    
}
?>

Hasil dari script diatas adalah log absensi dalam format JSON.

2 comments:

  1. Warning: fsockopen(): unable to connect to 192.168.16.10:80 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) in C:\xampp\htdocs\penggajianfingerprint\index.php on line 117
    Koneksi Gagal
    Notice: Undefined variable: buffer in C:\xampp\htdocs\penggajianfingerprint\index.php on line 135

    Notice: Undefined variable: export in C:\xampp\htdocs\penggajianfingerprint\index.php on line 153
    null

    kalo kaya diatas itu knapa ya mas ?

    ReplyDelete
    Replies
    1. gimana mas? udah dapat belum jalan keluar untuk Warning: fsockopen(): unable to connect to 192.168.16.10:80 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) ?

      saya juga sedang dimasalah tersebut, mohon bantuannya mas

      Delete