国控空气质量省级批量接口

按省份来下载该省所有城市,所有站点的实时报,包括时报和日报数据。适用于只研究某个省的空气质量的情况。

使用期限

价格

1
用户评价: 暂无评价

购买人数:0

规格与周期

1.00元/700次”,“一年

联系电话

服务保障

精选优质服务商
7*8小时在线客服
专业测试保证品质
退款售后无忧
API文档

站点日报

调用地址:https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release/api/v1/nation_air_by_province/station_day_list

请求方式:GET

返回类型:JSON

API调用: API调用说明(secret_id & secret_key)

去调试

请求参数(Headers)

名称
类型
是否必须
描述
暂无数据

请求参数(Qurey)

名称
类型
是否必须
描述
province
string
省份名称

请求参数(Body)

名称
类型
是否必须
描述
暂无数据

请求示例

import urllib2, ssl, datetime, hmac, base64, hashlib

host = 'service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com'
url = 'https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release'
path = '/api/v1/nation_air_by_province/station_day_list'
source = 'source'
method ='GET'
querys = "province=";
GMT_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'

#云市场分配的密钥Id
SecretId='xxx'
#云市场分配的密钥Key
SecretKey='xxx'
dateTime = datetime.datetime.utcnow().strftime(GMT_FORMAT)
auth = "hmac id=\"" + SecretId + "\", algorithm=\"hmac-sha1\", headers=\"date source\", signature=\""
signStr = "date: " + dateTime + "\n" + "source: " + source
sign = hmac.new(SecretKey, signStr, hashlib.sha1).digest()
sign = base64.b64encode(sign)
sign = auth + sign + "\""

url = url + path + '?' + querys
request = urllib2.Request(url)

request.add_header('Authorization', sign)
request.add_header('Host', host)
request.add_header('Source', 'source')
request.add_header('Date', dateTime)
request.add_header('X-Requested-With', 'XMLHttpRequest')
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)
curl -v -X GET https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release/api/v1/nation_air_by_province/station_day_list ?province=-H 'Host:service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com' -H 'Source:source' -H 'Date:Mon, 19 Mar 2018 12:08:40 GMT' -H 'Authorization:hmac id = "AKIDi6qE41WgJ9w8h4h9zq68Vq24d1beIuN0qIwU", algorithm = "hmac-sha1", headers = "date source", signature = yMCxXNytW5nvVGNZ8aBtRxmiLJ4=' -H 'X-Requested-With:XMLHttpRequest' 
//请用云市场分配给您的密钥计算签名并放入请求头,Date为当前的GMT时间
<?php
$host = 'service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com';
$url = 'https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release';
$path = '/api/v1/nation_air_by_province/station_day_list';
$method = 'GET';
$source = 'source';

#云市场分配的密钥Id
$SecretId = 'xxx';
#云市场分配的密钥Key
$SecretKey = 'xxx';
$dateTime = gmdate('D, d M Y H:i:s T');
$auth = 'hmac id="' . $SecretId . '", algorithm="hmac-sha1", headers="date source", signature="';
$signStr = 'date: ' . $dateTime . "\n" . 'source: ' . $source;
$sign = base64_encode(hash_hmac('sha1', $signStr, $SecretKey, true));
$sign = $auth . $sign . '"';

$querys = "province=";
$url = $url . $path . "?" . $querys;

$headers = array(
    "Host: $host",
    'Accept: text/html, */*; q=0.01',
    "Source: $source",
    "Date: $dateTime",
    "Authorization: $sign",
    'X-Requested-With: XMLHttpRequest',
    'Accept-Encoding: gzip, deflate, sdch'
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
$data = curl_exec($ch);
if (curl_errno($ch)) {
    echo "Error: " . curl_error($ch);
} else {
    // Show me the result
    var_dump($data);
    curl_close($ch);
}
using System.IO;
using System.Text;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System;

public class CsharpTest
{
    public static String HMACSHA1Text(String EncryptText, String EncryptKey)
    {
            HMACSHA1 hmacsha1 = new HMACSHA1();
            hmacsha1.Key = System.Text.Encoding.UTF8.GetBytes(EncryptKey);

            byte[] dataBuffer = System.Text.Encoding.UTF8.GetBytes(EncryptText);
            byte[] hashBytes = hmacsha1.ComputeHash(dataBuffer);
            return Convert.ToBase64String(hashBytes);
    }

    public static void Main(String[] args)
    {
        String url = "https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release";
        String host = "service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com";
        String path = "/api/v1/nation_air_by_province/station_day_list";
        String method = "GET";
        String querys = "province=";
        String source = "source";

        //云市场分配的密钥Id
        String  secretId = "xxx";
        //云市场分配的密钥Key
        String  secretKey = "xxx";

        String dt = DateTime.UtcNow.GetDateTimeFormats('r')[0]; //Mon, 19 Mar 2018 12:00:44 GMT
        url = url + path + "?" + querys;

        String signStr = "x-date: " + dt + "\n" + "source: " + source;
        String sign = HMACSHA1Text(signStr, secretKey);

        String auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date source\", signature=\"";
        auth = auth + sign + "\"";
        Console.WriteLine(auth + "\n");

        HttpWebRequest httpRequest = null;
        HttpWebResponse httpResponse = null;

        if (url.Contains("https://"))
        {
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
        }
        else
        {
            httpRequest = (HttpWebRequest)WebRequest.Create(url);
        }

        httpRequest.Method = method;
        httpRequest.Headers.Add("Authorization", auth);
        httpRequest.Headers.Add("Source", source);
        httpRequest.Headers.Add("X-date", dt);

        try
        {
            httpResponse = (HttpWebResponse)httpRequest.GetResponse();
        }
        catch (WebException ex)
        {
            httpResponse = (HttpWebResponse)ex.Response;
        }

        Console.WriteLine(httpResponse.StatusCode);
        Console.WriteLine(httpResponse.Headers);
        Stream st = httpResponse.GetResponseStream();
        StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
        Console.WriteLine(reader.ReadToEnd());
        Console.WriteLine("\n");

    }

    public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
    {
        return true;
    }
}
package main

import (
    "time"
    "fmt"
    "crypto/hmac"
    "crypto/sha1"
    "io"
    "io/ioutil"
    "encoding/base64"
    "net/http"
)


func calcAuthorization(source string, secretId string, secretKey string) (sign string, dateTime string, err error) {
    timeLocation, _ := time.LoadLocation("Etc/GMT")
    dateTime = time.Now().In(timeLocation).Format("Mon, 02 Jan 2006 15:04:05 GMT")
    sign = fmt.Sprintf("x-date: %s\nsource: %s", dateTime, source)
    fmt.Println(sign)

    //hmac-sha1
    h := hmac.New(sha1.New, []byte(secretKey))
    io.WriteString(h, sign)
    sign = fmt.Sprintf("%x", h.Sum(nil))
    sign = string(h.Sum(nil))
    fmt.Println("sign:", fmt.Sprintf("%s", h.Sum(nil)))

    //base64
    sign = base64.StdEncoding.EncodeToString([]byte(sign))
    fmt.Println("sign:", sign)

    auth := fmt.Sprintf("hmac id=\"%s\", algorithm=\"hmac-sha1\", headers=\"x-date source\", signature=\"%s\"",
        secretId, sign)
    fmt.Println("auth:", auth)

    return auth, dateTime, nil
}

func main () {

    //云市场分配的密钥Id
    SecretId := "xxx"
    //云市场分配的密钥Key
    SecretKey := "xxx"
    source := "source"

    sign, dateTime, err := calcAuthorization(source, SecretId, SecretKey)
    if err != nil {
        fmt.Println(err)
        return
    }

    defaultDomain := "service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com"
    path := "/api/v1/nation_air_by_province/station_day_list"
    query := "province="
    url := "https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release"
    reqUrl := url + path + "?" + query
    client := &http.Client{
        Timeout: 7 * time.Second,//set timeout
    }

    req, err := http.NewRequest("GET", reqUrl, nil) //set body
    if err != nil {
        fmt.Println(err)
        return
    }

    req.Header.Set("Accept", "*/*")
    req.Header.Set("Accept-Charset", "utf-8;")
    req.Header.Set("Host", defaultDomain)
    req.Header.Set("Source", source)
    req.Header.Set("X-Date", dateTime)
    req.Header.Set("Authorization", sign)

    resp, err := client.Do(req)
    if err != nil {
        fmt.Println(err)
        return
    }
    defer resp.Body.Close()

    fmt.Println("status code:", resp.StatusCode)

    //get resp header
    var headerMsg string
    for key, _ := range resp.Header {
        headerMsg += fmt.Sprintf("\n%s:%s", key, resp.Header.Get(key))
    }
    fmt.Println(headerMsg)

    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        fmt.Println(err)
        return
    }

    fmt.Println(string(body))
}
import java.io.*;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.HttpURLConnection;
import sun.misc.BASE64Encoder;

class test
{
    public static String sign(String secret, String timeStr)
        throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
        //get signStr
        String signStr = "date: " + timeStr + "\n" + "source: " + "source";
        //get sig
        String sig = null;
        Mac mac1 = Mac.getInstance("HmacSHA1");
        byte[] hash;
        SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes("UTF-8"), mac1.getAlgorithm());
        mac1.init(secretKey);
        hash = mac1.doFinal(signStr.getBytes("UTF-8"));
        sig = new BASE64Encoder().encode(hash);
        System.out.println("signValue--->" + sig);
        return sig;
    }

    public static void main(String[] args) {
        String result = "";
        BufferedReader in = null;

        //get current GMT time
        Calendar cd = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
        String timeStr = sdf.format(cd.getTime());

        String host = "service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com";
        String path = "/api/v1/nation_air_by_province/station_day_list";
        String query = "province=";
        String url = "https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release";
        url = url + path + "?" + query;
        String source = "source";


        //云市场分配的密钥Id
        String secretId = "xxx";
        //云市场分配的密钥Key
        String secretKey = "xxx";

        try {
            String urlNameString = url;
            URL realUrl = new URL(urlNameString);
            // 打开和URL之间的连接
            URLConnection connection = realUrl.openConnection();
            HttpURLConnection httpUrlCon = (HttpURLConnection)connection;
            // 设置通用的请求属性
            httpUrlCon.setRequestProperty("Host", host);
            httpUrlCon.setRequestProperty("Accept", "text/html, */*; q=0.01");
            httpUrlCon.setRequestProperty("Source", source );
            httpUrlCon.setRequestProperty("Date", timeStr);
            String sig = sign(secretKey,timeStr);
            String authen = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"date source\", signature=\"" + sig + "\"";
            System.out.println("authen --->" + authen);
            httpUrlCon.setRequestProperty("Authorization", authen);
            httpUrlCon.setRequestProperty("X-Requested-With", "XMLHttpRequest");
            httpUrlCon.setRequestProperty("Accept-Encoding", "gzip, deflate, sdch");
            // 建立实际的连接
            httpUrlCon.connect();
            // 获取所有响应头字段
            Map<String, List<String>> map = httpUrlCon.getHeaderFields();
            // 遍历所有的响应头字段
            for (String key : map.keySet()) {
                System.out.println(key + "--->" + map.get(key));
            }
            // 定义 BufferedReader输入流来读取URL的响应
            in = new BufferedReader(new InputStreamReader(
            httpUrlCon.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }

            System.out.println(result);

        } catch (Exception e) {
            System.out.println("发送GET请求出现异常!" + e);
            e.printStackTrace();
        }
        // 使用finally块来关闭输入流
        finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
}
/**
 * npm install crypto-js axios
 */
var CryptoJS = require("crypto-js");
var axios = require('axios');

var nowDate = new Date();
var dateTime = nowDate.toGMTString();

var host = "service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com";
var path = "/api/v1/nation_air_by_province/station_day_list";
var query = "province=";
var url = "https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release";
url = url + path + "?" + query;
var source = "source";

//云市场分配的密钥Id
var secretId = "xxx";
//云市场分配的密钥Key
var secretKey = "xxx";

var auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date source\", signature=\"";
var signStr = "x-date: " + dateTime + "\n" + "source: " + source;
var sign = CryptoJS.HmacSHA1(signStr, secretKey)
console.log(sign.toString())
sign = CryptoJS.enc.Base64.stringify(sign)
sign = auth + sign + "\""
console.log(sign)

var instance = axios.create({
    baseURL: url,
    timeout: 5000,
    headers: {
        "Source": source,
        "X-date": dateTime,
        "Authorization": sign
    },
    withCredentials: true
});


instance.get()
    .then(function (response) {
        console.log(response);
    })
    .catch(function (error) {
        console.log(error);
    });

正常返回示例

{
success: true,
data: [
[
{
province: "山东省",
city: "德州市",
o3_24h: 112,
station_code: "1622A",
co_24h: 1.683,
no2_24h: 59,
station: "儿童乐园",
so2_24h: 33,
pubtime: "2017-03-13 00:00:00",
pm2_5_24h: 61,
o3_8h_24h: 83,
pm10_24h: 120,
city_code: "371400"
},
...
]
]
}

返回码定义

返回码
返回信息
描述
无参数

站点时报

调用地址:https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release/api/v1/nation_air_by_province/station_realtime_list

请求方式:GET

返回类型:JSON

API调用: API调用说明(secret_id & secret_key)

去调试

请求参数(Headers)

名称
类型
是否必须
描述
暂无数据

请求参数(Qurey)

名称
类型
是否必须
描述
province
string
省份名称

请求参数(Body)

名称
类型
是否必须
描述
暂无数据

请求示例

import urllib2, ssl, datetime, hmac, base64, hashlib

host = 'service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com'
url = 'https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release'
path = '/api/v1/nation_air_by_province/station_realtime_list'
source = 'source'
method ='GET'
querys = "province=";
GMT_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'

#云市场分配的密钥Id
SecretId='xxx'
#云市场分配的密钥Key
SecretKey='xxx'
dateTime = datetime.datetime.utcnow().strftime(GMT_FORMAT)
auth = "hmac id=\"" + SecretId + "\", algorithm=\"hmac-sha1\", headers=\"date source\", signature=\""
signStr = "date: " + dateTime + "\n" + "source: " + source
sign = hmac.new(SecretKey, signStr, hashlib.sha1).digest()
sign = base64.b64encode(sign)
sign = auth + sign + "\""

url = url + path + '?' + querys
request = urllib2.Request(url)

request.add_header('Authorization', sign)
request.add_header('Host', host)
request.add_header('Source', 'source')
request.add_header('Date', dateTime)
request.add_header('X-Requested-With', 'XMLHttpRequest')
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)
curl -v -X GET https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release/api/v1/nation_air_by_province/station_realtime_list ?province=-H 'Host:service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com' -H 'Source:source' -H 'Date:Mon, 19 Mar 2018 12:08:40 GMT' -H 'Authorization:hmac id = "AKIDi6qE41WgJ9w8h4h9zq68Vq24d1beIuN0qIwU", algorithm = "hmac-sha1", headers = "date source", signature = yMCxXNytW5nvVGNZ8aBtRxmiLJ4=' -H 'X-Requested-With:XMLHttpRequest' 
//请用云市场分配给您的密钥计算签名并放入请求头,Date为当前的GMT时间
<?php
$host = 'service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com';
$url = 'https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release';
$path = '/api/v1/nation_air_by_province/station_realtime_list';
$method = 'GET';
$source = 'source';

#云市场分配的密钥Id
$SecretId = 'xxx';
#云市场分配的密钥Key
$SecretKey = 'xxx';
$dateTime = gmdate('D, d M Y H:i:s T');
$auth = 'hmac id="' . $SecretId . '", algorithm="hmac-sha1", headers="date source", signature="';
$signStr = 'date: ' . $dateTime . "\n" . 'source: ' . $source;
$sign = base64_encode(hash_hmac('sha1', $signStr, $SecretKey, true));
$sign = $auth . $sign . '"';

$querys = "province=";
$url = $url . $path . "?" . $querys;

$headers = array(
    "Host: $host",
    'Accept: text/html, */*; q=0.01',
    "Source: $source",
    "Date: $dateTime",
    "Authorization: $sign",
    'X-Requested-With: XMLHttpRequest',
    'Accept-Encoding: gzip, deflate, sdch'
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
$data = curl_exec($ch);
if (curl_errno($ch)) {
    echo "Error: " . curl_error($ch);
} else {
    // Show me the result
    var_dump($data);
    curl_close($ch);
}
using System.IO;
using System.Text;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System;

public class CsharpTest
{
    public static String HMACSHA1Text(String EncryptText, String EncryptKey)
    {
            HMACSHA1 hmacsha1 = new HMACSHA1();
            hmacsha1.Key = System.Text.Encoding.UTF8.GetBytes(EncryptKey);

            byte[] dataBuffer = System.Text.Encoding.UTF8.GetBytes(EncryptText);
            byte[] hashBytes = hmacsha1.ComputeHash(dataBuffer);
            return Convert.ToBase64String(hashBytes);
    }

    public static void Main(String[] args)
    {
        String url = "https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release";
        String host = "service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com";
        String path = "/api/v1/nation_air_by_province/station_realtime_list";
        String method = "GET";
        String querys = "province=";
        String source = "source";

        //云市场分配的密钥Id
        String  secretId = "xxx";
        //云市场分配的密钥Key
        String  secretKey = "xxx";

        String dt = DateTime.UtcNow.GetDateTimeFormats('r')[0]; //Mon, 19 Mar 2018 12:00:44 GMT
        url = url + path + "?" + querys;

        String signStr = "x-date: " + dt + "\n" + "source: " + source;
        String sign = HMACSHA1Text(signStr, secretKey);

        String auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date source\", signature=\"";
        auth = auth + sign + "\"";
        Console.WriteLine(auth + "\n");

        HttpWebRequest httpRequest = null;
        HttpWebResponse httpResponse = null;

        if (url.Contains("https://"))
        {
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
        }
        else
        {
            httpRequest = (HttpWebRequest)WebRequest.Create(url);
        }

        httpRequest.Method = method;
        httpRequest.Headers.Add("Authorization", auth);
        httpRequest.Headers.Add("Source", source);
        httpRequest.Headers.Add("X-date", dt);

        try
        {
            httpResponse = (HttpWebResponse)httpRequest.GetResponse();
        }
        catch (WebException ex)
        {
            httpResponse = (HttpWebResponse)ex.Response;
        }

        Console.WriteLine(httpResponse.StatusCode);
        Console.WriteLine(httpResponse.Headers);
        Stream st = httpResponse.GetResponseStream();
        StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
        Console.WriteLine(reader.ReadToEnd());
        Console.WriteLine("\n");

    }

    public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
    {
        return true;
    }
}
package main

import (
    "time"
    "fmt"
    "crypto/hmac"
    "crypto/sha1"
    "io"
    "io/ioutil"
    "encoding/base64"
    "net/http"
)


func calcAuthorization(source string, secretId string, secretKey string) (sign string, dateTime string, err error) {
    timeLocation, _ := time.LoadLocation("Etc/GMT")
    dateTime = time.Now().In(timeLocation).Format("Mon, 02 Jan 2006 15:04:05 GMT")
    sign = fmt.Sprintf("x-date: %s\nsource: %s", dateTime, source)
    fmt.Println(sign)

    //hmac-sha1
    h := hmac.New(sha1.New, []byte(secretKey))
    io.WriteString(h, sign)
    sign = fmt.Sprintf("%x", h.Sum(nil))
    sign = string(h.Sum(nil))
    fmt.Println("sign:", fmt.Sprintf("%s", h.Sum(nil)))

    //base64
    sign = base64.StdEncoding.EncodeToString([]byte(sign))
    fmt.Println("sign:", sign)

    auth := fmt.Sprintf("hmac id=\"%s\", algorithm=\"hmac-sha1\", headers=\"x-date source\", signature=\"%s\"",
        secretId, sign)
    fmt.Println("auth:", auth)

    return auth, dateTime, nil
}

func main () {

    //云市场分配的密钥Id
    SecretId := "xxx"
    //云市场分配的密钥Key
    SecretKey := "xxx"
    source := "source"

    sign, dateTime, err := calcAuthorization(source, SecretId, SecretKey)
    if err != nil {
        fmt.Println(err)
        return
    }

    defaultDomain := "service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com"
    path := "/api/v1/nation_air_by_province/station_realtime_list"
    query := "province="
    url := "https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release"
    reqUrl := url + path + "?" + query
    client := &http.Client{
        Timeout: 7 * time.Second,//set timeout
    }

    req, err := http.NewRequest("GET", reqUrl, nil) //set body
    if err != nil {
        fmt.Println(err)
        return
    }

    req.Header.Set("Accept", "*/*")
    req.Header.Set("Accept-Charset", "utf-8;")
    req.Header.Set("Host", defaultDomain)
    req.Header.Set("Source", source)
    req.Header.Set("X-Date", dateTime)
    req.Header.Set("Authorization", sign)

    resp, err := client.Do(req)
    if err != nil {
        fmt.Println(err)
        return
    }
    defer resp.Body.Close()

    fmt.Println("status code:", resp.StatusCode)

    //get resp header
    var headerMsg string
    for key, _ := range resp.Header {
        headerMsg += fmt.Sprintf("\n%s:%s", key, resp.Header.Get(key))
    }
    fmt.Println(headerMsg)

    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        fmt.Println(err)
        return
    }

    fmt.Println(string(body))
}
import java.io.*;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.HttpURLConnection;
import sun.misc.BASE64Encoder;

class test
{
    public static String sign(String secret, String timeStr)
        throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
        //get signStr
        String signStr = "date: " + timeStr + "\n" + "source: " + "source";
        //get sig
        String sig = null;
        Mac mac1 = Mac.getInstance("HmacSHA1");
        byte[] hash;
        SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes("UTF-8"), mac1.getAlgorithm());
        mac1.init(secretKey);
        hash = mac1.doFinal(signStr.getBytes("UTF-8"));
        sig = new BASE64Encoder().encode(hash);
        System.out.println("signValue--->" + sig);
        return sig;
    }

    public static void main(String[] args) {
        String result = "";
        BufferedReader in = null;

        //get current GMT time
        Calendar cd = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
        String timeStr = sdf.format(cd.getTime());

        String host = "service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com";
        String path = "/api/v1/nation_air_by_province/station_realtime_list";
        String query = "province=";
        String url = "https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release";
        url = url + path + "?" + query;
        String source = "source";


        //云市场分配的密钥Id
        String secretId = "xxx";
        //云市场分配的密钥Key
        String secretKey = "xxx";

        try {
            String urlNameString = url;
            URL realUrl = new URL(urlNameString);
            // 打开和URL之间的连接
            URLConnection connection = realUrl.openConnection();
            HttpURLConnection httpUrlCon = (HttpURLConnection)connection;
            // 设置通用的请求属性
            httpUrlCon.setRequestProperty("Host", host);
            httpUrlCon.setRequestProperty("Accept", "text/html, */*; q=0.01");
            httpUrlCon.setRequestProperty("Source", source );
            httpUrlCon.setRequestProperty("Date", timeStr);
            String sig = sign(secretKey,timeStr);
            String authen = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"date source\", signature=\"" + sig + "\"";
            System.out.println("authen --->" + authen);
            httpUrlCon.setRequestProperty("Authorization", authen);
            httpUrlCon.setRequestProperty("X-Requested-With", "XMLHttpRequest");
            httpUrlCon.setRequestProperty("Accept-Encoding", "gzip, deflate, sdch");
            // 建立实际的连接
            httpUrlCon.connect();
            // 获取所有响应头字段
            Map<String, List<String>> map = httpUrlCon.getHeaderFields();
            // 遍历所有的响应头字段
            for (String key : map.keySet()) {
                System.out.println(key + "--->" + map.get(key));
            }
            // 定义 BufferedReader输入流来读取URL的响应
            in = new BufferedReader(new InputStreamReader(
            httpUrlCon.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }

            System.out.println(result);

        } catch (Exception e) {
            System.out.println("发送GET请求出现异常!" + e);
            e.printStackTrace();
        }
        // 使用finally块来关闭输入流
        finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
}
/**
 * npm install crypto-js axios
 */
var CryptoJS = require("crypto-js");
var axios = require('axios');

var nowDate = new Date();
var dateTime = nowDate.toGMTString();

var host = "service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com";
var path = "/api/v1/nation_air_by_province/station_realtime_list";
var query = "province=";
var url = "https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release";
url = url + path + "?" + query;
var source = "source";

//云市场分配的密钥Id
var secretId = "xxx";
//云市场分配的密钥Key
var secretKey = "xxx";

var auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date source\", signature=\"";
var signStr = "x-date: " + dateTime + "\n" + "source: " + source;
var sign = CryptoJS.HmacSHA1(signStr, secretKey)
console.log(sign.toString())
sign = CryptoJS.enc.Base64.stringify(sign)
sign = auth + sign + "\""
console.log(sign)

var instance = axios.create({
    baseURL: url,
    timeout: 5000,
    headers: {
        "Source": source,
        "X-date": dateTime,
        "Authorization": sign
    },
    withCredentials: true
});


instance.get()
    .then(function (response) {
        console.log(response);
    })
    .catch(function (error) {
        console.log(error);
    });

正常返回示例

{
success: true,
data: [
[
{
pm2_5: 96,
co: 1.6,
o3_24h: 159,
pollutions: "细颗粒物(PM2.5)",
quality: "轻度污染",
pm10_24h: 127,
no2: 28,
city: "德州市",
district: "",
o3_8h: 56,
station_code: "1624A",
station: "监理站",
so2_24h: 25,
pm2_5_24h: 87,
latitude: 37.4489,
o3: 85,
city_code: "371400",
province: "山东省",
co_24h: 1.5,
so2: 33,
aqi: 127,
pm10: 142,
level: "",
longitude: 116.3189,
o3_8h_24h: 56,
no2_24h: 33,
pubtime: "2017-03-30 13:00:00"
},
...
]
]
}

返回码定义

返回码
返回信息
描述
无参数

城市时报

调用地址:https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release/api/v1/nation_air_by_province/city_realtime_list

请求方式:GET

返回类型:JSON

API调用: API调用说明(secret_id & secret_key)

去调试

请求参数(Headers)

名称
类型
是否必须
描述
暂无数据

请求参数(Qurey)

名称
类型
是否必须
描述
province
string
省份名称

请求参数(Body)

名称
类型
是否必须
描述
暂无数据

请求示例

import urllib2, ssl, datetime, hmac, base64, hashlib

host = 'service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com'
url = 'https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release'
path = '/api/v1/nation_air_by_province/city_realtime_list'
source = 'source'
method ='GET'
querys = "province=";
GMT_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'

#云市场分配的密钥Id
SecretId='xxx'
#云市场分配的密钥Key
SecretKey='xxx'
dateTime = datetime.datetime.utcnow().strftime(GMT_FORMAT)
auth = "hmac id=\"" + SecretId + "\", algorithm=\"hmac-sha1\", headers=\"date source\", signature=\""
signStr = "date: " + dateTime + "\n" + "source: " + source
sign = hmac.new(SecretKey, signStr, hashlib.sha1).digest()
sign = base64.b64encode(sign)
sign = auth + sign + "\""

url = url + path + '?' + querys
request = urllib2.Request(url)

request.add_header('Authorization', sign)
request.add_header('Host', host)
request.add_header('Source', 'source')
request.add_header('Date', dateTime)
request.add_header('X-Requested-With', 'XMLHttpRequest')
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)
curl -v -X GET https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release/api/v1/nation_air_by_province/city_realtime_list ?province=-H 'Host:service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com' -H 'Source:source' -H 'Date:Mon, 19 Mar 2018 12:08:40 GMT' -H 'Authorization:hmac id = "AKIDi6qE41WgJ9w8h4h9zq68Vq24d1beIuN0qIwU", algorithm = "hmac-sha1", headers = "date source", signature = yMCxXNytW5nvVGNZ8aBtRxmiLJ4=' -H 'X-Requested-With:XMLHttpRequest' 
//请用云市场分配给您的密钥计算签名并放入请求头,Date为当前的GMT时间
<?php
$host = 'service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com';
$url = 'https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release';
$path = '/api/v1/nation_air_by_province/city_realtime_list';
$method = 'GET';
$source = 'source';

#云市场分配的密钥Id
$SecretId = 'xxx';
#云市场分配的密钥Key
$SecretKey = 'xxx';
$dateTime = gmdate('D, d M Y H:i:s T');
$auth = 'hmac id="' . $SecretId . '", algorithm="hmac-sha1", headers="date source", signature="';
$signStr = 'date: ' . $dateTime . "\n" . 'source: ' . $source;
$sign = base64_encode(hash_hmac('sha1', $signStr, $SecretKey, true));
$sign = $auth . $sign . '"';

$querys = "province=";
$url = $url . $path . "?" . $querys;

$headers = array(
    "Host: $host",
    'Accept: text/html, */*; q=0.01',
    "Source: $source",
    "Date: $dateTime",
    "Authorization: $sign",
    'X-Requested-With: XMLHttpRequest',
    'Accept-Encoding: gzip, deflate, sdch'
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
$data = curl_exec($ch);
if (curl_errno($ch)) {
    echo "Error: " . curl_error($ch);
} else {
    // Show me the result
    var_dump($data);
    curl_close($ch);
}
using System.IO;
using System.Text;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System;

public class CsharpTest
{
    public static String HMACSHA1Text(String EncryptText, String EncryptKey)
    {
            HMACSHA1 hmacsha1 = new HMACSHA1();
            hmacsha1.Key = System.Text.Encoding.UTF8.GetBytes(EncryptKey);

            byte[] dataBuffer = System.Text.Encoding.UTF8.GetBytes(EncryptText);
            byte[] hashBytes = hmacsha1.ComputeHash(dataBuffer);
            return Convert.ToBase64String(hashBytes);
    }

    public static void Main(String[] args)
    {
        String url = "https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release";
        String host = "service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com";
        String path = "/api/v1/nation_air_by_province/city_realtime_list";
        String method = "GET";
        String querys = "province=";
        String source = "source";

        //云市场分配的密钥Id
        String  secretId = "xxx";
        //云市场分配的密钥Key
        String  secretKey = "xxx";

        String dt = DateTime.UtcNow.GetDateTimeFormats('r')[0]; //Mon, 19 Mar 2018 12:00:44 GMT
        url = url + path + "?" + querys;

        String signStr = "x-date: " + dt + "\n" + "source: " + source;
        String sign = HMACSHA1Text(signStr, secretKey);

        String auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date source\", signature=\"";
        auth = auth + sign + "\"";
        Console.WriteLine(auth + "\n");

        HttpWebRequest httpRequest = null;
        HttpWebResponse httpResponse = null;

        if (url.Contains("https://"))
        {
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
        }
        else
        {
            httpRequest = (HttpWebRequest)WebRequest.Create(url);
        }

        httpRequest.Method = method;
        httpRequest.Headers.Add("Authorization", auth);
        httpRequest.Headers.Add("Source", source);
        httpRequest.Headers.Add("X-date", dt);

        try
        {
            httpResponse = (HttpWebResponse)httpRequest.GetResponse();
        }
        catch (WebException ex)
        {
            httpResponse = (HttpWebResponse)ex.Response;
        }

        Console.WriteLine(httpResponse.StatusCode);
        Console.WriteLine(httpResponse.Headers);
        Stream st = httpResponse.GetResponseStream();
        StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
        Console.WriteLine(reader.ReadToEnd());
        Console.WriteLine("\n");

    }

    public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
    {
        return true;
    }
}
package main

import (
    "time"
    "fmt"
    "crypto/hmac"
    "crypto/sha1"
    "io"
    "io/ioutil"
    "encoding/base64"
    "net/http"
)


func calcAuthorization(source string, secretId string, secretKey string) (sign string, dateTime string, err error) {
    timeLocation, _ := time.LoadLocation("Etc/GMT")
    dateTime = time.Now().In(timeLocation).Format("Mon, 02 Jan 2006 15:04:05 GMT")
    sign = fmt.Sprintf("x-date: %s\nsource: %s", dateTime, source)
    fmt.Println(sign)

    //hmac-sha1
    h := hmac.New(sha1.New, []byte(secretKey))
    io.WriteString(h, sign)
    sign = fmt.Sprintf("%x", h.Sum(nil))
    sign = string(h.Sum(nil))
    fmt.Println("sign:", fmt.Sprintf("%s", h.Sum(nil)))

    //base64
    sign = base64.StdEncoding.EncodeToString([]byte(sign))
    fmt.Println("sign:", sign)

    auth := fmt.Sprintf("hmac id=\"%s\", algorithm=\"hmac-sha1\", headers=\"x-date source\", signature=\"%s\"",
        secretId, sign)
    fmt.Println("auth:", auth)

    return auth, dateTime, nil
}

func main () {

    //云市场分配的密钥Id
    SecretId := "xxx"
    //云市场分配的密钥Key
    SecretKey := "xxx"
    source := "source"

    sign, dateTime, err := calcAuthorization(source, SecretId, SecretKey)
    if err != nil {
        fmt.Println(err)
        return
    }

    defaultDomain := "service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com"
    path := "/api/v1/nation_air_by_province/city_realtime_list"
    query := "province="
    url := "https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release"
    reqUrl := url + path + "?" + query
    client := &http.Client{
        Timeout: 7 * time.Second,//set timeout
    }

    req, err := http.NewRequest("GET", reqUrl, nil) //set body
    if err != nil {
        fmt.Println(err)
        return
    }

    req.Header.Set("Accept", "*/*")
    req.Header.Set("Accept-Charset", "utf-8;")
    req.Header.Set("Host", defaultDomain)
    req.Header.Set("Source", source)
    req.Header.Set("X-Date", dateTime)
    req.Header.Set("Authorization", sign)

    resp, err := client.Do(req)
    if err != nil {
        fmt.Println(err)
        return
    }
    defer resp.Body.Close()

    fmt.Println("status code:", resp.StatusCode)

    //get resp header
    var headerMsg string
    for key, _ := range resp.Header {
        headerMsg += fmt.Sprintf("\n%s:%s", key, resp.Header.Get(key))
    }
    fmt.Println(headerMsg)

    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        fmt.Println(err)
        return
    }

    fmt.Println(string(body))
}
import java.io.*;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.HttpURLConnection;
import sun.misc.BASE64Encoder;

class test
{
    public static String sign(String secret, String timeStr)
        throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
        //get signStr
        String signStr = "date: " + timeStr + "\n" + "source: " + "source";
        //get sig
        String sig = null;
        Mac mac1 = Mac.getInstance("HmacSHA1");
        byte[] hash;
        SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes("UTF-8"), mac1.getAlgorithm());
        mac1.init(secretKey);
        hash = mac1.doFinal(signStr.getBytes("UTF-8"));
        sig = new BASE64Encoder().encode(hash);
        System.out.println("signValue--->" + sig);
        return sig;
    }

    public static void main(String[] args) {
        String result = "";
        BufferedReader in = null;

        //get current GMT time
        Calendar cd = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
        String timeStr = sdf.format(cd.getTime());

        String host = "service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com";
        String path = "/api/v1/nation_air_by_province/city_realtime_list";
        String query = "province=";
        String url = "https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release";
        url = url + path + "?" + query;
        String source = "source";


        //云市场分配的密钥Id
        String secretId = "xxx";
        //云市场分配的密钥Key
        String secretKey = "xxx";

        try {
            String urlNameString = url;
            URL realUrl = new URL(urlNameString);
            // 打开和URL之间的连接
            URLConnection connection = realUrl.openConnection();
            HttpURLConnection httpUrlCon = (HttpURLConnection)connection;
            // 设置通用的请求属性
            httpUrlCon.setRequestProperty("Host", host);
            httpUrlCon.setRequestProperty("Accept", "text/html, */*; q=0.01");
            httpUrlCon.setRequestProperty("Source", source );
            httpUrlCon.setRequestProperty("Date", timeStr);
            String sig = sign(secretKey,timeStr);
            String authen = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"date source\", signature=\"" + sig + "\"";
            System.out.println("authen --->" + authen);
            httpUrlCon.setRequestProperty("Authorization", authen);
            httpUrlCon.setRequestProperty("X-Requested-With", "XMLHttpRequest");
            httpUrlCon.setRequestProperty("Accept-Encoding", "gzip, deflate, sdch");
            // 建立实际的连接
            httpUrlCon.connect();
            // 获取所有响应头字段
            Map<String, List<String>> map = httpUrlCon.getHeaderFields();
            // 遍历所有的响应头字段
            for (String key : map.keySet()) {
                System.out.println(key + "--->" + map.get(key));
            }
            // 定义 BufferedReader输入流来读取URL的响应
            in = new BufferedReader(new InputStreamReader(
            httpUrlCon.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }

            System.out.println(result);

        } catch (Exception e) {
            System.out.println("发送GET请求出现异常!" + e);
            e.printStackTrace();
        }
        // 使用finally块来关闭输入流
        finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
}
/**
 * npm install crypto-js axios
 */
var CryptoJS = require("crypto-js");
var axios = require('axios');

var nowDate = new Date();
var dateTime = nowDate.toGMTString();

var host = "service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com";
var path = "/api/v1/nation_air_by_province/city_realtime_list";
var query = "province=";
var url = "https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release";
url = url + path + "?" + query;
var source = "source";

//云市场分配的密钥Id
var secretId = "xxx";
//云市场分配的密钥Key
var secretKey = "xxx";

var auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date source\", signature=\"";
var signStr = "x-date: " + dateTime + "\n" + "source: " + source;
var sign = CryptoJS.HmacSHA1(signStr, secretKey)
console.log(sign.toString())
sign = CryptoJS.enc.Base64.stringify(sign)
sign = auth + sign + "\""
console.log(sign)

var instance = axios.create({
    baseURL: url,
    timeout: 5000,
    headers: {
        "Source": source,
        "X-date": dateTime,
        "Authorization": sign
    },
    withCredentials: true
});


instance.get()
    .then(function (response) {
        console.log(response);
    })
    .catch(function (error) {
        console.log(error);
    });

正常返回示例

{
success: true,
data: [
[
{
pm2_5: 54,
co: 0.733,
o3_24h: 156,
pollutions: "颗粒物(PM10)",
quality: "良",
pm10_24h: 124,
no2: 22,
city: "德州市",
o3_8h: 99,
so2_24h: 30,
pm2_5_24h: 67,
latitude: "",
o3: 144,
city_code: "371400",
province: "山东省",
co_24h: 0.967,
so2: 25,
aqi: 79,
pm10: 106,
level: "2",
longitude: "",
o3_8h_24h: 99,
no2_24h: 56,
pubtime: "2017-03-15 16:00:00"
}
],
...
]
]
}

返回码定义

返回码
返回信息
描述
无参数

城市日报

调用地址:https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release/api/v1/nation_air_by_province/city_day_list

请求方式:GET

返回类型:JSON

API调用: API调用说明(secret_id & secret_key)

去调试

请求参数(Headers)

名称
类型
是否必须
描述
暂无数据

请求参数(Qurey)

名称
类型
是否必须
描述
province
string
省份名称

请求参数(Body)

名称
类型
是否必须
描述
暂无数据

请求示例

import urllib2, ssl, datetime, hmac, base64, hashlib

host = 'service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com'
url = 'https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release'
path = '/api/v1/nation_air_by_province/city_day_list'
source = 'source'
method ='GET'
querys = "province=";
GMT_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'

#云市场分配的密钥Id
SecretId='xxx'
#云市场分配的密钥Key
SecretKey='xxx'
dateTime = datetime.datetime.utcnow().strftime(GMT_FORMAT)
auth = "hmac id=\"" + SecretId + "\", algorithm=\"hmac-sha1\", headers=\"date source\", signature=\""
signStr = "date: " + dateTime + "\n" + "source: " + source
sign = hmac.new(SecretKey, signStr, hashlib.sha1).digest()
sign = base64.b64encode(sign)
sign = auth + sign + "\""

url = url + path + '?' + querys
request = urllib2.Request(url)

request.add_header('Authorization', sign)
request.add_header('Host', host)
request.add_header('Source', 'source')
request.add_header('Date', dateTime)
request.add_header('X-Requested-With', 'XMLHttpRequest')
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)
curl -v -X GET https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release/api/v1/nation_air_by_province/city_day_list ?province=-H 'Host:service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com' -H 'Source:source' -H 'Date:Mon, 19 Mar 2018 12:08:40 GMT' -H 'Authorization:hmac id = "AKIDi6qE41WgJ9w8h4h9zq68Vq24d1beIuN0qIwU", algorithm = "hmac-sha1", headers = "date source", signature = yMCxXNytW5nvVGNZ8aBtRxmiLJ4=' -H 'X-Requested-With:XMLHttpRequest' 
//请用云市场分配给您的密钥计算签名并放入请求头,Date为当前的GMT时间
<?php
$host = 'service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com';
$url = 'https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release';
$path = '/api/v1/nation_air_by_province/city_day_list';
$method = 'GET';
$source = 'source';

#云市场分配的密钥Id
$SecretId = 'xxx';
#云市场分配的密钥Key
$SecretKey = 'xxx';
$dateTime = gmdate('D, d M Y H:i:s T');
$auth = 'hmac id="' . $SecretId . '", algorithm="hmac-sha1", headers="date source", signature="';
$signStr = 'date: ' . $dateTime . "\n" . 'source: ' . $source;
$sign = base64_encode(hash_hmac('sha1', $signStr, $SecretKey, true));
$sign = $auth . $sign . '"';

$querys = "province=";
$url = $url . $path . "?" . $querys;

$headers = array(
    "Host: $host",
    'Accept: text/html, */*; q=0.01',
    "Source: $source",
    "Date: $dateTime",
    "Authorization: $sign",
    'X-Requested-With: XMLHttpRequest',
    'Accept-Encoding: gzip, deflate, sdch'
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
$data = curl_exec($ch);
if (curl_errno($ch)) {
    echo "Error: " . curl_error($ch);
} else {
    // Show me the result
    var_dump($data);
    curl_close($ch);
}
using System.IO;
using System.Text;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System;

public class CsharpTest
{
    public static String HMACSHA1Text(String EncryptText, String EncryptKey)
    {
            HMACSHA1 hmacsha1 = new HMACSHA1();
            hmacsha1.Key = System.Text.Encoding.UTF8.GetBytes(EncryptKey);

            byte[] dataBuffer = System.Text.Encoding.UTF8.GetBytes(EncryptText);
            byte[] hashBytes = hmacsha1.ComputeHash(dataBuffer);
            return Convert.ToBase64String(hashBytes);
    }

    public static void Main(String[] args)
    {
        String url = "https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release";
        String host = "service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com";
        String path = "/api/v1/nation_air_by_province/city_day_list";
        String method = "GET";
        String querys = "province=";
        String source = "source";

        //云市场分配的密钥Id
        String  secretId = "xxx";
        //云市场分配的密钥Key
        String  secretKey = "xxx";

        String dt = DateTime.UtcNow.GetDateTimeFormats('r')[0]; //Mon, 19 Mar 2018 12:00:44 GMT
        url = url + path + "?" + querys;

        String signStr = "x-date: " + dt + "\n" + "source: " + source;
        String sign = HMACSHA1Text(signStr, secretKey);

        String auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date source\", signature=\"";
        auth = auth + sign + "\"";
        Console.WriteLine(auth + "\n");

        HttpWebRequest httpRequest = null;
        HttpWebResponse httpResponse = null;

        if (url.Contains("https://"))
        {
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
        }
        else
        {
            httpRequest = (HttpWebRequest)WebRequest.Create(url);
        }

        httpRequest.Method = method;
        httpRequest.Headers.Add("Authorization", auth);
        httpRequest.Headers.Add("Source", source);
        httpRequest.Headers.Add("X-date", dt);

        try
        {
            httpResponse = (HttpWebResponse)httpRequest.GetResponse();
        }
        catch (WebException ex)
        {
            httpResponse = (HttpWebResponse)ex.Response;
        }

        Console.WriteLine(httpResponse.StatusCode);
        Console.WriteLine(httpResponse.Headers);
        Stream st = httpResponse.GetResponseStream();
        StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
        Console.WriteLine(reader.ReadToEnd());
        Console.WriteLine("\n");

    }

    public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
    {
        return true;
    }
}
package main

import (
    "time"
    "fmt"
    "crypto/hmac"
    "crypto/sha1"
    "io"
    "io/ioutil"
    "encoding/base64"
    "net/http"
)


func calcAuthorization(source string, secretId string, secretKey string) (sign string, dateTime string, err error) {
    timeLocation, _ := time.LoadLocation("Etc/GMT")
    dateTime = time.Now().In(timeLocation).Format("Mon, 02 Jan 2006 15:04:05 GMT")
    sign = fmt.Sprintf("x-date: %s\nsource: %s", dateTime, source)
    fmt.Println(sign)

    //hmac-sha1
    h := hmac.New(sha1.New, []byte(secretKey))
    io.WriteString(h, sign)
    sign = fmt.Sprintf("%x", h.Sum(nil))
    sign = string(h.Sum(nil))
    fmt.Println("sign:", fmt.Sprintf("%s", h.Sum(nil)))

    //base64
    sign = base64.StdEncoding.EncodeToString([]byte(sign))
    fmt.Println("sign:", sign)

    auth := fmt.Sprintf("hmac id=\"%s\", algorithm=\"hmac-sha1\", headers=\"x-date source\", signature=\"%s\"",
        secretId, sign)
    fmt.Println("auth:", auth)

    return auth, dateTime, nil
}

func main () {

    //云市场分配的密钥Id
    SecretId := "xxx"
    //云市场分配的密钥Key
    SecretKey := "xxx"
    source := "source"

    sign, dateTime, err := calcAuthorization(source, SecretId, SecretKey)
    if err != nil {
        fmt.Println(err)
        return
    }

    defaultDomain := "service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com"
    path := "/api/v1/nation_air_by_province/city_day_list"
    query := "province="
    url := "https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release"
    reqUrl := url + path + "?" + query
    client := &http.Client{
        Timeout: 7 * time.Second,//set timeout
    }

    req, err := http.NewRequest("GET", reqUrl, nil) //set body
    if err != nil {
        fmt.Println(err)
        return
    }

    req.Header.Set("Accept", "*/*")
    req.Header.Set("Accept-Charset", "utf-8;")
    req.Header.Set("Host", defaultDomain)
    req.Header.Set("Source", source)
    req.Header.Set("X-Date", dateTime)
    req.Header.Set("Authorization", sign)

    resp, err := client.Do(req)
    if err != nil {
        fmt.Println(err)
        return
    }
    defer resp.Body.Close()

    fmt.Println("status code:", resp.StatusCode)

    //get resp header
    var headerMsg string
    for key, _ := range resp.Header {
        headerMsg += fmt.Sprintf("\n%s:%s", key, resp.Header.Get(key))
    }
    fmt.Println(headerMsg)

    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        fmt.Println(err)
        return
    }

    fmt.Println(string(body))
}
import java.io.*;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.HttpURLConnection;
import sun.misc.BASE64Encoder;

class test
{
    public static String sign(String secret, String timeStr)
        throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
        //get signStr
        String signStr = "date: " + timeStr + "\n" + "source: " + "source";
        //get sig
        String sig = null;
        Mac mac1 = Mac.getInstance("HmacSHA1");
        byte[] hash;
        SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes("UTF-8"), mac1.getAlgorithm());
        mac1.init(secretKey);
        hash = mac1.doFinal(signStr.getBytes("UTF-8"));
        sig = new BASE64Encoder().encode(hash);
        System.out.println("signValue--->" + sig);
        return sig;
    }

    public static void main(String[] args) {
        String result = "";
        BufferedReader in = null;

        //get current GMT time
        Calendar cd = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
        String timeStr = sdf.format(cd.getTime());

        String host = "service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com";
        String path = "/api/v1/nation_air_by_province/city_day_list";
        String query = "province=";
        String url = "https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release";
        url = url + path + "?" + query;
        String source = "source";


        //云市场分配的密钥Id
        String secretId = "xxx";
        //云市场分配的密钥Key
        String secretKey = "xxx";

        try {
            String urlNameString = url;
            URL realUrl = new URL(urlNameString);
            // 打开和URL之间的连接
            URLConnection connection = realUrl.openConnection();
            HttpURLConnection httpUrlCon = (HttpURLConnection)connection;
            // 设置通用的请求属性
            httpUrlCon.setRequestProperty("Host", host);
            httpUrlCon.setRequestProperty("Accept", "text/html, */*; q=0.01");
            httpUrlCon.setRequestProperty("Source", source );
            httpUrlCon.setRequestProperty("Date", timeStr);
            String sig = sign(secretKey,timeStr);
            String authen = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"date source\", signature=\"" + sig + "\"";
            System.out.println("authen --->" + authen);
            httpUrlCon.setRequestProperty("Authorization", authen);
            httpUrlCon.setRequestProperty("X-Requested-With", "XMLHttpRequest");
            httpUrlCon.setRequestProperty("Accept-Encoding", "gzip, deflate, sdch");
            // 建立实际的连接
            httpUrlCon.connect();
            // 获取所有响应头字段
            Map<String, List<String>> map = httpUrlCon.getHeaderFields();
            // 遍历所有的响应头字段
            for (String key : map.keySet()) {
                System.out.println(key + "--->" + map.get(key));
            }
            // 定义 BufferedReader输入流来读取URL的响应
            in = new BufferedReader(new InputStreamReader(
            httpUrlCon.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }

            System.out.println(result);

        } catch (Exception e) {
            System.out.println("发送GET请求出现异常!" + e);
            e.printStackTrace();
        }
        // 使用finally块来关闭输入流
        finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
}
/**
 * npm install crypto-js axios
 */
var CryptoJS = require("crypto-js");
var axios = require('axios');

var nowDate = new Date();
var dateTime = nowDate.toGMTString();

var host = "service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com";
var path = "/api/v1/nation_air_by_province/city_day_list";
var query = "province=";
var url = "https://service-krjgp4ej-1255304211.ap-shanghai.apigateway.myqcloud.com/release";
url = url + path + "?" + query;
var source = "source";

//云市场分配的密钥Id
var secretId = "xxx";
//云市场分配的密钥Key
var secretKey = "xxx";

var auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date source\", signature=\"";
var signStr = "x-date: " + dateTime + "\n" + "source: " + source;
var sign = CryptoJS.HmacSHA1(signStr, secretKey)
console.log(sign.toString())
sign = CryptoJS.enc.Base64.stringify(sign)
sign = auth + sign + "\""
console.log(sign)

var instance = axios.create({
    baseURL: url,
    timeout: 5000,
    headers: {
        "Source": source,
        "X-date": dateTime,
        "Authorization": sign
    },
    withCredentials: true
});


instance.get()
    .then(function (response) {
        console.log(response);
    })
    .catch(function (error) {
        console.log(error);
    });

正常返回示例

{
success: true,
data: [
[
{
province: "山东省",
city: "德州市",
level: "5",
o3_8h_24h: 8,
co_24h: 2.9,
no2_24h: 71,
so2_24h: 67,
pubtime: "2016-12-25 00:00:00",
pm2_5_24h: 174,
pollutions: "细颗粒物(PM2.5)",
aqi: 224,
pm10_24h: 258,
city_code: "371400"
}
],
...
]
]
}

返回码定义

返回码
返回信息
描述
无参数
产品详情

商品详情

1. 数据权威:直接从环保部空气质量实时发布系统获取,全面,及时,准确。含全国300多个地级市及全国环保模范城市的1497个监测站点。
 2. 稳定可靠: 多机采集,API侧负载均衡。
 3. 更新及时: 因为环保部发布平台时常会增减或者修改站点,青悦接口每小时实时同步,建议每次调用前先获取站点列表。 环保部实时发布平台每小时整点28~29分左右更新数据,青悦接口每小时整点35分更新数据。 
4. 经青悦核对,自环保部实时空气质量发布系统获取的经纬度最接近百度地图经纬度,可按此坐标系进行坐标偏移,具体偏移可以到gpsspg网站进行偏移计算。 
5. 如果需要批量下载历史数据,可以前往青悦开放环境数据中心。
 6. 如果需要非国控数据,比如各个省控,美领馆等数据,可以使用我们另外一个大中华地区数据的API,也在店铺中。 
7.无数据(返回码441)或者无效数据(实时报超过2个小时 返回码:442)时不扣费。 
8.数据及时:国控,省控在官方发布后10分钟内更新数据,地市控,港澳台在官方发布后20分钟内更新数据。
产品说明

接口返回值:

字段字段说明province省份名称city城市名称station监测点名称station_code监测点编码pollutions首要污染物level空气质量指数类别,有“优、良、轻度污染、中度污染、重度污染、严重污染”6类index空气质量指数等级,和类别对应0,1,2,3,4,5aqi空气质量指数(AQI),即air quality index,是定量描述空气质量状况的无纲量指数so2二氧化硫1小时平均浓度,ug/m3so2_24h二氧化硫24小时滑动平均浓度,ug/m3no2二氧化氮1小时平均浓度,ug/m3no2_24h二氧化氮24小时滑动平均浓度,ug/m3pm10颗粒物(粒径小于等于10μm)1小时平均浓度,ug/m3pm10_24h颗粒物(粒径小于等于10μm)24小时滑动平均浓度,ug/m3co一氧化碳1小时平均浓度,mg/m3co_24h一氧化碳24小时滑动平均浓度,mg/m3o3臭氧1小时平均浓度,ug/m3o3_24h臭氧日最大1小时平均浓度,ug/m3o3_8h臭氧8小时滑动平均浓度,ug/m3o3_8h_24h臭氧日最大8小时滑动平均浓度,ug/m3pm2_5颗粒物(粒径小于等于2.5μm)1小时平均浓度,ug/m3pm2_5_24h颗粒物(粒径小于等于2.5μm)24小时滑动平均浓度,ug/m3pubtime数据发布的时间

iso2:    二氧化硫分指数IAQI

ico:     一氧化碳分指数IAQI

io3:    臭氧分指数IAQI

ino2:  二氧化碳分指数IAQI

ipm2_5:  PM2.5分指数IAQI

ipm10:    PM10分指数IAQI

评价详情
暂无评价
购买记录
联系电话

021-60534095

联系客服
请提前登录QQ,以获得更好体验

青悦客服

服务时间

7:30~20:30

联系邮箱

support@epmap.org

1
立即购买
联系方式

联系电话

021-60534095

在线客服

青悦客服

服务时间

7:30~20:30

联系邮箱

support@epmap.org
必须同意使用协议才可购买