新增bngumi番剧计划接口

优化打印参数接口返回值
This commit is contained in:
yutou 2021-01-13 18:56:07 +08:00
parent 24a214489b
commit b0f3f26728
2 changed files with 67 additions and 2 deletions

View File

@ -0,0 +1,65 @@
package com.yutou.tools.bangumi;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yutou.tools.utils.HttpTools;
import com.yutou.tools.utils.RedisTools;
import java.util.Calendar;
import java.util.Date;
public class BangumiTools {
private static final String url = "http://api.bgm.tv/";
private static final String toDayBangumi = url + "calendar";
private static final String BangumiInfo = url + "/subject/%s?responseGroup=large";
/**
* 获取番剧列表
* @param day 周几-1为全部,非1~7范围则为当天
* @return 当日数据
*/
public static JSONObject getBangumi(int day) {
String str = HttpTools.get(toDayBangumi);
JSONArray main = JSONArray.parseArray(str);
if(day==-1){
JSONObject json=new JSONObject();
json.put("bangumi",main);
return json;
}
if(day<1||day>7) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
day=calendar.get(Calendar.DAY_OF_WEEK);
}
if (main != null)
for (Object o : main) {
JSONObject json = (JSONObject) o;
if (json.getJSONObject("weekday").getInteger("id") == day) {
return json;
}
}
return null;
}
/**
* 获取番剧详细信息
* @param id 剧集id
* @return 详细信息
*/
public static JSONObject getBangumiInfo(int id){
String str = HttpTools.get(String.format(BangumiInfo,id+""));
JSONObject main = JSONObject.parseObject(str);
return main;
}
public static void reportToDayBangumi(){
if(!RedisTools.get("reportToDayBangumi").equals("true")){
JSONObject toDay=getBangumi(0);
}
}
public static void main(String[] args) {
System.out.println(getBangumiInfo(293193));
}
}

View File

@ -75,7 +75,7 @@ public class tools {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("code", 0); json.put("code", 0);
json.put("address", Tools.getRemoteAddress(request)); json.put("address", Tools.getRemoteAddress(request));
json.put("UA", request.getHeader("")); json.put("UA", request.getHeader("User-Agent"));
json.put("addressUrl", request.getPathInfo()); json.put("addressUrl", request.getPathInfo());
json.put("params", params); json.put("params", params);
json.put("cookie", cookies); json.put("cookie", cookies);
@ -88,7 +88,7 @@ public class tools {
case "-999": case "-999":
case "param": case "param":
return json.toJSONString(); return json.toJSONString();
case "user": default:
return RedisTools.get("request"); return RedisTools.get("request");
} }
}catch (Exception e){ }catch (Exception e){