From 3ad89e44dd2c71bc79901e39b522930111ed4a53 Mon Sep 17 00:00:00 2001 From: tongliran Date: Wed, 15 Jan 2025 11:01:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A9=E6=B0=94=E6=8E=A5=E5=8F=A3=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=BC=80=E9=B2=81location?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/weather/WeatherController.java | 8 ++-- .../api/xinzhitianqi/TianqiApi.java | 37 ++++++++++++++++--- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/fastbee-open-api/src/main/java/com/fastbee/data/controller/weather/WeatherController.java b/fastbee-open-api/src/main/java/com/fastbee/data/controller/weather/WeatherController.java index 4025d7f..2a54fbf 100644 --- a/fastbee-open-api/src/main/java/com/fastbee/data/controller/weather/WeatherController.java +++ b/fastbee-open-api/src/main/java/com/fastbee/data/controller/weather/WeatherController.java @@ -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)); } } diff --git a/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/deviceData/api/xinzhitianqi/TianqiApi.java b/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/deviceData/api/xinzhitianqi/TianqiApi.java index 939cfc8..871ae63 100644 --- a/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/deviceData/api/xinzhitianqi/TianqiApi.java +++ b/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/deviceData/api/xinzhitianqi/TianqiApi.java @@ -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); + }*/ } }