富贵资源网 Design By www.hznty.com
经常有查下自己的车有没有违章,所以写了现在这个脚本,帮助查询自己的车是否违章。
主要用到,带cookie模拟表单提交和验证码识别。
Tesseract-OCR
验证码识别技术,Tesseract-OCR:https://github.com/tesseract-ocr/tesseract
安装教程:https://github.com/tesseract-ocr/tesseract
Tesseract-Ocr-For-PHP
把需要执行的命令,封装了一下
https://github.com/thiagoalessio/tesseract-ocr-for-php
直接上脚本,没进行什么优化,简单了解下:
PHP
<"http://$url_pre.122.gov.cn/views/inquiry.html"; $post_url = "http://$url_pre.122.gov.cn/m/publicquery/vio"; $verify_code_url = "http://$url_pre.122.gov.cn/captcha".time(); $curl = curl_init(); $timeout = 5; curl_setopt($curl, CURLOPT_URL, $login_url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file); //获取COOKIE并存储 $contents = curl_exec($curl); curl_close($curl); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $verify_code_url); curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $img = curl_exec($curl); curl_close($curl); $fp = fopen("verifyCode.jpg", "w"); fwrite($fp, $img); fclose($fp); $code = (new TesseractOCR('verifyCode.jpg'))->psm(7)->run(); $code = explode("\n", $code); $code = $code[1]; echo $code.PHP_EOL; if (strlen($code) != 4) { return json_encode(array('code'=>500)); } $data = array( 'hpzl'=>'02', 'hphm1b' => substr($car_code, -6), 'hphm' => $car_code, 'fdjh' => $fdjh, 'captcha' => $code, 'qm' => 'wf', 'page' => 1 ); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $post_url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file); $result = curl_exec($curl); curl_close($curl); //unlink($cookie_file); //unlink('verifyCode.jpg'); return $result; } $count = 0; // 车牌号 $car_code = '冀Dxxxxx'; // 发动机后6位 $fdjh = 'xxxxxx'; while (true) { $count++; if ($count>50) { exit('查询失败'); } $res = weizhang($car_code, $fdjh); $info = json_decode($res, true); echo $res.PHP_EOL; if ($info['code'] == 200) { echo '车牌号: '. $car_code.PHP_EOL; echo '未处理违章数: '.$info['data']['content']['zs']; exit(); } }
执行效果
以上所述是小编给大家介绍的PHP脚本自动识别验证码查询汽车违章,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com
暂无评论...