ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2020-06-26 13:02:56  阅读:362  来源: 互联网

标签:07 编程 接口 weather Array PHP id wind temperature


一、根据城市名/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
)

标签:07,编程,接口,weather,Array,PHP,id,wind,temperature
来源: https://www.cnblogs.com/lpxspring/p/13194590.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有