[Public platform development] Baidu peripheral search interface php encapsulates a lot of entertainment products on the public platform, all of which are useful for peripheral search. The research is relatively simple. The Baidu peripheral search interface is encapsulated as follows:
Call format:
$wechatBaiduAPI = new WechatBaiduAPI();$ret = $wechatBaiduAPI->Place_search($str_key,$location['x'].",".$location['y'] );
Parameter description:
$ Query: search keyword
$ Location: geographical location, longitude, and latitude
$ Radius: search radius
Api_server_url = "http://api.map.baidu.com/place/v2/"; $ this-> auth_params = array (); $ this-> auth_params ['AK'] = "11ffd27d38deda622f51c9d314d46b1";} // http://api.map.baidu.com/place/search? & Query = glasses & location = 39.915, 116.404 & radius = 3000 & output = json & key = 37109c0ee6f924cb5e934fa08c6b1676public function Place_search ($ query, $ location, $ radius = 3000) {return $ this-> call ("search", array ("output" => json, "query" => $ query, "page_size" => 10, "page_num" => 0, "scope" => 2, "location" => $ location, "radius" => $ radius);} protected function call ($ method, $ params = array () {$ params = array_merge ($ this -> Auth_params, $ params); $ url = $ this-> api_server_url. "$ method? ". Http_build_query ($ params); $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true ); $ data = curl_exec ($ ch); curl_close ($ ch); $ result = null; $ result = json_decode ($ data, true); return $ result ;}}
Note: the accesskey in the code is a Baidu key. each Baidu account has a unique accesskey, which can be Baidu!
$this->auth_params['ak'] = "11ffd27d38deda622f51c9d314d46b1";