日出日落
根据经纬度点和日期,获取该点位当日的日出、日落时刻点数
接口地址
https://api.foreocean.com/geography/sun
请求方式
GET
请求参数说明
参数名称 | 类型 | 是否必须 | 备注 |
---|---|---|---|
Token | String | 是 | API 调用令牌,您申请应用的 Token,放在请求头中 |
location | String | 是 | 经纬度,例如:121.841676,31.055285 |
date | String | 是 | 日期,例如:20220310,格式:YYYYMMDD |
请求示例
public static void main(String[] args) {
Map<String, Object> params = new HashMap<>(16);
params.put("location", "121.841676,31.055285");
params.put("date", "20230530");
String requestUrl = "https://api.foreocean.com/geography/sun";
String response = get(requestUrl, params);
System.out.println(response);
}
public static String get(String url, Map<String, Object> params) {
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
url = url + "?";
for (Iterator<String> iterator = params.keySet().iterator(); iterator.hasNext();) {
String key = iterator.next();
String temp = key + "=" + params.get(key) + "&";
url = url + temp;
}
url = url.substring(0, url.length() - 1);
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("Token","API调用令牌");
CloseableHttpResponse response = httpClient.execute(httpGet);
try {
HttpEntity entity = response.getEntity();
if (entity != null) {
String str = EntityUtils.toString(entity, CHARSET);
return str;
}
} finally {
response.close();
httpClient.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
import requests
if __name__ == '__main__':
url = 'https://api.foreocean.com/geography/sun'
headers = {'Token': 'API调用令牌'}
params = {'location': '119.664236,35.529743','date': '20230530'}
response = requests.get(url, headers=headers, params=params)
print(response.text)
返回结果示例
{
"code": "1000", //响应码,1000-处理成功,其他代码说明请参考API返回错误代码说明
"data": {
"sunrise": "07:21", //日出时间
"sunset": "16:49" //日落时间
},
"msg": "success",
"success": true
}