PHP script automatically identifies the verification code to query car violations

Source: Internet
Author: User
Tags php website
I often check whether my car is in violation of regulations, so I wrote this script to help check whether my car is in violation of regulations. It is mainly used to simulate form submission and verification code identification with cookies. I learned how to write specific scripts. I often checked whether my car was in violation of regulations. so I wrote this script to check whether my car was in violation of regulations.

It is mainly used to simulate form submission and verification code identification with cookies.

Tesseract-OCR

Verification code recognition technology, Tesseract-OCR: https://github.com/tesseract-ocr/tesseract

Installation tutorial: https://github.com/tesseract-ocr/tesseract

Tesseract-Ocr-For-PHP

Encapsulate the command to be executed

Https://github.com/thiagoalessio/tesseract-ocr-for-php

Directly run the script without any optimization. For more information, see:

PHP

 'He', 'yun '=> '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 '); // Initialization variable $ cookie_file = 'cookie.txt'; $ login_url = "http: // $ response/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 ); // Obtain the COOKIE and store $ contents = curl_exec ($ curl); curl_close ($ curl); $ curl = curl_init (); curl_setopt ($ cu Rl, CURLOPT_URL, $ scheme); curl_setopt ($ curl, CURLOPT_COOKIEFILE, $ cookie_file); curl_setopt ($ curl, scheme, $ headers); curl_setopt ($ curl, scheme, 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 = $ c Ode [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, 'fd' => $ fd1_, 'captcha' => $ code, 'QM '=> 'WF', 'page' => 1); $ curl = curl_init (); curl_setopt ($ curl, CURLOPT_URL, $ post_url); curl_setopt ($ curl, expires, 1); curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ data); curl_setopt ($ curl, expires, $ 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; // license plate number $ car_code = 'Ji dxxxxxx'; // The last six digits of the engine $ fd1_= 'xxxxxx'; while (true) {$ count ++; if ($ count> 50) {exit ('query failed') ;}$ res = weizhang ($ car_code, $ fdang); $ info = json_decode ($ res, true ); echo $ res. PHP_EOL; if ($ info ['code'] = 200) {echo 'license plate number :'. $ car_code.PHP_EOL; echo 'number of unprocessed violations :'. $ info ['data'] ['content'] ['zs']; exit ();}}

Execution result

The above is a small series of PHP scripts introduced to you to automatically identify the verification code to query car violations, I hope to help you, if you have any questions, please leave a message, the small series will reply to you in a timely manner. Thank you for your support for the PHP website!

For more information about automatic identification and verification codes using PHP scripts, see PHP Chinese network!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.