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

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

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

二。

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

三、

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

四、

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

实例

<?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接口编程——调用第三方接口获取天气

上一篇:PHP获取文件拓展名的方法


下一篇:Web For Pentester1 - LDAP attacks ,File Upload,XML attacks