{ "status": 0, "message": "ok", "result": { "uid": "435d7aea036e54355abbbcc8", "street_id": "435d7aea036e54355abbbcc8", "name": "百度大厦", "location": { "lng": 116.30789936414, "lat": 40.05703792689 }, "address": "北京市海淀区上地十街10号", "province": "北京市", "city": "北京市", "area": "海淀区", "detail_info": { "tag": "房地产;写字楼", "navi_location": { "lng": 116.30695398742, "lat": 40.057199045475 }, "alias": [ "" ], "detail_url": "http://api.map.baidu.com/place/detail?uid=435d7aea036e54355abbbcc8&output=html&source=placeapi_v2", "type": "house", "overall_rating": "3.8", "image_num": "50", "comment_num": "50", "content_tag": "位置优越;毗邻地铁;花园景观" }, "detail": 1 } }
<?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/place/v2/detail?uid=435d7aea036e54355abbbcc8&output=json&scope=2&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; } }