考勤机集成到 Laravel 10

问题描述 投票:0回答:1

嗨,我在将数据从考勤机同步到我的网络应用程序时遇到问题,我目前正在使用 Laravel 10 和 PHP 8.1,连接成功,但它返回一个空字符串,这是我的代码

 public function tarikDataAbsen(AttendanceMachineInformation $attendanceMachineInformation): JsonResponse
    {
        $ip = $attendanceMachineInformation->ip_address;
        $port = $attendanceMachineInformation->port;
        $key = $attendanceMachineInformation->key;

        $connect = fsockopen($ip, $port, $errno, $errstr, 1);
        dd($connect);
        $buffer = "";
        if ($connect) {
            $soapRequest = "<GetAttLog><ArgComKey xsi:type=\"xsd:integer\">" . $key . "</ArgComKey><Arg><PIN xsi:type=\"xsd:integer\">All</PIN></Arg></GetAttLog>";
            $newLine = "\r\n";
            fwrite($connect, "POST /iWsService HTTP/1.0" . $newLine);
            fwrite($connect, "Content-Type: text/xml" . $newLine);
            fwrite($connect, "Content-Length: " . strlen($soapRequest) . $newLine . $newLine);
            fwrite($connect, $soapRequest . $newLine);
            while ($response = fgets($connect, 1024)) {
                $buffer .= $response;
            }
        } else {
            echo "Koneksi Gagal";
        }

        $buffer = $this->parseData($buffer, "<GetAttLogResponse>", "</GetAttLogResponse>");
//        dd($buffer);
        $buffer = explode("\r\n", $buffer);

        $export = [];
        for ($a = 0, $aMax = count($buffer); $a < $aMax; $a++) {
            $data = $this->parseData($buffer[$a], "<Row>", "</Row>");
            $export[$a]['pin'] = $this->parseData($data, "<PIN>", "</PIN>");
            $export[$a]['waktu'] = $this->parseData($data, "<DateTime>", "</DateTime>");
            $export[$a]['status'] = $this->parseData($data, "<Status>", "</Status>");
        }
        return response()->json($export);
    }
private function parseData($data, $p1, $p2): string
{
    $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;
}

当我添加 $connect 时
enter image description here

当我添加 fgets 函数时它返回 false,有人可以帮忙吗?谢谢。

我尝试使用ZKLib,但花了很长时间才回复

laravel fingerprint
1个回答
0
投票

我最终使用了来自 https://github.com/jmrashed/zkteco的这个库,并且它起作用了

© www.soinside.com 2019 - 2024. All rights reserved.