{ "status": 0, "message": "OK", "recommendStops": [{ "name": "北京发那科机电有限公司-东北门", "address": "信息路9号", "distance": 31.0, "bd09ll_x": 116.31336097180909, "bd09ll_y": 40.04875989119061, "gcj02ll_x": 116.30689819521366, "gcj02ll_y": 40.04270884908236, "id": "dbdfc729e22930d622f01734" }, { "name": "信息路/上地六街路口", "address": "", "distance": 91.0, "bd09ll_x": 116.3131004632112, "bd09ll_y": 40.04920864731756, "gcj02ll_x": 116.30663946101423, "gcj02ll_y": 40.0431529706092, "id": "48c13c08c88ffcb94557260b" }, { "name": "奎科科技大厦-正门", "address": "信息路甲9号东门", "distance": 122.0, "bd09ll_x": 116.31381910761918, "bd09ll_y": 40.047965930748038, "gcj02ll_x": 116.3073531765317, "gcj02ll_y": 40.0419230556821, "id": "d8d9f0057005489ff503b8bf" }] }
<?php /** * Created by PhpStorm. * User: FZS * Time: 2019/9/3 23:10 */ //---------------------------------- // 调用类 //---------------------------------- class freeApi{ private $ak; private $apiUrl; public function __construct($ak){ $this->ak = $ak; $this->apiUrl = 'http://api.map.baidu.com/parking/search?location=116.313064,40.048541&coordtype=bd09ll&ak='.$this->ak; } /** * 获取结果 * @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 , 'free-api' ); 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; } }