实时天气预报
简介:可根据城市代码、城市中文、城市拼音、ip地址、经纬度信息提供全国各城市提供全国各城市实时天气预报,含当前及未来一天
接口代码:rtweather 已接入应用数:280 接口状态:正常
接口价格: 0 元/次 接口服务商:点睛数据 申请 测试 接口请求地址示例:api.djapi.cn/rtweather/get 请求接口的方式: GET        POST
参数名 参数说明 可选值 备注 必填项
citycode 城市代码(旧)|城市代码(新) << 点击查看列表 速度快,准确率高,推荐等级为1级(建议优先使用该方式获取数据)
cityname_ch 城市名称(中文) 速度偏慢,准确率高,推荐等级为3级
cityname_py 城市名称(拼音) 速度偏慢,准确率偏低,推荐等级为4级(不推荐)
ip IP地址 速度快,准确率较高,推荐等级为2级(使用此方法较为简单,但准确率稍欠佳,请斟酌使用)
jwd 经纬度,输入格式如: 经度|纬度 速度快,准确率较高,推荐等级为2级(使用此方法较为简单,但准确率稍欠佳,请斟酌使用)
cn_to_unicode 汉字Unicode转码 1
0
本设置是对服务器返回数据时是否对中文汉字进行unicode转码,为增强兼容性,默认以unicode转码
token 密匙 您的token密匙
datatype 返回的数据类型 json
xml
json/xml 可选,默认为json格式
通用返回结果
参数名 参数说明 备注
ApiName 接口代码
ErrorCode 返回0或1,0代表无错误,1代表错误,代码不为0时注意查看ErrorReason
ErrorReason 请求失败原因,“no” 代表无错误,正常返回数据
本接口返回的数据( Result )
参数名 参数说明 备注
Date 当天日期 05月21日(星期一)
UpdateTime 数据更新时间 如:16:00
City ch 城市名称(中文) 如:深圳
en 城市名称(英文) 如:shenzhen
code 城市代码 如:101280601
Weathernow
(实时天气)
Temp Sheshi 实时气温-摄氏温度 如:29℃
Huashi 实时气温-华氏温度 如:84℉
Wet 实时相对湿度 如:70%
Weather 实时天气情况(点击查看常见天气列表) 如:晴/雨/多云等(点击查看常见天气列表)
QiYa 实时大气压 如:1001百帕
Rain last24h 过去24小时的降雨量
now 本小时降雨量
Warning 天气预警 如:广东省**县气象台于**发布广东省**县暴雨黄色预警信号,请注意防御。(预警信息来源:国家预警信息发布中心),若为null 则提示无预警
Warning_brief 天气预警精简 如:广东省**县发布暴雨黄色预警,若为null 则提示无预警
Warning_only 预警内容 如:暴雨黄色预警,若为null 则提示无预警
Wind Direction 实时风向 如:西南风
Level 实时风级 如:2级
Speed 实时风速 如:12km/h
Weather24h
(未来24小时天气)
date_20180101
(日期以当天为准)
MaxTemp 当天最高气温
MinTemp 当天最低气温
hour_02 Time 具体时间时间点 如:21日20时
Weather 该时间点的具体天气(点击查看常见天气列表) 如:晴(点击查看常见天气列表)
Temp 该时间点的具体气温(摄氏度) 如:34℃
WindDirection 该时间点的风向 如:东南方
WindLevel 该时间点的风力等级 如:2-3级
hour_05 Time 同上
Weather 同上
Temp 同上
WindDirection 同上
WindLevel 同上
hour_08 Time 同上
Weather 同上
Temp 同上
WindDirection 同上
WindLevel 同上
hour_... ... ...
... ...
... ...
... ...
... ...
  • PHP
  • ASP.NET
  • Python
  • JAVA
  • 极简方式

<?php
	header('Content-Type:text/html;charset=utf-8');
	date_default_timezone_set('PRC');
	class apidemo
	{
		public $apipath='api.djapi.cn/rtweather/get';
		public $params;
		public function __construct($params){
			$this->params=http_build_query($params); 
			return $this->get();
		}

		public function get($post_array)
		{
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $this->apipath);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $this->params);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			$result = curl_exec($ch);
			curl_close($ch);
			return $result;
		}
	}

	$post_array = array(
	    'citycode' => '101280601'
	    'cityname_ch' => '深圳'
	    'cityname_py' => 'shenzhen'
	    'ip' => '192.168.1.1'
	    'jwd' => '114.064632|22.555933'
	    'cn_to_unicode' => '1'
	    'token' => 'XXXXXX'
	    'datatype' => 'json'
	    
	);
	$result=new apidemo($post_array);
	echo '数据返回如下:'.PHP_EOL;
	var_dump($result);

	
//点睛数据:实时天气预报,使用ASP.NET方式调用接口简单示例
using System;
using System.Collections.Generic;
using System.Net.Http;
namespace apidemo
{
    public partial class djapi
    {
        public static string apipath = "http://api.djapi.cn";
        public static string get(string citycode,string cityname_ch,string cityname_py,string ip,string jwd,string cn_to_unicode,string token,string datatype)
        {
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(apipath);
			var content = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("citycode", citycode), new KeyValuePair<string, string>("cityname_ch", cityname_ch), new KeyValuePair<string, string>("cityname_py", cityname_py), new KeyValuePair<string, string>("ip", ip), new KeyValuePair<string, string>("jwd", jwd), new KeyValuePair<string, string>("cn_to_unicode", cn_to_unicode), new KeyValuePair<string, string>("token", token), new KeyValuePair<string, string>("datatype", datatype) });
            var result = client.PostAsync("/rtweather/get", content).Result;
            string resultContent = result.Content.ReadAsStringAsync().Result;
            return resultContent;
        }

    }
    public class test{
	public static string citycode = "101280601";
	public static string cityname_ch = "深圳";
	public static string cityname_py = "shenzhen";
	public static string ip = "192.168.1.1";
	public static string jwd = "114.064632|22.555933";
	public static string cn_to_unicode = "1";
	public static string token = "XXXXXX";
	public static string datatype = "json";
	
        static void Main(string[] args)
        {
            string res = djapi.get(citycode, cityname_ch, cityname_py, ip, jwd, cn_to_unicode, token, datatype);
            Console.WriteLine(res);
            Console.Read();
        }
    }
}




#点睛数据:实时天气预报,使用Python方式调用接口简单示例
import http.client,urllib.parse
class apidemo:
    apipath="api.djapi.cn"
    apiuri="/rtweather/get";
    def get(self,paramslist):
        params = urllib.parse.urlencode(paramslist)
        headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
        conn = http.client.HTTPConnection(self.apipath)
        conn.request('POST', self.apiuri, params, headers)
        response = conn.getresponse()
        return  response.read()
citycode = "101280601"
cityname_ch = "深圳"
cityname_py = "shenzhen"
ip = "192.168.1.1"
jwd = "114.064632|22.555933"
cn_to_unicode = "1"
token = "XXXXXX"
datatype = "json"

data = apidemo.get(apidemo,{"citycode" = citycode,"cityname_ch" = cityname_ch,"cityname_py" = cityname_py,"ip" = ip,"jwd" = jwd,"cn_to_unicode" = cn_to_unicode,"token" = token,"datatype" = datatype})
print(data)




/**
 *点睛数据:实时天气预报,使用JAVA方式调用接口简单示例
 * @author 点睛数据
 *          djapi.cn
 */
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class apidemo {
	public static final String citycode = "101280601";
	public static final String cityname_ch = "深圳";
	public static final String cityname_py = "shenzhen";
	public static final String ip = "192.168.1.1";
	public static final String jwd = "114.064632|22.555933";
	public static final String cn_to_unicode = "1";
	public static final String token = "XXXXXX";
	public static final String datatype = "json";
	
    public static void main(String[] args) {

        try {
            URL url = new URL("http://api.djapi.cn/ipaddr/get");
            HttpURLConnection connect = (HttpURLConnection)url.openConnection();
            connect.addRequestProperty("encoding","UTF-8");
            connect.setDoInput(true);
            connect.setDoOutput(true);
            connect.setRequestMethod("GET");//POST or GET
            OutputStream output = connect.getOutputStream();
            OutputStreamWriter outputstreamreader = new OutputStreamWriter(output);
            BufferedWriter writer = new BufferedWriter(outputstreamreader);

            // 发送 请求
            String params="&citycode="+citycode+"&cityname_ch="+cityname_ch+"&cityname_py="+cityname_py+"&ip="+ip+"&jwd="+jwd+"&cn_to_unicode="+cn_to_unicode+"&token="+token+"datatype="+datatype;
            writer.write(params);
            // 强制清空缓冲区 输出数据
            writer.flush();

            // 设置好 输入流 -- 因为 只有发送数据之后才会有接收数据
            InputStream inputstream = connect.getInputStream();
            InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
            BufferedReader bufferreader = new BufferedReader(inputstreamreader);

            // 上述步骤将数据封装好之后 即可将数据读取出来了
            String outputstring;
            StringBuilder strbuilder = new StringBuilder();
            while((outputstring=bufferreader.readLine())!= null){
                    strbuilder.append(outputstring);
            }

            writer.close();
            bufferreader.close();
            output.close();
            outputstreamreader.close();
            inputstream.close();
            inputstreamreader.close();

            System.out.println(strbuilder);

        } catch (MalformedURLException e) {
                e.printStackTrace();
        } catch (IOException e) {
                e.printStackTrace();
        }
    }
}
	
//点睛数据:实时天气预报,使用极简方式调用接口示例
//直接使用浏览器直接打开如下链接:
api.djapi.cn/rtweather/get?citycode=101280601&cityname_ch=深圳&cityname_py=shenzhen&ip=192.168.1.1&jwd=114.064632|22.555933&cn_to_unicode=1&token=XXXXXX&datatype=json
//结果直接在浏览器中输出
	
								
返回结果示例(JSON格式)
示例0


点睛数据
https://djapi.cn

© 2017-2022 深圳市点睛网络有限公司 版权所有   粤ICP备15037691号-2 粤公网安备-44030502001414号