久久久久在线观看_又色又爽又黄的免费视频播放_一区中文字幕_日韩电影在线播放

今日焦點 焦點資訊 營銷之道 企業報道 淘寶運營 網站建設 軟件開發 400電話
  當前位置: 首頁 » 資訊 » 軟件開發 » 正文

PHP腳本自動識別驗證碼查詢汽車違章

放大字體  縮小字體 發布日期:2018-02-10  來源:企業800網  作者:新格網  瀏覽次數:136  【去百度看看】
經常有查下自己的車有沒有違章,所以寫了現在這個腳本,幫助查詢自己的車是否違章。

主要用到,帶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

<?php
require 'TesseractOCR.php';
function weizhang($car_code, $fdjh)
{
  $shanghui = mb_substr($car_code, 0, 1, 'utf-8');
  $pre = array(
    '冀' => 'he',
    '云' => 'yn'
  );
  $url_pre = $pre[$shanghui];
  $headers = array(
    'Host: '.$url_pre.'.122.gov.cn',
    'Origin: http://'.$url_pre.'.122.gov.cn',
    'Referer: http://'.$url_pre.'.122.gov.cn/views/inquiry.html?q=j',
    'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36 QQBrowser/4.1.4132.400'
  );
  //初始化變量
  $cookie_file = 'cookie.txt';
  $login_url = "http://$url_pre.122.gov.cn/views/inquiry.html?q=j";
  $post_url = "http://$url_pre.122.gov.cn/m/publicquery/vio";
  $verify_code_url = "http://$url_pre.122.gov.cn/captcha?nocache=".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腳本自動識別驗證碼查詢汽車違章

以上所述是小編給大家介紹的PHP腳本自動識別驗證碼查詢汽車違章,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對PHP網站的支持!

更多PHP腳本自動識別驗證碼查詢汽車違章相關文章請關注PHP中文網!

 
關鍵詞: 識別 驗證碼 腳本
 
[ 資訊搜索 ]  [ 加入收藏 ]  [ 告訴好友 ]  [ 打印本文 ]  [ 違規舉報 ]  [ 關閉窗口 ]

 
0條 [查看全部]  相關評論

 
網站首頁 | 關于我們 | 聯系方式 | 使用協議 | 版權隱私 | 網站地圖 | 排名推廣 | 廣告服務 | 積分換禮 | 網站留言 | RSS訂閱 | 皖ICP備2021004516號-14
企業800網 · 提供技術支持