通过二维码图片识别二维码内容方法

 示例代码功能见-识别二维码工具 反解析二维码工具 识别条码工具 反解析条码工具http://sberwm.gsjlw.com/

可以通过读取图片中的信息,来逆向识别二维码的内容,

主要使用了ZBarCodeImage这个类的功能。

而这个类需要在服务器上安装php-zbarcode 具体安装方法见https://www.cnblogs.com/mengzhilva/p/10670228.html

$url = $_GET['url'];
$urlimg = $url;
$img = togetc($urlimg);

$name = substr($url,1+strrpos($url,'/'));
//var_dump($name);exit;
$img = file_put_contents('Public/Uploads/'.$name,$img);
//var_dump($img);exit;
//新建一个图像对象
//$image = new ZBarCodeImage('4324.jpg');
$image = new ZBarCodeImage('Public/Uploads/'.$name);

// 创建一个二维码识别器
$scanner = new ZBarCodeScanner();

//识别图像
$barcode = $scanner->scan($image);
echo json_encode($barcode);exit;
//循环输出二维码信息
if (!empty($barcode)) {
foreach ($barcode as $code) {
printf("Found type %s barcode with data %s\n", $code['type'], $code['data']);
}
}

function togetc($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$a = curl_exec($ch);
return $a;
}

猜你喜欢

转载自www.cnblogs.com/mengzhilva/p/10670222.html
今日推荐