Introduction
Aggregated data The national vehicle violation data interface has currently supported about 300 city violation queries and has been connected to tens of thousands of apps. It is convenient for car owners to know whether they have ever committed traffic violations at any time, and avoid unnecessary losses caused by forgetting or overdue processing of violation tickets.
API reference documentation: https://www.juhe.cn/docs/api/id/36
Example of API calling code for national vehicle violation query based on PHP
This code example is based on the call of the National Vehicle Violation Query API based on aggregated data. Before using it, you need:
Apply for an appkey for illegal inquiries through http://www.juhe.cn/docs/api/id/36
1. Introduce the encapsulated request class class.juhe.wz.php
header('Content-type:text/html;charset=utf-8'); include 'class.juhe.wz.php'; //Introduce files
2. Configuration parameters
//Configuration of interface basic information $appkey = '**********'; //The illegal query key you applied for $ wz = new wz ($ appkey);
3. Query the list of cities supported by illegal regulations
Since the supported cities will be updated from time to time, but not too frequently, you can cache the data, for example, update it every 3 hours, without requesting the interface every time.
$wzcitys = $wz->getCitys(); //Query all supported cities $wzcitys = $wz->getCitys('GD'); //Query the cities under the specified province
The format of the returned data is as follows: (very important, it involves some conditions required for the next step of querying violations. For the specific field meaning, please refer to the official interface document, in which regist and registno can be ignored, and are only required for the old version)
{ "resultcode": "200", "reason": "Successful return", "result": [ { "province": "北京", "province_code": "BJ", "citys": [ { "city_name": "北京", "city_code": "BJ", "abbr": "京", "engine": "1", "engineno": "0", "classa": "0", "class": "0", "classno": "0", "regist": "0", "registno": "0" } ] } ], "error_code": 0 }
4. Inquire about the violation information of the vehicle
Basically, the city only supports small car query, so hpzl can be omitted.
//According to the required query conditions, query the violation information of the vehicle $city = 'GD_DG'; //city code, must be passed $carno = 'Guangdong S*****'; //The license plate number, must be passed $engineno = '****'; //Engine number, the required city must be passed $classno = '*****'; //Frame number, the required city must be passed $wzResult = $wz->query($city,$carno,$engineno,$classno); if($wzResult['error_code'] ==0){ if($wzResult['result']['lists']){ foreach($wzResult['result']['lists'] as $key =>$w){ //The following is modified according to the actual business needs echo $w['area']." ".$w['date']." ".$w['act']." ".$w['fen']." ".$w['money']."<br>"; } }else{ echo "The car has no illegal record"; } }else{ // query failed echo $wzResult['error_code'].":".$wzResult['reason']; }
<!--?php // +---------------------------------------------------------------------- // | JuhePHP [ NO ZUO NO DIE ] // +---------------------------------------------------------------------- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved. // +---------------------------------------------------------------------- // | Author: Juhedata <[email protected]> // +---------------------------------------------------------------------- //---------------------------------- // Aggregate data national illegal interface calling class //---------------------------------- class wz{ private $appkey = false; //Application for national illegal query APPKEY private $cityUrl = 'http://v.juhe.cn/wz/citys'; private $wzUrl = 'http://v.juhe.cn/wz/query'; public function __construct($appkey){ $this->appkey = $appkey; } /** * Get the list of cities supported by violations * @return array */ public function getCitys($province=false){ $params = 'key='.$this->appkey."&format=2"; $content = $this->juhecurl($this->cityUrl,$params); return $this->_returnArray($content); } /** * Check vehicle violations * @param string $city [city code] * @param string $carno [license plate number] * @param string $engineno [engine number] * @param string $classno [chassis number] * @return array returns the violation information */ public function query($city,$carno,$engineno='',$classno=''){ $params = array( 'key' => $this->appkey, 'city' => $city, 'hphm' => $carno, 'engineno'=> $engineno, 'classno' => $classno ); $content = $this->juhecurl($this->wzUrl,$params,1); return $this->_returnArray($content); } /** * Convert JSON content to data and return * @param string $content [content] * @return array */ public function _returnArray($content){ return json_decode($content,true); } /** * Request interface return content * @param string $url [request URL] * @param string $params [request parameters] * @param int $ipost [whether in POST form] * @return string */ public function juhecurl($url,$params=false,$ispost=0){ $httpInfo = array(); $ch = curl_init(); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 ); curl_setopt( $ch, CURLOPT_TIMEOUT , 60); curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true ); if( $ispost ) { curl_setopt( $ch , CURLOPT_POST , true ); curl_setopt( $ch , CURLOPT_POSTFIELDS , $params ); curl_setopt( $ch , CURLOPT_URL , $url ); } else { if($params){ curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params ); }else{ curl_setopt( $ch , CURLOPT_URL , $url); } } $response = curl_exec( $ch ); if ($response === FALSE) { //echo "cURL Error: " . curl_error($ch); return false; } $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE ); $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) ); curl_close( $ch ); return $response; } }
An example of calling code for the national vehicle violation interface based on Python
An example of calling code for the national vehicle violation interface based on C#
Example of calling code of national vehicle violation interface based on GO
An example of calling code of national vehicle violation interface based on JAVA