码迷,mamicode.com
首页 > Web开发 > 详细

PHP接口编程——调用第三方接口获取天气

时间:2020-06-26 14:33:26      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:exe   第三方   file   temp   Oday   The   ima   dir   index   

一、根据城市名/id查询天气

技术图片

二。

技术图片

三、

技术图片

四、

技术图片

实例

<?php
//appkey
$key=‘9b1380be63fc20a841c454894651521‘;
$city=‘杭州‘;

//url
$url=‘http://v.juhe.cn/weather/index?key=‘.$key.‘&cityname=‘.$city.‘&dtype=json&format=2‘;

$res=file_get_contents($url);
echo ‘<pre>‘;
//转化为数组
print_r(json_decode($res,true));     

查询结果

Array
(
    [resultcode] => 200
    [reason] => 查询成功
    [result] => Array
        (
            [sk] => Array
                (
                    [temp] => 31
                    [wind_direction] => 西南风
                    [wind_strength] => 3级
                    [humidity] => 64%
                    [time] => 12:36
                )

            [today] => Array
                (
                    [temperature] => 25℃~32℃
                    [weather] => 小雨
                    [weather_id] => Array
                        (
                            [fa] => 07
                            [fb] => 07
                        )

                    [wind] => 东南风3-5级
                    [week] => 星期五
                    [city] => 杭州
                    [date_y] => 2020年06月26日
                    [dressing_index] => 炎热
                    [dressing_advice] => 天气炎热,建议着短衫、短裙、短裤、薄型T恤衫等清凉夏季服装。
                    [uv_index] => 弱
                    [comfort_index] => 
                    [wash_index] => 不宜
                    [travel_index] => 较不宜
                    [exercise_index] => 较不宜
                    [drying_index] => 
                )

            [future] => Array
                (
                    [0] => Array
                        (
                            [temperature] => 25℃~32℃
                            [weather] => 小雨
                            [weather_id] => Array
                                (
                                    [fa] => 07
                                    [fb] => 07
                                )

                            [wind] => 东南风3-5级
                            [week] => 星期五
                            [date] => 20200626
                        )

                    [1] => Array
                        (
                            [temperature] => 24℃~28℃
                            [weather] => 中雨-大雨转阴
                            [weather_id] => Array
                                (
                                    [fa] => 22
                                    [fb] => 02
                                )

                            [wind] => 西南风4-5级
                            [week] => 星期六
                            [date] => 20200627
                        )

                    [2] => Array
                        (
                            [temperature] => 25℃~30℃
                            [weather] => 阴
                            [weather_id] => Array
                                (
                                    [fa] => 02
                                    [fb] => 02
                                )

                            [wind] => 东南风3-5级
                            [week] => 星期日
                            [date] => 20200628
                        )

                    [3] => Array
                        (
                            [temperature] => 24℃~30℃
                            [weather] => 中雨-大雨转小雨
                            [weather_id] => Array
                                (
                                    [fa] => 22
                                    [fb] => 07
                                )

                            [wind] => 西南风5-6级
                            [week] => 星期一
                            [date] => 20200629
                        )

                    [4] => Array
                        (
                            [temperature] => 23℃~30℃
                            [weather] => 小雨
                            [weather_id] => Array
                                (
                                    [fa] => 07
                                    [fb] => 07
                                )

                            [wind] => 持续无风向微风
                            [week] => 星期二
                            [date] => 20200630
                        )

                    [5] => Array
                        (
                            [temperature] => 24℃~28℃
                            [weather] => 中雨-大雨转阴
                            [weather_id] => Array
                                (
                                    [fa] => 22
                                    [fb] => 02
                                )

                            [wind] => 西南风4-5级
                            [week] => 星期三
                            [date] => 20200701
                        )

                    [6] => Array
                        (
                            [temperature] => 24℃~30℃
                            [weather] => 中雨-大雨转小雨
                            [weather_id] => Array
                                (
                                    [fa] => 22
                                    [fb] => 07
                                )

                            [wind] => 西南风5-6级
                            [week] => 星期四
                            [date] => 20200702
                        )

                )

        )

    [error_code] => 0
)

PHP接口编程——调用第三方接口获取天气

标签:exe   第三方   file   temp   Oday   The   ima   dir   index   

原文地址:https://www.cnblogs.com/lpxspring/p/13194590.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!