聚合数据违章查询接口文档:http://www.juhe.cn/docs/api/id/36,本文仅供学习参考。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
/** * 获取违章支持的城市列表 * @return array */ function wzCity($province=false){ $config = get_config('juhe'); //读取配置 $postArr = array ( 'key' => $config['wz_appkey'], 'province' => $province, 'format' => 1 ); $result = curlPost($config['wz_citys_url'], $postArr); writeLogFile('juhe', 'wzCity:'.$result); //写日志 $jsonArr = json_decode($result, true); return $jsonArr; } /** * 查询车辆违章(聚合数据v1.0) * @param array $info 查询信息:engineno和classno根据城市代码填写 * @param int $query_from 终端:1-平台端 2-门店端 * @param string $op_user 操作者 * @param boolean $log 是否记录查询日志 * @return array 违章信息 */ function wzQuery($info, $query_from, $op_user, $log=true){ $config = get_config('juhe'); //读取配置 $postArr = array ( 'key' => $config['wz_appkey'], 'city' => $info['city'], //城市代码 'hphm' => $info['plate_number'], //车牌 'engineno' => $info['engineno'], //发动机号 'classno' => $info['classno'], //车架号 ); $result = curlPost($config['wz_query_url'], $postArr); writeLogFile('juhe', 'wzQuery:'.$result); //写日志 $jsonArr = json_decode($result, true); /* 查询记录 */ if($log) { $wzQuery = M("wz_query"); if($jsonArr['resultcode'] == 200){ if($jsonArr['result']['lists']){ foreach($jsonArr['result']['lists'] as $key =>$w){ $data['plate_number'] = $info['plate_number']; //车牌 $data['area'] = $w['area']; //违章地点 $data['act'] = $w['act']; //违章行为 $data['wz_time'] = strtotime($w['date']); //违章时间 $data['money'] = $w['money']; //违章罚款 $data['score'] = $w['fen']; //违章扣分 $data['handled'] = $w['handled']; //是否处理:0-未处理 1-已处理 空-未知 $data['add_time'] = time(); //查询时间 $data['query_from'] = $query_from; $data['op_user'] = $op_user; $data['result_code'] = '200'; $data['result_msg'] = 'success'; $wzQuery->add($data); unset($data); } }else{ $data['plate_number'] = $info['plate_number']; $data['add_time'] = time(); $data['query_from'] = $query_from; $data['op_user'] = $op_user; $data['result_code'] = '200'; $data['result_msg'] = 'success'; $wzQuery->add($data); } }else{ $data['plate_number'] = $info['plate_number']; $data['add_time'] = time(); $data['query_from'] = $query_from; $data['op_user'] = $op_user; $data['result_code'] = $jsonArr['resultcode']; $data['result_msg'] = $jsonArr['reason']; $wzQuery->add($data); } } return $jsonArr; } /** * 违章接口剩余请求次数查询 * @return array */ function wzBalance(){ $config = get_config('juhe'); //读取配置 $postArr = array ( 'key' => $config['wz_appkey'] ); $result = curlPost($config['wz_status_url'], $postArr); writeLogFile('juhe', 'wzBalance:'.$result); //写日志 $jsonArr = json_decode($result, true); return $jsonArr; } /** * 通过CURL发送HTTP请求 * @param string $url //请求URL * @param array $postFields //请求参数 * @return mixed */ function curlPost($url,$postFields){ $postFields = http_build_query($postFields); $ch = curl_init (); curl_setopt ( $ch, CURLOPT_POST, 1 ); curl_setopt ( $ch, CURLOPT_HEADER, 0 ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_URL, $url ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $postFields ); $result = curl_exec ( $ch ); curl_close ( $ch ); return $result; } |