天气查询接口
昨日/今日/明日天气查询接口

接口地址: https://api.mir6.com/api/tqcx

返回格式: JSON

请求方式: GET

请求示例: https://api.mir6.com/api/tqcx?name=绵阳市&num=1

请求参数说明:

名称 必填 参数示例 类型 说明
name 绵阳市 string 需要查询的城市名称
num 1 string 需要查询的下辖区县编号,为1时查询本城市/该参数为空将返回下辖区县名

返回参数说明:

名称 类型 说明
num int 请求参数num为空时返回下辖区县总数/否则返回请求参数num值
data 数组 请求参数num为空时返回数组列城市名称/否则返回天气相关信息
data.cityname string 查询的城市名称
data.yesterday_xingqi string 昨日星期几
data.yesterday_wendu_minimum string 昨日最低温度
data.yesterday_wendu_highest string 昨日最高温度
data.yesterday_tianqi string 昨日天气
data.yesterday_fengli string 昨日风力
data.yesterday_fengji string 昨日风级
data.yesterday_kongqi string 昨日空气质量
data.today_xingqi string 今日星期几
data.today_wendu_minimum string 今日最低温度
data.today_wendu_highest string 今日最高温度
data.today_tianqi string 今日天气
data.today_fengli string 今日风力
data.today_fengji string 今日风级
data.today_kongqi string 今日空气质量
data.tomorrow_xingqi string 明日星期几
data.tomorrow_wendu_minimum string 明日最低温度
data.tomorrow_wendu_highest string 明日最高温度
data.tomorrow_tianqi string 明日天气
data.tomorrow_fengli string 明日风力
data.tomorrow_fengji string 明日风级
data.tomorrow_kongqi string 明日空气质量

返回示例:

{
	"code": 200,
	"msg": "查询成功",
	"num": 1,
	"data": {
		"cityname": "绵阳市",
		"yesterday_xingqi": "周三",
		"yesterday_wendu_minimum": "6",
		"yesterday_wendu_highest": "10",
		"yesterday_tianqi": "阴",
		"yesterday_fengdu": "微风",
		"yesterday_fengji": "1级",
		"yesterday_kongqi": "优",
		"today_xingqi": "周四",
		"today_wendu_minimum": "6",
		"today_wendu_highest": "10",
		"today_tianqi": "小雨",
		"today_fengdu": "微风",
		"today_fengji": "2级",
		"today_kongqi": "优",
		"tomorrow_xingqi": "周五",
		"tomorrow_wendu_minimum": "6",
		"tomorrow_wendu_highest": "11",
		"tomorrow_tianqi": "阴",
		"tomorrow_fengdu": "微风",
		"tomorrow_fengji": "2级",
		"tomorrow_kongqi": "良"
	}
}

请求参数设置:

参数名称 参数值


{
	"code": 200,
	"msg": "查询成功",
	"num": 1,
	"data": {
		"cityname": "绵阳市",
		"yesterday_xingqi": "周三",
		"yesterday_wendu_minimum": "6",
		"yesterday_wendu_highest": "10",
		"yesterday_tianqi": "阴",
		"yesterday_fengdu": "微风",
		"yesterday_fengji": "1级",
		"yesterday_kongqi": "优",
		"today_xingqi": "周四",
		"today_wendu_minimum": "6",
		"today_wendu_highest": "10",
		"today_tianqi": "小雨",
		"today_fengdu": "微风",
		"today_fengji": "2级",
		"today_kongqi": "优",
		"tomorrow_xingqi": "周五",
		"tomorrow_wendu_minimum": "6",
		"tomorrow_wendu_highest": "11",
		"tomorrow_tianqi": "阴",
		"tomorrow_fengdu": "微风",
		"tomorrow_fengji": "2级",
		"tomorrow_kongqi": "良"
	}
}

错误码格式说明:

名称 类型 说明
code int 返回状态码 -1 未提交name参数
返回状态码 200/201 成功/失败
返回状态码 202 访问接口超过QPS限制15次/秒 / 备注:当前设置QPS计时周期为5分钟 / 注意:如有高频QPS需求请注册帐号使用mykey设置ip白名单访问

代码示例:

<?php 
$name = $_GET['name'];
$num = $_GET['num'];
$str = file_get_contents('https://api.mir6.com/api/tqcx?name='.$name.'&num='.$num);
$data = json_decode($str,true);
$name = $data['data']['cityname'];
$yesterday_xingqi = $data['data']['yesterday_xingqi'];
$yesterday_wendu_minimum = $data['data']['yesterday_wendu_minimum'];
$yesterday_wendu_highest = $data['data']['yesterday_wendu_highest'];
$yesterday_tianqi = $data['data']['yesterday_tianqi'];
$yesterday_fengli = $data['data']['yesterday_fengli'];
$yesterday_fengji = $data['data']['yesterday_fengji'];
$yesterday_kongqi = $data['data']['yesterday_kongqi'];
$today_xingqi = $data['data']['today_xingqi'];
$today_wendu_minimum = $data['data']['today_wendu_minimum'];
$today_wendu_highest = $data['data']['today_wendu_highest'];
$today_tianqi = $data['data']['today_tianqi'];
$today_fengli = $data['data']['today_fengli'];
$today_fengji = $data['data']['today_fengji'];
$today_kongqi = $data['data']['today_kongqi'];
$tomorrow_xingqi = $data['data']['tomorrow_xingqi'];
$tomorrow_wendu_minimum = $data['data']['tomorrow_wendu_minimum'];
$tomorrow_wendu_highest = $data['data']['tomorrow_wendu_highest'];
$tomorrow_tianqi = $data['data']['tomorrow_tianqi'];
$tomorrow_fengli = $data['data']['tomorrow_fengli'];
$tomorrow_fengji = $data['data']['tomorrow_fengji'];
$tomorrow_kongqi = $data['data']['tomorrow_kongqi'];
?>
<!--HTML代码开始-->
<ul>
<li>查询的城市名称:<?php echo $name;?></li>
<li>昨日星期:<?php echo $yesterday_xingqi;?></li>
<li>昨日最低温度:<?php echo $yesterday_wendu_minimum;?></li>
<li>昨日最高温度:<?php echo $yesterday_wendu_highest;?></li>
<li>昨日天气:<?php echo $yesterday_tianqi;?></li>
<li>昨日风力:<?php echo $yesterday_fengli;?></li>
<li>昨日风级:<?php echo $yesterday_fengji;?></li>
<li>昨日空气质量:<?php echo $yesterday_kongqi;?></li>
<li>今日星期:<?php echo $today_xingqi;?></li>
<li>今日最低温度:<?php echo $today_wendu_minimum;?></li>
<li>今日最高温度:<?php echo $today_wendu_highest;?></li>
<li>今日天气:<?php echo $today_tianqi;?></li>
<li>今日风力:<?php echo $today_fengli;?></li>
<li>今日风级:<?php echo $today_fengji;?></li>
<li>今日空气质量:<?php echo $today_kongqi;?></li>
<li>明日星期:<?php echo $tomorrow_xingqi;?></li>
<li>明日最低温度:<?php echo $tomorrow_wendu_minimum;?></li>
<li>明日最高温度:<?php echo $tomorrow_wendu_highest;?></li>
<li>明日天气:<?php echo $tomorrow_tianqi;?></li>
<li>明日风力:<?php echo $tomorrow_fengli;?></li>
<li>明日风级:<?php echo $tomorrow_fengji;?></li>
<li>明日空气质量:<?php echo $tomorrow_kongqi;?></li>
</ul>
最后,假设写在了api.php,访问api.php/?name=城市名称&num=下辖区县编号,1为本城市
<!--HTML代码结束-->