稳定、快速、免费的 API 接口服务
如初API天气查询
接口地址: https://www.58.linkpc.net/api/weather
返回格式: 请看返回示例
请求方式: GET
请求示例: https://www.58.linkpc.net/api/weather?city=广州
请求参数说明:
名称 | 必填 | 类型 | 说明 |
---|---|---|---|
city | 是 | string | 需要查询的地区名 |
返回参数说明:
名称 | 类型 | 说明 |
---|
返回示例:
{
"code": 1,
"text": "获取成功",
"data": {
"city": "广州",
"cityEnglish": "guangzhou",
"temp": "999",
"tempn": "23",
"weather": "阴转多云",
"wind": "西南风转微风",
"windSpeed": "<3级",
"time": "2025-05-02 08:00",
"warning": {},
"current": {
"city": "广州",
"cityEnglish": "guangzhou",
"humidity": "100%",
"wind": "北风",
"windSpeed": "1级",
"visibility": "16km",
"weather": "阴",
"weatherEnglish": "Overcast",
"temp": "25.1",
"fahrenheit": "77.2",
"air": "41",
"air_pm25": "41",
"date": "05月01日(星期四)",
"time": "23:50",
"image": "http://api.suyanw.cn/api/data/weather/image/云.png"
},
"living": [
{
"name": "穿衣指数",
"index": "舒适",
"tips": "建议穿长袖衬衫单裤等服装。"
},
{
"name": "路况指数",
"index": "湿滑",
"tips": "部分路面湿滑,车辆易打滑,小心驾驶。"
},
{
"name": "钓鱼指数",
"index": "适宜",
"tips": "适宜垂钓,愿您度过愉快垂钓时光。"
},
{
"name": "晨练指数",
"index": "较适宜",
"tips": "部分地面较湿滑,选择合适的地点晨练。"
},
{
"name": "夜生活指数",
"index": "较适宜",
"tips": "只要您稍作准备就可以放心外出。"
},
{
"name": "感冒指数",
"index": "易发",
"tips": "大幅度降温,湿度较大,注意防护。"
},
{
"name": "逛街指数",
"index": "适宜",
"tips": "这种好天气去逛街可使身心畅快放松。"
},
{
"name": "空气污染扩散条件指数",
"index": "中",
"tips": "易感人群应适当减少室外活动。"
},
{
"name": "旅游指数",
"index": "适宜",
"tips": "天气较好,丝毫不会影响您出行的心情。"
},
{
"name": "舒适度指数",
"index": "舒适",
"tips": "白天温度宜人,风力不大。"
},
{
"name": "啤酒指数",
"index": "较适宜",
"tips": "适量的饮用啤酒,注意不要过量。"
},
{
"name": "划船指数",
"index": "适宜",
"tips": "天气较好,适宜划船及嬉玩水上运动。"
},
{
"name": "太阳镜指数",
"index": "必要",
"tips": "建议佩戴透射比为1级的浅色太阳镜"
},
{
"name": "紫外线强度指数",
"index": "中等",
"tips": "涂擦SPF大于15、PA+防晒护肤品。"
},
{
"name": "风寒指数",
"index": "无",
"tips": "温度未达到风寒所需的低温,稍作防寒准备即可。"
},
{
"name": "放风筝指数",
"index": "较适宜",
"tips": "温暖舒适,较适宜放风筝。"
},
{
"name": "空调开启指数",
"index": "较少开启",
"tips": "体感舒适,不需要开启空调。"
},
{
"name": "晾晒指数",
"index": "适宜",
"tips": "天气不错,抓紧时机让衣物晒太阳吧。"
},
{
"name": "洗车指数",
"index": "不宜",
"tips": "积水较多,车辆易溅上泥水。"
},
{
"name": "心情指数",
"index": "较好",
"tips": "温度适宜,心情会不错。"
},
{
"name": "中暑指数",
"index": "无中暑风险",
"tips": "天气不热,在炎炎夏日中十分难得,可以告别暑气漫漫啦~"
},
{
"name": "交通指数",
"index": "较差",
"tips": "路面湿滑,注意控制车速。"
},
{
"name": "约会指数",
"index": "较适宜",
"tips": "不用担心天气来调皮捣乱而影响了兴致。"
},
{
"name": "运动指数",
"index": "适宜",
"tips": "天气较好,尽情感受运动的快乐吧。"
},
{
"name": "过敏指数",
"index": "不易发",
"tips": "除特殊体质,无需担心过敏问题。"
},
{
"name": "美发指数",
"index": "适宜",
"tips": "建议选择含防晒滋润成分的护发品。"
},
{
"name": "雨伞指数",
"index": "不带伞",
"tips": "天气较好,不用带雨伞。"
},
{
"name": "防晒指数",
"index": "中等",
"tips": "适合涂擦SPF大于15,PA+护肤品。"
},
{
"name": "化妆指数",
"index": "保湿",
"tips": "请选用中性保湿型霜类化妆品。"
},
{
"name": "干燥指数",
"index": "适宜",
"tips": "温湿条件适宜,风速不大,皮肤无需特殊保养,只做日常护理即可。"
}
]
}
}
错误码格式说明:
名称 | 类型 | 说明 |
---|
代码示例:
<?php
header('Content-type: application/json; charset=utf-8');
date_default_timezone_set('PRC');
$url = 'https://58.linkpc.net/api/weather';
$type = isset($_GET['type']) ? $_GET['type'] : '';
if ($type == 'json' || $type == 'JSON') {
$result = file_get_contents($url . '?type=json');
echo $result;
} else {
// 使用cURL获取URL内容
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
// 检查内容类型并输出相应内容
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch);
if (strpos($contentType, 'image') !== false) {
// 输出图片
header('Content-Type: ' . $contentType);
echo $response;
} elseif (strpos($contentType, 'text') !== false) {
// 输出文字
header('Content-Type: ' . $contentType);
echo $response;
} elseif (strpos($contentType, 'application/json') !== false) {
// 输出JSON
header('Content-Type: application/json');
echo $response;
} else {
// 输出网页返回内容
header('Content-Type: text/html');
echo $response;
}
}
?>