您现在的位置是:首页> api 个人博客模板

天气查询

无痕小Q个人博客 2020-03-15 02:19:48主页 2162人已围观

简介输入地址可以查询该地区天气

接口地址https://yzc136.cn/api/open/weather

请求方式POST

请求参数 ( 参数名: city , 介绍: 这里是查询的城市 , 参数: 北京 。)

返回示例:

{"errors":false,"data":{"status":"1","count":"1","info":"OK","infocode":"10000","forecasts":[{"city":"北京市","adcode":"110000","province":"北京","reporttime":"2020-03-15 01:58:40","casts":[{"date":"2020-03-15","week":"7","dayweather":"晴","nightweather":"晴","daytemp":"16","nighttemp":"0","daywind":"东南","nightwind":"东南","daypower":"4","nightpower":"4"},{"date":"2020-03-16","week":"1","dayweather":"晴","nightweather":"晴","daytemp":"14","nighttemp":"1","daywind":"北","nightwind":"北","daypower":"≤3","nightpower":"≤3"},{"date":"2020-03-17","week":"2","dayweather":"晴","nightweather":"晴","daytemp":"19","nighttemp":"3","daywind":"西南","nightwind":"西南","daypower":"≤3","nightpower":"≤3"},{"date":"2020-03-18","week":"3","dayweather":"晴","nightweather":"多云","daytemp":"19","nighttemp":"4","daywind":"北","nightwind":"北","daypower":"4","nightpower":"4"}]}]}}

介绍:

本接口可以查询城市的天气

返回参数

名称

含义

规则说明

status

返回状态

值为0或1

1:成功;0:失败

count

返回结果总数目


info

返回的状态信息


infocode

返回状态说明,10000代表正确


lives

实况天气数据信息



province

省份名



city

城市名



adcode

区域编码



weather

天气现象(汉字描述)



temperature

实时气温,单位:摄氏度



winddirection

风向描述



windpower

风力级别,单位:级



humidity

空气湿度



reporttime

数据发布的时间


forecast

预报天气信息数据



city

城市名称



adcode

城市编码



province

省份名称



reporttime

预报发布时间



casts

预报数据list结构,元素cast,按顺序为当天、第二天、第三天的预报数据




date

日期




week

星期几




dayweather

白天天气现象




nightweather

晚上天气现象




daytemp

白天温度




nighttemp

晚上温度




daywind

白天风向




nightwind

晚上风向




daypower

白天风力




nightpower

晚上风力


php代码:

$host = "https://yzc136.cn/api/open/weather";
 
$method = "POST";
$headers = array();
array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");

$bodys = "city=北京";

$url = $host;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
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);
}

curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);

var_dump(curl_exec($curl));

python代码:

import urllib, urllib2, sys
import ssl


host = 'https://yzc136.cn/class/api/open/weather'
path = ''
method = 'POST'
appcode = ''
querys = ''
bodys = {}
url = host + path

bodys['city'] = '北京'
post_data = urllib.urlencode(bodys)
request = urllib2.Request(url, post_data)
request.add_header('Authorization', 'APPCODE ' + appcode)

request.add_header('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
response = urllib2.urlopen(request, context=ctx)
content = response.read()
if (content):
    print(content)

阅读量! (2162)

关于本站

昵称:无痕小Q

职业:php-go-web开发工程师

现居:北京

Email:1838638884@qq.com

    最累的时候,家人是你最好的归宿。

网站公告

  • 欢迎来到我的博客

  • 1:欢迎来到我的博客


    2:博客免费api接口现已上线


    3:博客会定期更新文章


    4:欢迎大家来捧场


    生活是一位睿智的长者,生活是一位博学的老师,它常常春风化雨,润物无声地为我们指点迷津,给我们人生的启迪。

站点信息

青山横北郭,白水绕东城。
此地一为别,孤蓬万里征。
浮云游子意,落日故人情。
挥手自兹去,萧萧班马鸣。 床前明月光,疑是地上霜。 举头望明月,低头思故乡。
  • 建站时间:2019-8-30
  • 网站程序:php,laravel-swoole框架
  • 今日流量:565(10分钟统计一次)
  • 本月流量:6026
  • 浏览总量:464528
  • 统计方式:中间件,redis消息队列,定时任务
    进军飞狐北,穷寇势将变。日落沙尘昏,背河更一战。 骍马黄金勒,雕弓白羽箭。射杀左贤王,归奏未央殿。 欲言塞下事,天子不召见。东出咸阳门,哀哀泪如霰。