How to use PHP to call API interface to implement weather query function

一个新手
Release: 2023-03-16 12:20:01
Original
3117 people have browsed it

Weather forecast query interface API, here I use the National Meteorological Administration weather forecast interface

The most commonly used ones are: Sina weather forecast interface, Baidu weather forecast interface, google weather interface, Yahoo weather Interfaces and so on.

1. Query method

Query the weather conditions of each city based on place name

2. Request URL address
http://route.showapi.com/9-2

3. Interface parameter description:

1. System-level parameters (parameters required by all access points):

2. Application-level parameters (each access point has its own parameters):

4. Return parameters

Return results in JSON format

1) System-level parameters (parameters returned by all access points)

2)Application Level parameters (json data structure in the system-level output parameter showapi_res_body field)

Specific calling operation:

PHP It comes with built-in functions for processing json format strings. Let’s do an example below and give the complete code:


 , 'areaid'=> "", 'area'=> "淄博", 'needMoreDay'=> "", 'needIndex'=> "", 'needHourData'=> "", 'need3HourForcast'=> "", 'needAlarm'=> "" createParam (, = "" = ""( ( => ( != '' && != '' .= . .= .'='.().'&' .= ; = (( .= 'showapi_sign='.; = createParam(, = 'http://route.showapi.com/9-2?'. = ( = (json_decode( = ->
Copy after login

The effect is as shown in the figure:

The above is the detailed content of How to use PHP to call API interface to implement weather query function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!