Php reads APIJson data from Baidu weather

Source: Internet
Author: User
This article briefly introduces how to use baidu's iov api to read the official JSON Data Manual developer. baidu. commapwikiindex. php? Titlecarapiweather #. e8.BF. 94. e5.9B. 9E. e7.BB. 93. e6.9E. 9C had been tossing for several hours today to understand the weather interface in Baidu API. To be honest, Baidu is also pitfall,

This article briefly introduces how to use Baidu's Internet of vehicles API to read the JSON data official manual http://developer.baidu.com/map/wiki/index.php? Title = car/api/weather #. e8.BF. 94. e5.9B. 9E. e7.BB. 93. e6.9E. 9C had been tossing for several hours today to understand the weather interface in Baidu API. To be honest, Baidu is also pitfall,

This article briefly introduces how to read JSON data using Baidu's IOV API

Official Manual

Http://developer.baidu.com/map/wiki/index.php? Title = car/api/weather #. E8.BF. 94. E5.9B. 9E. E7.BB. 93. E6.9E. 9C

Today, I spent several hours figuring out the weather interface in Baidu API. To be honest, Baidu is also a pitfall. I tried it for the first time because I chose a server as the application type, why can't I verify it? I chose the sn verification white list.

The second time I tried it directly in the browser, the result was successfully read into the json data, and the rest will be parsed ....


Run the Code directly.

Weather
 $ Ak, "location" => $ location, "output" => $ output );
// Baidu sn algorithm $ sn = caculateAKSN ($ ak, $ sk, $ url, $ querystring_arrays); return sprintf ($ url, $ ak, $ location, $ output, $ sn);} function browser ($ output, $ location) {// browser test ----- $ ak = "xxxxxxxx"; $ url = "http://api.map.baidu.com/telematics/v3/weather? Ak = % s & location = % s & output = % s "; return sprintf ($ url, $ ak, $ location, $ output);} // $ template = http://api.map.baidu.com/telematics/v3/weather? Location = % s & output = % s & ak = % s $ weather_contents = file_get_contents ($ result); print_r (json_decode ($ weather_contents);?>

From another submitted city, the operations after I come in are like the above. Here I will explain a few places where ak is the app key in the Baidu application. If it is a server type, secret key, if the browser type does not exist, use the sn algorithm provided by Baidu for encryption. The Code is as follows:

 Value format. The signature cannot be re-ordered after calculation, or the data element * @ param string $ method can only be 'post' or 'get' */function caculateAKSN ($ ak, $ sk, $ url, $ querystring_arrays, $ method = 'get') {if ($ method = 'post') {ksort ($ querystring_arrays );} $ querystring = http_build_query ($ querystring_arrays); return md5 (urlencode ($ url. '? '. $ Querystring. $ sk) ;}?>
I haven't understood it for a long time. The url has no format. What do I mean? I did it later, because I read it... why are there two different pages ....

Http://developer.baidu.com/map/index.php? Title = lbscloud/api/appendix

Forgive me for my IQ.

Location can be transcoded using urlencode to avoid errors. In the end, get the complete result and use file_get_contents to get the data, which is output in array format...

For beginners, I want to help you.



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.