{ "status": "1", "info": "OK", "infocode": "10000", "trafficinfo": { "description": "京藏高速:从龙城园到中医药报社严重拥堵;中关村北大街:自北向南缓慢,从圆明园遗址东门到清华大学西门严重拥堵;清华西路:双向拥堵;颐和园路:北京大学西门附近自南向北严重拥堵,反向行驶缓慢;北四环路:海淀桥附近自西向东行驶缓慢;成府路:从王庄路到财经东路行驶缓慢;巴沟路:双向缓慢;彩和坊路:创富大厦附近自北向南行驶缓慢;海淀大街:自西向东缓慢,反向畅通;善缘街:我们电子大厦附近自西向东行驶缓慢。", "evaluation": { "expedite": "76.00%", "congested": "16.00%", "blocked": "8.00%", "unknown": "0.00%", "status": "2", "description": "轻度拥堵" } } }
<?php /** * Created by PhpStorm. * User: FZS * Time: 2019/7/20 17:50 */ //---------------------------------- // 圆形区域交通态势 调用类 //---------------------------------- class freeApi{ private $apiUrl = 'https://restapi.amap.com/v3/traffic/status/circle?rectangle=116,39;116,39&radius=15&key=key'; /** * 获取 圆形区域交通态势 结果 * @return array */ public function getResult(){ return $this->freeApiCurl($this->apiUrl); } /** * 请求接口返回内容 * @param string $url [请求的URL地址] * @param string $params [请求的参数] * @param int $ipost [是否采用POST形式] * @return string */ public function freeApiCurl($url,$params=false,$ispost=0){ $ch = curl_init(); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); curl_setopt( $ch, CURLOPT_USERAGENT , 'chuanshuoapi' ); 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) { return false; } curl_close( $ch ); return $response; } }