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

天气查询

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

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

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

阅读量! (1947)

关于本站

昵称:无痕小Q

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

现居:北京

Email:1838638884@qq.com

点击排行

细草微风岸,危樯独夜舟。  星垂平野阔,月涌大江流。  名岂文章著,官应老病休。  飘飘何所似?天地一沙鸥。 细草微风岸,危樯独夜舟。 星垂平野阔,月涌大江流。 名岂文章著,官应老病休。 飘飘何所似?天地一沙鸥。
    欲下星斗动,天乐一声肌骨寒。  金霞昕昕渐东上,轮欹影促犹频望。  绝景良时难再并,他年此日应惆怅。

网站公告

  • 欢迎来到我的博客

  • 1:欢迎来到我的博客


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


    3:博客会定期更新文章


    4:欢迎大家来捧场


    尝同徐勉构东田,花竹成阴雨后天。为爱宪台宽白简,得随相府赏红莲。清樽屡釂吟情逸,红袖频翻舞态妍。归兴直须三鼓尽,月华况是十分圆。

站点信息

渭城朝雨浥轻尘,客舍青青柳色新。
劝君更尽一杯酒,西出阳关无故人。 海纳百川,有容乃大;壁立千仞,无欲则刚。
  • 建站时间:2019-8-30
  • 网站程序:php,laravel-swoole框架
  • 今日流量:0(10分钟统计一次)
  • 本月流量:0
  • 浏览总量:396141
  • 统计方式:中间件,redis消息队列,定时任务
    听闻远方有你,动身跋涉千里,我吹过你吹过的风,这算不算相拥,我喜欢你,从一而终,认真且怂。