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

天气查询

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

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

接口地址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)

阅读量! (2161)

关于本站

昵称:无痕小Q

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

现居:北京

Email:1838638884@qq.com

    把复杂的事情简单化,把琐碎的事情自动化,集中精力做事

网站公告

  • 欢迎来到我的博客

  • 1:欢迎来到我的博客


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


    3:博客会定期更新文章


    4:欢迎大家来捧场


    山河远阔,人间烟火,无一是你,无一不是你。愿我们的相逢,是爱情,是天时地利人和,是一切都刚刚好。

站点信息

皓月清凉, 你是人间曙光. 辛苦遭逢起一经,干戈寥落四周星。 山河破碎风飘絮,身世浮沉雨打萍。 惶恐滩头说惶恐,零丁洋里叹零丁。 人生自古谁无死,留取丹心照汗青。
  • 建站时间:2019-8-30
  • 网站程序:php,laravel-swoole框架
  • 今日流量:411(10分钟统计一次)
  • 本月流量:5872
  • 浏览总量:464374
  • 统计方式:中间件,redis消息队列,定时任务
    在你生命的前30年里,你养成习惯。 在你生命的后30年里,你的习惯决定了你。 -- 乔布斯