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

天气查询

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

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

接口地址https://yzc136.cn/class/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/class/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)

阅读量! (1314)

关于本站

昵称:无痕小Q

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

现居:北京

Email:1838638884@qq.com

    回首,轮回的渡口依旧熙熙攘攘。看一些缘分来了又走,走了又回。看一些人渐行渐远,终淡出彼此的视线。那一年,走失的青春。早已,淡出了瞩目的号码牌。

网站公告

  • 欢迎来到我的博客

  • 1:欢迎来到我的博客


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


    3:博客会定期更新文章


    4:欢迎大家来捧场


    昔人已乘黄鹤去,此地空余黄鹤楼。  黄鹤一去不复返,白云千载空悠悠。  晴川历历汉阳树,芳草萋萋鹦鹉洲。  日暮乡关何处是,烟波江上使人愁。

站点信息

要说酸甜苦辣都不足以形容人生的苦于乐,唯有一个熬字,各中滋味万千,身在其中的人最明白。 风回岂复坚。 明月易低人易散,归来呼酒更重看。
  • 建站时间:2019-8-30
  • 网站程序:php,laravel-swoole框架
  • 今日流量:92(10分钟统计一次)
  • 本月流量:9433
  • 浏览总量:388360
  • 统计方式:中间件,redis消息队列,定时任务
    生命的天空,或晴空万里,或阴云密布,或狂风暴雨,无论身处何时,只要坚定信念,乌云必散,暴雨必停,阳光必现。