This commit is contained in:
dy 2025-07-18 10:04:38 +08:00
parent 72b3e40124
commit 75292374fa

View File

@ -0,0 +1,36 @@
package org.dromara.property.utils;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import org.json.JSONObject;
/**
* 法定节假日工具类
*/
public class HolidayUtil {
public HolidayUtil() throws Exception {
// 调用jiejiariapi.com API获取节假日信息
String baiduUrl = "https://api.jiejiariapi.com/v1/holidays/2025";
JSONObject jiejiariapiResponse = getJsonFromUrl(baiduUrl);
}
private static JSONObject getJsonFromUrl(String urlString) throws Exception {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
return new JSONObject(response.toString());
}
}