稳定、快速、免费的 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": "10",
"weather": "阴转多云",
"wind": "东北风转北风",
"windSpeed": "3-4级",
"time": "2025-02-23 08:00",
"warning": {},
"current": {
"city": "广州",
"cityEnglish": "guangzhou",
"humidity": "56%",
"wind": "东北风",
"windSpeed": "2级",
"visibility": "28km",
"weather": "晴",
"weatherEnglish": "Sunny",
"temp": "14.7",
"fahrenheit": "58.5",
"air": "18",
"air_pm25": "18",
"date": "02月23日(星期日)",
"time": "19:30",
"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": "辐射较弱,涂擦SPF12-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": "涂抹12-15SPF,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;
}
}
?>