
吃完早饭觉得有点无聊,不想继续敲代码(但是又想敲)……突然想起朋友前两天让我帮忙写个天气API,于是就打开Notepad,敲代码
优点/特性
- 同时支持HTTP/HTTPS协议
- 准确获取天气情况
- 自带天气ICO,快速集成(点击下载)
本接口目前仍有很多需要改善的地方,如果您在使用中有任何的意见/建议甚至系统出现故障都可以联系我
使用方法
直接使用URL参数的形式调用即可
请求方法
HTTP/HTTPS GET
返回数据
Json
接口地址
请求示例(PHP)
<?php
$host = "http://api.yuncaioo.com";
$path = "/weather";
$method = "GET";
$querys = "city=上海";
$bodys = "";
$url = $host . $path . "?" . $querys;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
if (1 == strpos("$".$host, "https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
var_dump(curl_exec($curl));
?>
返回数据(Json)
{
"code":"200",
"city":"上海",
"date":"2017-08-28",
"week":"星期一",
"weather":"多云",
"winddirect":"东南风",
"windpower":"2级",
"temp":"35",
"temphigh":"36",
"templow":"27",
"img":"1",
"uptime":"2017-08-28 11:35:01"
}
返回参数
code: 状态码
city: 城市
date: 日期
week: 星期
weather: 天气
winddirect: 风向
windpower: 风力
temp: 温度
temphigh: 当日最高温度
templow: 当日最低温度
img: 图片编号(需搭配天气图片使用)
uptime: 发布日期
原创文章采用 CC BY-NC-SA 4.0 协议 进行许可,转载请注明来源。
最近(2018年7月14日)怎么一直返回
{
“code”:”500″,
“msg”:”系统故障”
}
呢?
我昨天打开易语言用这个接口写了一个天气预报(๑•̀ㅁ•́ฅ),然后第二天下午打开发现一直返回“系统故障”
感觉非常开心ヾ(≧∇≦*)ゝ
我说呢(╯‵□′)╯︵┴─┴
dalao欸
估计没什么人用=w=