connect('api.qrserver.com', 80); $sock->set_method('GET'); $sock->query('/v1/read-qr-code/', $param); $raw_text = $sock->fetch_body(); $result_array = json_decode($raw_text, true); if (isset($result_array[0])) { return $result_array[0]['symbol'][0]['data']; } return null; } public static function phpzbar_decode($url) { $filepath = BASE_PATH . '/storage/' . time() . random_int(1, 100) . '.png'; $img = file_get_contents($url); file_put_contents($filepath, $img); /* Create new image object */ $image = new ZBarCodeImage($filepath); /* Create a barcode scanner */ $scanner = new ZBarCodeScanner(); /* Scan the image */ $barcode = $scanner->scan($image); unlink($filepath); return ($barcode[0]['data'] ?? null); } public static function zxing_local_decode($url) { $filepath = BASE_PATH . '/storage/' . time() . random_int(1, 100) . '.png'; $img = file_get_contents($url); file_put_contents($filepath, $img); $qrcode = new QrReader($filepath); $text = $qrcode->text(); //return decoded text from QR Code unlink($filepath); if ($text == null || $text == '') { return null; } return $text; } public static function zxing_decode($url) { $raw_text = file_get_contents('https://zxing.org/w/decode?u=' . urlencode($url)); return Tools::get_middle_text($raw_text, '
', '
');
}
}