水质量查询
请求Header:
名称 | 值 | |
---|---|---|
Content-Type | application/x-www-form-urlencoded |
请求参数说明:
名称 | 必填 | 类型 | 说明 | |
---|---|---|---|---|
key | 是 | string | 在个人中心->我的数据,接口名称上方查看 | |
page | 否 | int | 第几页(默认1) | |
province | 否 | string | 省份,例:江苏省 | |
river | 否 | string | 流域,例:海河流域 | |
section | 否 | string | 断面名称,例:鼓楼外大街 |
请求代码示例:
curl -k -i "https://apis.juhe.cn/environment/river?key=key&page=20&province=&river=§ion="
<?php
/**
* 1867-水质量查询 - 代码参考(根据实际业务情况修改)
*/
// 基本参数配置
$apiUrl = "https://apis.juhe.cn/environment/river"; // 接口请求URL
$method = "GET"; // 接口请求方式
$headers = ["Content-Type: application/x-www-form-urlencoded"]; // 接口请求header
$apiKey = "您申请的调用APIkey"; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
$requestParams = [
'key' => $apiKey,
'page'=> '20',
'province'=> '',
'river'=> '',
'section'=> '',
];
$requestParamsStr = http_build_query($requestParams);
// 发起接口网络请求
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $apiUrl . '?' . $requestParamsStr);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if (1 == strpos("$" . $apiUrl, "https://")) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$response = curl_exec($curl);
$httpInfo = curl_getinfo($curl);
curl_close($curl);
// 解析响应结果
$responseResult = json_decode($response, true);
if ($responseResult) {
// 网络请求成功。可依据业务逻辑和接口文档说明自行处理。
var_dump($responseResult);
} else {
// 网络异常等因素,解析结果异常。可依据业务逻辑自行处理。
// var_dump($httpInfo);
var_dump("请求异常");
}
import requests
# 1867-水质量查询 - 代码参考(根据实际业务情况修改)
# 基本参数配置
apiUrl = 'https://apis.juhe.cn/environment/river' # 接口请求URL
apiKey = '您申请的调用APIkey' # 在个人中心->我的数据,接口名称上方查看
# 接口请求入参配置
requestParams = {
'key': apiKey,
'page': '20',
'province': '',
'river': '',
'section': '',
}
# 发起接口网络请求
response = requests.get(apiUrl, params=requestParams)
# 解析响应结果
if response.status_code == 200:
responseResult = response.json()
# 网络请求成功。可依据业务逻辑和接口文档说明自行处理。
print(responseResult)
else:
# 网络异常等因素,解析结果异常。可依据业务逻辑自行处理。
print('请求异常')
package main
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
)
func main() {
// 基本参数配置
apiUrl := "https://apis.juhe.cn/environment/river"
apiKey := "您申请的调用APIkey"
// 接口请求入参配置
requestParams := url.Values{}
requestParams.Set("key", apiKey)
requestParams.Set("page", "20")
requestParams.Set("province", "")
requestParams.Set("river", "")
requestParams.Set("section", "")
// 发起接口网络请求
resp, err := http.Get(apiUrl + "?" + requestParams.Encode())
if err != nil {
fmt.Println("网络请求异常:", err)
return
}
defer resp.Body.Close()
var responseResult map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&responseResult)
if err != nil {
fmt.Println("解析响应结果异常:", err)
return
}
fmt.Println(responseResult)
}
using System;
using System.Net;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
namespace Common_API_Test.Test_Demo
{
class Csharp_get
{
static void Main(string[] args)
{
string url = "https://apis.juhe.cn/environment/river";
string apiKey = "您申请的调用APIkey";
Dictionary<string, string> data = new Dictionary<string, string>();
data.Add("key", apiKey);
data.Add( "page", "20");
data.Add( "province", "");
data.Add( "river", "");
data.Add( "section", "");
using (WebClient client = new WebClient())
{
string fullUrl = url + "?" + string.Join("&", data.Select(x => x.Key + "=" + x.Value));
try
{
string responseContent = client.DownloadString(fullUrl);
dynamic responseData = JsonConvert.DeserializeObject(responseContent);
if (responseData != null)
{
Console.WriteLine("Return Code: " + responseData["error_code"]);
Console.WriteLine("Return Message: " + responseData["reason"]);
}
else
{
Console.WriteLine("json解析异常!");
}
}
catch (Exception)
{
Console.WriteLine("请检查其它错误");
}
}
}
}
}
const axios = require('axios'); // npm install axios
// 基本参数配置
const apiUrl = 'https://apis.juhe.cn/environment/river'; // 接口请求URL
const apiKey = '您申请的调用APIkey'; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
const requestParams = {
key: apiKey,
page: '20',
province: '',
river: '',
section: '',
};
// 发起接口网络请求
axios.get(apiUrl, {params: requestParams})
.then(response => {
// 解析响应结果
if (response.status === 200) {
const responseResult = response.data;
// 网络请求成功。可依据业务逻辑和接口文档说明自行处理。
console.log(responseResult);
} else {
// 网络异常等因素,解析结果异常。可依据业务逻辑自行处理。
console.log('请求异常');
}
})
.catch(error => {
// 网络请求失败,可以根据实际情况进行处理
console.log('网络请求失败:', error);
});
package cn.juhe.test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class JavaGet {
public static void main(String[] args) throws Exception {
String apiKey = "你申请的key";
String apiUrl = "https://apis.juhe.cn/environment/river";
HashMap<String, String> map = new HashMap<>();
map.put("key", apiKey);
map.put("page", "20");
map.put("province", "");
map.put("river", "");
map.put("section", "");
URL url = new URL(String.format("%s?%s", apiUrl, params(map)));
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response);
}
public static String params(Map<String, String> map) {
return map.entrySet().stream()
.map(entry -> {
try {
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString());
} catch (Exception e) {
e.printStackTrace();
return entry.getKey() + "=" + entry.getValue();
}
})
.collect(Collectors.joining("&"));
}
}
// 基本参数配置
NSString *apiUrl = @"https://apis.juhe.cn/environment/river"; // 接口请求URL
NSString *apiKey = @"您申请的调用APIkey"; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
NSDictionary *requestParams = @{
@"key": apiKey,
@"page": @"20",
@"province": @"",
@"river": @"",
@"section": @"",
};
// 发起接口网络请求
NSURLComponents *components = [NSURLComponents componentsWithString:apiUrl];
NSMutableArray *queryItems = [NSMutableArray array];
[requestParams enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) {
[queryItems addObject:[NSURLQueryItem queryItemWithName:key value:value]];
}];
components.queryItems = queryItems;
NSURL *url = components.URL;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
// 网络请求异常处理
NSLog(@"请求异常");
} else {
NSError *jsonError;
NSDictionary *responseResult = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
if (!jsonError) {
// 网络请求成功处理
// NSLog(@"%@", [responseResult objectForKey:@"error_code"]);
NSLog(@"%@", responseResult);
} else {
// 解析结果异常处理
NSLog(@"解析结果异常");
}
}
}];
[task resume];
返回参数说明:
名称 | 类型 | 说明 | |
---|---|---|---|
error_code | int | 状态码 | |
reason | string | 状态提示 | |
result | jsonObject | 返回结果 | |
total | int | 查询结果总数 | |
num | int | 返回条数 | |
page | int | 当前页 | |
province | string | 省份 | |
river | string | 流域 | |
section | string | 断面名称 | |
monitor_time | string | 监测时间 | |
water_level | string | 水质类别 | |
tempreture | string | 水温 | |
ph | string | ph(无量纲) | |
oxygen | string | 溶解氧(mg/L) | |
conductivity | string | 电导率(us/cm) | |
turbidity | string | 浊度(NFU) | |
permanganate_index | string | 高锰酸盐指数 | |
ammonia_nitrogen | string | 氨氮 | |
phosphorus | string | 总磷 | |
total_nitrogen | string | 总氮 | |
chlorophyll | string | 叶绿素α | |
algal_density | string | 藻密度 | |
states | string | 站点情况 |
JSON返回示例:JSON在线格式化工具 >
{
"reason": "成功",
"result": {
"total": 50,
"num": 10,
"page": 1,
"data": [
{
"province": "河北省",
"river": "海河流域",
"section": "三块石",
"monitor_time": "2023-12-11 08:00",
"water_level": "Ⅰ",
"tempreture": "1.8",
"ph": "8.38",
"oxygen": "12.41",
"conductivity": "1425.2",
"turbidity": "0.5",
"permanganate_index": "0.93",
"ammonia_nitrogen": "0.025",
"phosphorus": "0.005",
"total_nitrogen": "4.42",
"chlorophyll": "*",
"algal_density": "*",
"states": "正常"
},
{
"province": "河北省",
"river": "海河流域",
"section": "三小营",
"monitor_time": "2023-12-11 08:00",
"water_level": "Ⅲ",
"tempreture": "4.1",
"ph": "7.84",
"oxygen": "11.25",
"conductivity": "1218.3",
"turbidity": "5.8",
"permanganate_index": "5.36",
"ammonia_nitrogen": "0.123",
"phosphorus": "0.075",
"total_nitrogen": "10.08",
"chlorophyll": "*",
"algal_density": "*",
"states": "正常"
},
{
"province": "河北省",
"river": "海河流域",
"section": "上二道河子",
"monitor_time": "2023-12-11 08:00",
"water_level": "Ⅰ",
"tempreture": "2.2",
"ph": "8.06",
"oxygen": "12.61",
"conductivity": "732.6",
"turbidity": "3.7",
"permanganate_index": "0.75",
"ammonia_nitrogen": "0.025",
"phosphorus": "0.005",
"total_nitrogen": "7.71",
"chlorophyll": "*",
"algal_density": "*",
"states": "正常"
},
{
"province": "河北省",
"river": "海河流域",
"section": "上板城大桥",
"monitor_time": "2023-12-11 08:00",
"water_level": "Ⅳ",
"tempreture": "1.6",
"ph": "8.13",
"oxygen": "12.35",
"conductivity": "635.6",
"turbidity": "73.6",
"permanganate_index": "6.70",
"ammonia_nitrogen": "0.264",
"phosphorus": "0.106",
"total_nitrogen": "5.78",
"chlorophyll": "*",
"algal_density": "*",
"states": "正常"
},
{
"province": "河北省",
"river": "海河流域",
"section": "丰北闸",
"monitor_time": "2023-",
"water_level": "",
"tempreture": "--",
"ph": "--",
"oxygen": "--",
"conductivity": "--",
"turbidity": "--",
"permanganate_index": "--",
"ammonia_nitrogen": "--",
"phosphorus": "--",
"total_nitrogen": "--",
"chlorophyll": "*",
"algal_density": "*",
"states": "不具备运行条件"
},
{
"province": "河北省",
"river": "海河流域",
"section": "何老营",
"monitor_time": "2023-12-11 08:00",
"water_level": "Ⅲ",
"tempreture": "5.7",
"ph": "7.79",
"oxygen": "7.73",
"conductivity": "--",
"turbidity": "102.4",
"permanganate_index": "5.94",
"ammonia_nitrogen": "0.025",
"phosphorus": "0.081",
"total_nitrogen": "0.62",
"chlorophyll": "*",
"algal_density": "*",
"states": "维护"
},
{
"province": "河北省",
"river": "海河流域",
"section": "兆通",
"monitor_time": "2023-12-11 08:00",
"water_level": "Ⅰ",
"tempreture": "7.9",
"ph": "8.58",
"oxygen": "11.18",
"conductivity": "468.2",
"turbidity": "9.4",
"permanganate_index": "1.60",
"ammonia_nitrogen": "0.025",
"phosphorus": "0.011",
"total_nitrogen": "2.62",
"chlorophyll": "*",
"algal_density": "*",
"states": "正常"
},
{
"province": "河北省",
"river": "海河流域",
"section": "党坝",
"monitor_time": "2023-12-11 08:00",
"water_level": "Ⅲ",
"tempreture": "1.0",
"ph": "8.37",
"oxygen": "12.52",
"conductivity": "978.6",
"turbidity": "3.0",
"permanganate_index": "1.36",
"ammonia_nitrogen": "0.515",
"phosphorus": "0.073",
"total_nitrogen": "9.25",
"chlorophyll": "*",
"algal_density": "*",
"states": "正常"
},
{
"province": "河北省",
"river": "海河流域",
"section": "八号桥",
"monitor_time": "2023-12-11 08:00",
"water_level": "Ⅱ",
"tempreture": "3.0",
"ph": "8.56",
"oxygen": "13.75",
"conductivity": "1390.1",
"turbidity": "39.6",
"permanganate_index": "3.04",
"ammonia_nitrogen": "0.411",
"phosphorus": "0.081",
"total_nitrogen": "5.77",
"chlorophyll": "*",
"algal_density": "*",
"states": "正常"
},
{
"province": "河北省",
"river": "海河流域",
"section": "刘家庄",
"monitor_time": "2023-12-11 08:00",
"water_level": "Ⅱ",
"tempreture": "4.9",
"ph": "8.41",
"oxygen": "11.17",
"conductivity": "578.2",
"turbidity": "35.5",
"permanganate_index": "0.52",
"ammonia_nitrogen": "0.043",
"phosphorus": "0.024",
"total_nitrogen": "5.03",
"chlorophyll": "*",
"algal_density": "*",
"states": "正常"
}
]
},
"error_code": 0
}
服务级错误码参照(error_code):
错误码 | 说明 |
---|
系统级错误码参照:
错误码 | 说明 | 旧版本(resultcode) | |
---|---|---|---|
10001 | 错误的请求KEY | 101 | |
10002 | 该KEY无请求权限 | 102 | |
10003 | KEY过期 | 103 | |
10004 | 错误的OPENID | 104 | |
10005 | 应用未审核超时,请提交认证 | 105 | |
10007 | 未知的请求源 | 107 | |
10008 | 被禁止的IP | 108 | |
10009 | 被禁止的KEY | 109 | |
10011 | 当前IP请求超过限制 | 111 | |
10012 | 请求超过次数限制 | 112 | |
10013 | 测试KEY超过请求限制 | 113 | |
10014 | 系统内部异常(调用充值类业务时,请务必联系客服或通过订单查询接口检测订单,避免造成损失) | 114 | |
10020 | 接口维护 | 120 | |
10021 | 接口停用 | 121 |
错误码格式说明(示例:200201):
2 | 002 | 01 | |
---|---|---|---|
服务级错误(1为系统级错误) | 服务模块代码(即数据ID) | 具体错误代码 |