依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.73</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>2.7.5</version>
</dependency>
代码实现
public class HolidayAndVacationsUtil {
public static void main(String[] args) {
System.out.println(getDateInfo("2022-05-12"));
System.out.println(getDateInfo("2022-05-01"));
System.out.println(getDateInfo("2022-05-07"));
}
private static String getDateInfo(String date) {
String url = "http://timor.tech/api/holiday/info/"+date;
OkHttpClient client = new OkHttpClient();
Response response;
//解密数据
String rsa = null;
Request request = new Request.Builder()
.url(url)
.get()
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
try {
response = client.newCall(request).execute();
rsa = response.body().string();
} catch (IOException e) {
e.printStackTrace();
}
return JSONObject.parseObject(rsa, String.class);
}
}
{"code":0,"type":{"week":4,"name":"周四","type":0}}
{"code":0,"type":{"week":7,"name":"劳动节","type":2},"holiday":{"date":"2022-05-01","rest":1,"name":"劳动节","holiday":true,"wage":3}}
{"code":0,"type":{"week":6,"name":"劳动节后补班","type":3},"holiday":{"date":"2022-05-07","rest":3,"name":"劳动节后补班","after":true,"holiday":false,"wage":1,"target":"劳动节"}}
Api文档地址:免费节假日 API - 提莫的神秘商店