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:
<? = '46435'; = '7c55aef4ede442ffa49b24c2c808e523'; = 'showapi_appid'=> , 'areaid'=> "", 'area'=> "淄博", 'needMoreDay'=> "", 'needIndex'=> "", 'needHourData'=> "", 'need3HourForcast'=> "", 'needAlarm'=> "" createParam (, = "" = ""( ( => ( != '' && != '' .= . .= .'='.().'&' .= ; = (( .= 'showapi_sign='.; = createParam(, = 'http://route.showapi.com/9-2?'. = ( = (json_decode( = ->
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!