Convenient to have a car family at any time to understand whether they have traffic violations, to avoid the forgotten or overdue treatment of illegal tickets caused by unnecessary loss. This code example is based on aggregated data for the national vehicle traffic violation query API calls, there is a need to look down.
Before use you need to:
Through: Https://www.juhe.cn/docs/api/id/36 to apply for an illegal query Appkey
First, the introduction of packaged request Class class.juhe.wz.php
Header (' Content-type:text/html;charset=utf-8 ');
Include ' class.juhe.wz.php '; Introducing Files
Second, configuration parameters
Interface basic information configuration
$appkey = ' ********** ';//You apply for the illegal query key
$WZ = new wz ($appkey);
Third, check the list of cities and towns supported by the city because the supported cities will not be updated regularly, but not too often, you can cache these data, such as every 3 hours to update once, do not have to request the interface every time.
$wzcitys = $wz->getcitys (); Query all support City
$wzcitys = $wz->getcitys (' GD ');//query city under designated province
The returned data format is as follows: (very important, related to the next step to check the violation of some of the conditions required, the specific field meaning can refer to the official interface documents, which Regist and Registno can be ignored, is the old version needed)
{"
ResultCode": "Reason": "
successful return",
"result": [
{
"province": "Beijing",
"Province_code": "BJ",
"Citys": [
{
"city_name": "Beijing",
"City_code": "BJ",
"abbr": "Beijing",
"engine": "1", "
Engineno": "0", "
ClassA": "0",
"class": "0",
"Classno": "0",
"regist": "0",
" Registno ":" 0 "
}
]
}
],
" Error_code ": 0
}
Four, inquires the traffic violation information basically the city only supports the small car inquiry, therefore HPZL may omit.
According to the requirements of the query conditions, the vehicle information
$city = "GD_DG";//city code, must pass
$carno = ' Yue s***** ';//car license number, must pass
$engineno = ' * * *; Required cities must be transmitted
$classno = ' * * * * * * * * * * * * * *, the required city must pass
$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 the modification of the
echo $w [' area '] based on the actual business requirements. ". $w [' Date ']." ". $w [' act ']." ". $w [' Fen ']." ". $w [' money ']." <br> ";
}
} else{
echo "The car has no record of violation";
}
else{
//query unsuccessful
echo $wzResult [' Error_code ']. ":". $wzResult [' reason '];
}
Five, class.juhe.wz.php complete code
<!--? php//+----------------------------------------------------------------------//| juhephp [No ZUO no DIE]//+----------------------------------------------------------------------//|
Copyright (c) 2010-2015 http://juhe.cn All rights reserved. // +----------------------------------------------------------------------
// |
Author:juhedata <info@juhe.cn-->//+---------------------------------------------------------------------- ----------------------------------//Aggregation Data National Illegal interface call class//----------------------------------class wz{Private $appkey = False
Application of the national illegal inquiries appkey private $CITYURL = ' http://v.juhe.cn/wz/citys ';
Private $WZURL = ' http://v.juhe.cn/wz/query ';
Public function __construct ($appkey) {$this->appkey = $appkey; /** * Access to the list of cities supported by the violation * @return Array/Public function Getcitys ($province =false) {$params = ' key= '. $thi S->appkey. "
&format=2 ";
$content = $this->juhecurl ($this->cityurl, $params); ReTurn $this->_returnarray ($content); /** * Check the traffic violation * @param string $city [city Code] * @param string $carno [license plate number] * @param string $engineno [engine Number] * @param string $classno [frame number] * @return Array returns the violation information/Public function query ($city, $carno, $engineno = ', $cl
Assno= ') {$params = array (' key ' => $this->appkey, ' City ' => $city, ' hphm ' => $carno,
' Engineno ' => $engineno, ' Classno ' => $classno);
$content = $this->juhecurl ($this->wzurl, $params, 1);
return $this->_returnarray ($content); /** * Converts the JSON content to data and returns the * @param string $content [content] * @return Array/Public function _returnarray ($c
ontent) {return Json_decode ($content, true); The/** * Request interface returns the content * @param string $url [requested URL address] * @param string $params [requested parameters] * @param int $ipost [whether to use
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;
}
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.