php调用第三方的api,PHP接口编程——调用第三方接口获取天气

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

1e5a56b34bdc4de91b8c69a931abb189.png

二。

047f44448dbdaeb0343ca166f924a729.png

三、

3900a1b686f9c7c742f5679d0fc96b27.png

四、

5e6f0f486adda4e510079b586fe89698.png

实例

//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 '

';

//转化为数组

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值