天气接口添加开鲁location
This commit is contained in:
parent
3a642833c4
commit
3ad89e44dd
@ -18,16 +18,16 @@ public class WeatherController {
|
||||
* 获取七天的天气预报
|
||||
*/
|
||||
@GetMapping("/qitian")
|
||||
public AjaxResult getWeather() {
|
||||
return AjaxResult.success(TianqiApi.QitianApi());
|
||||
public AjaxResult getWeather(Long projectId) {
|
||||
return AjaxResult.success(TianqiApi.QitianApi(projectId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取实时天气
|
||||
*/
|
||||
@GetMapping("/shishi")
|
||||
public AjaxResult getWeatherShiShi() {
|
||||
return AjaxResult.success(TianqiApi.weatherNow());
|
||||
public AjaxResult getWeatherShiShi(Long projectId) {
|
||||
return AjaxResult.success(TianqiApi.weatherNow(projectId));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,11 +15,19 @@ public class TianqiApi {
|
||||
/**
|
||||
* 获取未来天气预测
|
||||
*/
|
||||
public static JSONObject QitianApi() {
|
||||
public static JSONObject QitianApi(Long projectId) {
|
||||
String location="";
|
||||
if(projectId==35){//黑龙江项目
|
||||
location="YBMUBR41ZWVC";
|
||||
|
||||
}else if(projectId==39){//开鲁
|
||||
location="WXY201PUQV5D";
|
||||
}
|
||||
// System.out.println(location);
|
||||
String url = UrlConstant.QitianApi + "?key=" +
|
||||
UrlConstant.PrivateKey +
|
||||
"&location=YBMUBR41ZWVC&language=zh-Hans&unit=c";//指定URL
|
||||
"&location="+location+"&language=zh-Hans&unit=c";//指定URL
|
||||
// System.out.println(url);
|
||||
HttpResponse execute = HttpUtil.createGet(url).execute();
|
||||
if (execute.getStatus() == HttpStatus.HTTP_OK) {
|
||||
JSONObject jsonObject = new JSONObject(execute.body());
|
||||
@ -33,10 +41,19 @@ public class TianqiApi {
|
||||
/**
|
||||
* 获取天气实况
|
||||
*/
|
||||
public static JSONObject weatherNow() {
|
||||
public static JSONObject weatherNow(Long projectId) {
|
||||
String location="";
|
||||
if(projectId==35){//黑龙江项目
|
||||
location="YBMUBR41ZWVC";
|
||||
|
||||
}else if(projectId==39){//开鲁项目
|
||||
location="WXY201PUQV5D";
|
||||
}
|
||||
// System.out.println(location);
|
||||
String url = UrlConstant.ShishiApi + "?key=" +
|
||||
UrlConstant.PrivateKey +
|
||||
"&location=YBMUBR41ZWVC&language=zh-Hans&unit=c";//指定URL
|
||||
"&location="+location+"&language=zh-Hans&unit=c";//指定URL
|
||||
// System.out.println(url);
|
||||
HttpResponse execute = HttpUtil.createGet(url).execute();
|
||||
if (execute.getStatus() == HttpStatus.HTTP_OK) {
|
||||
JSONObject jsonObject = new JSONObject(execute.body());
|
||||
@ -71,7 +88,15 @@ public class TianqiApi {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TianqiApi.weatherNow();
|
||||
public static void main(String[] args)
|
||||
{
|
||||
TianqiApi.weatherNow(39L);
|
||||
/*String url="https://api.seniverse.com/v3/location/search.json?key="+UrlConstant.PrivateKey
|
||||
+"&q="+"开鲁";
|
||||
HttpResponse execute = HttpUtil.createGet(url).execute();
|
||||
if (execute.getStatus() == HttpStatus.HTTP_OK) {
|
||||
JSONObject jsonObject = new JSONObject(execute.body());
|
||||
System.out.println("jsonObject = " + jsonObject);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user