Home  >  Article  >  Backend Development  >  How to use PHP to call API interface to implement weather query function

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

一个新手
一个新手Original
2017-09-28 10:08:163205browse

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:


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

Statement:
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