稳定、快速、免费的 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": "21",
"tempn": "20",
"weather": "阵雨",
"wind": "东南风",
"windSpeed": "3-4级",
"time": "2025-04-26 08:00",
"warning": {},
"current": {
"city": "广州",
"cityEnglish": "guangzhou",
"humidity": "96%",
"wind": "东北风",
"windSpeed": "1级",
"visibility": "6km",
"weather": "阴",
"weatherEnglish": "Overcast",
"temp": "24",
"fahrenheit": "75.2",
"air": "51",
"air_pm25": "51",
"date": "04月26日(星期六)",
"time": "15:55",
"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": "白天能见度差不需要佩戴太阳镜"
},
{
"name": "紫外线强度指数",
"index": "最弱",
"tips": "辐射弱,涂擦SPF8-12防晒护肤品。"
},
{
"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": "涂抹8-12SPF防晒护肤品。"
},
{
"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;
}
}
?>