|
@@ -1,10 +1,13 @@
|
|
|
package com.yunfeiyun.agmp.common.utils.weather;
|
|
package com.yunfeiyun.agmp.common.utils.weather;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
import java.io.InputStreamReader;
|
|
import java.io.InputStreamReader;
|
|
|
|
|
+import java.io.OutputStream;
|
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Field;
|
|
|
import java.net.HttpURLConnection;
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
@@ -13,15 +16,21 @@ import java.nio.charset.StandardCharsets;
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
public class WeatherUtil {
|
|
public class WeatherUtil {
|
|
|
|
|
|
|
|
- public static final String WEATHER_API = "https://v0.yiketianqi.com/api?";
|
|
|
|
|
|
|
+ public static final String WEATHER_API = "http://open.nyzhwlw.com:10001/yf_weather";
|
|
|
|
|
|
|
|
public static String getWeather(WeatherReqVo weatherReqVo) {
|
|
public static String getWeather(WeatherReqVo weatherReqVo) {
|
|
|
- String path = appendRequestParam(weatherReqVo);
|
|
|
|
|
|
|
+
|
|
|
HttpURLConnection conn;
|
|
HttpURLConnection conn;
|
|
|
try {
|
|
try {
|
|
|
- URL url = new URL(path);
|
|
|
|
|
|
|
+ URL url = new URL(WEATHER_API);
|
|
|
conn = (HttpURLConnection) url.openConnection();
|
|
conn = (HttpURLConnection) url.openConnection();
|
|
|
- conn.setRequestMethod("GET");
|
|
|
|
|
|
|
+ conn.setRequestMethod("POST");
|
|
|
|
|
+ conn.setRequestProperty("Content-Type", "application/json");
|
|
|
|
|
+ conn.setDoOutput(true);
|
|
|
|
|
+ OutputStream outputStream = conn.getOutputStream();
|
|
|
|
|
+ outputStream.write(JSON.toJSONBytes(weatherReqVo));
|
|
|
|
|
+ outputStream.flush();
|
|
|
|
|
+ outputStream.close();
|
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
|
log.error("请求构造失败",e);
|
|
log.error("请求构造失败",e);
|
|
|
return null;
|
|
return null;
|
|
@@ -43,15 +52,21 @@ public class WeatherUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static String getWeatherNearlySevenDays(WeatherReqVo weatherReqVo) {
|
|
public static String getWeatherNearlySevenDays(WeatherReqVo weatherReqVo) {
|
|
|
- return request(appendRequestParam(weatherReqVo));
|
|
|
|
|
|
|
+ return request(weatherReqVo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static String request(String path) {
|
|
|
|
|
|
|
+ public static String request(WeatherReqVo weatherReqVo) {
|
|
|
HttpURLConnection conn;
|
|
HttpURLConnection conn;
|
|
|
try {
|
|
try {
|
|
|
- URL url = new URL(path);
|
|
|
|
|
|
|
+ URL url = new URL(WEATHER_API);
|
|
|
conn = (HttpURLConnection) url.openConnection();
|
|
conn = (HttpURLConnection) url.openConnection();
|
|
|
- conn.setRequestMethod("GET");
|
|
|
|
|
|
|
+ conn.setRequestMethod("POST");
|
|
|
|
|
+ conn.setRequestProperty("Content-Type", "application/json");
|
|
|
|
|
+ conn.setDoOutput(true);
|
|
|
|
|
+ OutputStream outputStream = conn.getOutputStream();
|
|
|
|
|
+ outputStream.write(JSON.toJSONBytes(weatherReqVo));
|
|
|
|
|
+ outputStream.flush();
|
|
|
|
|
+ outputStream.close();
|
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
|
log.error("请求构造失败",e);
|
|
log.error("请求构造失败",e);
|
|
|
return null;
|
|
return null;
|