[WeChat public platform development] php encapsulation of Baidu peripheral search interface

Source: Internet
Author: User
[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";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.