| | |
| | | import com.yeshi.buwan.funtv.entity.FunTVAlbum2; |
| | | import com.yeshi.buwan.funtv.entity.FunTVShortVideo2; |
| | | import com.yeshi.buwan.funtv.entity.FunTVVideo2; |
| | | import com.yeshi.buwan.funtv.vo.*; |
| | | import com.yeshi.buwan.util.HttpUtil; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.util.TimeUtil; |
| | |
| | | public class FunTVNewApi { |
| | | private static final String CP = "fk84vly"; |
| | | private static final String SECRET_KEY = "eD*r3dZNQ%7"; |
| | | |
| | | private static final String APP_ID = "b22whcwhkc4uczk7"; |
| | | private static final String APP_SECRET = "wrLDM2QLJWPM1Oem"; |
| | | |
| | | private static String accessToken; |
| | | private static long accessTokenInvalidTime; |
| | |
| | | * @param pageSize |
| | | * @param startTime 开始时间 |
| | | * @param endTime 结束时间 |
| | | * @param channelId 频道ID 1-电影 2-电视剧 3-动漫 4-综艺 5-少儿 |
| | | * @param status 0表示不可用媒体,1表示可用媒体,2表示全部媒体 |
| | | * @return |
| | | */ |
| | | public static Funtv2ResultVO getAlbums(int page, int pageSize, Long startTime, Long endTime, Integer channelId, Integer status) { |
| | | String url = "http://papi.funshion.com/cp/syncmv"; |
| | | public static Funtv2ResultVO getAlbums(int page, int pageSize, Long startTime, Long endTime, Integer status) { |
| | | String url = "http://pfmg.funshion.com/v1/cp/syncmv"; |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("mtype", "media"); |
| | | if (startTime == null) |
| | | params.put("start", "0"); |
| | | else |
| | | if (startTime != null) |
| | | params.put("start", TimeUtil.getGernalTime(startTime, "yyyyMMddHHmm")); |
| | | if (endTime == null) |
| | | params.put("end", "0"); |
| | | else |
| | | if (endTime != null) |
| | | params.put("end", TimeUtil.getGernalTime(endTime, "yyyyMMddHHmm")); |
| | | |
| | | if (channelId != null) |
| | | params.put("channel", channelId + ""); |
| | | |
| | | if (status != null) |
| | | params.put("status", status + ""); |
| | |
| | | |
| | | try { |
| | | String result = baseRequest(url, params); |
| | | |
| | | System.out.println(result); |
| | | JSONObject json = JSONObject.fromObject(result); |
| | | if (json.optInt("code") == 0) { |
| | | JSONArray array = json.optJSONArray("datas"); |
| | | JSONArray array = json.optJSONArray("data"); |
| | | List<FunTVAlbum2> album2List = new Gson().fromJson(array.toString(), new TypeToken<List<FunTVAlbum2>>() { |
| | | }.getType()); |
| | | for (FunTVAlbum2 album2 : album2List) |
| | | if (album2.getEpisodes() != null) |
| | | for (FunTVVideo2 video2 : album2.getEpisodes()) |
| | | for (FunTVVideo2 video2 : album2.getEpisodes()) { |
| | | video2.setMediaId(album2.getId()); |
| | | video2.setFunH5Url(String.format("http://m.fun.tv/focplay/?mid=%s&vid=%s&malliance=fk84vly", album2.getId(), video2.getId())); |
| | | } |
| | | int totalCount = json.optInt("total"); |
| | | return new Funtv2ResultVO(totalCount, album2List); |
| | | } |
| | |
| | | return null; |
| | | } |
| | | |
| | | public static FunTVAlbum2 getAlbumsDetail(String aid) { |
| | | String url = "http://papi.funshion.com/cp/syncmv"; |
| | | // public static FunTVAlbum2 getAlbumsDetail(String aid) { |
| | | // String url = "http://papi.funshion.com/cp/syncmv"; |
| | | // Map<String, String> params = new HashMap<>(); |
| | | // params.put("mtype", "media"); |
| | | // params.put("id", aid); |
| | | // try { |
| | | // String result = baseRequest(url, params); |
| | | // JSONObject json = JSONObject.fromObject(result); |
| | | // if (json.optInt("code") == 0) { |
| | | // JSONArray array = json.optJSONArray("datas"); |
| | | // List<FunTVAlbum2> album2List = new Gson().fromJson(array.toString(), new TypeToken<List<FunTVAlbum2>>() { |
| | | // }.getType()); |
| | | // for (FunTVAlbum2 album2 : album2List) |
| | | // if (album2.getEpisodes() != null) |
| | | // for (FunTVVideo2 video2 : album2.getEpisodes()) |
| | | // video2.setMediaId(album2.getId()); |
| | | // if (album2List != null && album2List.size() > 0) |
| | | // return album2List.get(0); |
| | | // } |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // return null; |
| | | // } |
| | | |
| | | // |
| | | // public static Funtv2ResultVO getVideos(int page, int pageSize, Long startTime, Long endTime, Integer channelId, Integer status) { |
| | | // String url = "http://papi.funshion.com/cp/syncmv"; |
| | | // Map<String, String> params = new HashMap<>(); |
| | | // params.put("mtype", "video"); |
| | | // if (startTime == null) |
| | | // params.put("start", "0"); |
| | | // else |
| | | // params.put("start", TimeUtil.getGernalTime(startTime, "yyyyMMddHHmm")); |
| | | // if (endTime == null) |
| | | // params.put("end", "0"); |
| | | // else |
| | | // params.put("end", TimeUtil.getGernalTime(endTime, "yyyyMMddHHmm")); |
| | | // |
| | | // if (channelId != null) |
| | | // params.put("channel", channelId + ""); |
| | | // |
| | | // if (status != null) |
| | | // params.put("status", status + ""); |
| | | // |
| | | // params.put("page_size", pageSize + ""); |
| | | // params.put("page_no", page + ""); |
| | | // |
| | | // try { |
| | | // String result = baseRequest(url, params); |
| | | // JSONObject json = JSONObject.fromObject(result); |
| | | // if (json.optInt("code") == 0) { |
| | | // JSONArray array = json.optJSONArray("datas"); |
| | | // List<FunTVShortVideo2> videoList = new Gson().fromJson(array.toString(), new TypeToken<List<FunTVShortVideo2>>() { |
| | | // }.getType()); |
| | | // int totalCount = json.optInt("total"); |
| | | // return new Funtv2ResultVO(totalCount, videoList); |
| | | // } |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // return null; |
| | | // } |
| | | |
| | | // |
| | | // public static FunTVShortVideo2 getVideoDetail(String vid) { |
| | | // String url = "http://papi.funshion.com/cp/syncmv"; |
| | | // Map<String, String> params = new HashMap<>(); |
| | | // params.put("mtype", "video"); |
| | | // params.put("id", vid); |
| | | // |
| | | // try { |
| | | // String result = baseRequest(url, params); |
| | | // JSONObject json = JSONObject.fromObject(result); |
| | | // if (json.optInt("code") == 0) { |
| | | // JSONArray array = json.optJSONArray("datas"); |
| | | // List<FunTVShortVideo2> videoList = new Gson().fromJson(array.toString(), new TypeToken<List<FunTVShortVideo2>>() { |
| | | // }.getType()); |
| | | // if (videoList != null && videoList.size() > 0) |
| | | // return videoList.get(0); |
| | | // } |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // return null; |
| | | // } |
| | | |
| | | /** |
| | | * 获取授权码 |
| | | * |
| | | * @return |
| | | */ |
| | | public static String getAuthCode() { |
| | | String url = "http://pfmg.funshion.com/v1/config/authcode"; |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("mtype", "media"); |
| | | params.put("id", aid); |
| | | try { |
| | | String result = baseRequest(url, params); |
| | | JSONObject json = JSONObject.fromObject(result); |
| | | if (json.optInt("code") == 0) { |
| | | JSONArray array = json.optJSONArray("datas"); |
| | | List<FunTVAlbum2> album2List = new Gson().fromJson(array.toString(), new TypeToken<List<FunTVAlbum2>>() { |
| | | }.getType()); |
| | | for (FunTVAlbum2 album2 : album2List) |
| | | if (album2.getEpisodes() != null) |
| | | for (FunTVVideo2 video2 : album2.getEpisodes()) |
| | | video2.setMediaId(album2.getId()); |
| | | if (album2List != null && album2List.size() > 0) |
| | | return album2List.get(0); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public static Funtv2ResultVO getVideos(int page, int pageSize, Long startTime, Long endTime, Integer channelId, Integer status) { |
| | | String url = "http://papi.funshion.com/cp/syncmv"; |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("mtype", "video"); |
| | | if (startTime == null) |
| | | params.put("start", "0"); |
| | | else |
| | | params.put("start", TimeUtil.getGernalTime(startTime, "yyyyMMddHHmm")); |
| | | if (endTime == null) |
| | | params.put("end", "0"); |
| | | else |
| | | params.put("end", TimeUtil.getGernalTime(endTime, "yyyyMMddHHmm")); |
| | | |
| | | if (channelId != null) |
| | | params.put("channel", channelId + ""); |
| | | |
| | | if (status != null) |
| | | params.put("status", status + ""); |
| | | |
| | | params.put("page_size", pageSize + ""); |
| | | params.put("page_no", page + ""); |
| | | |
| | | try { |
| | | String result = baseRequest(url, params); |
| | | JSONObject json = JSONObject.fromObject(result); |
| | | if (json.optInt("code") == 0) { |
| | | JSONArray array = json.optJSONArray("datas"); |
| | | List<FunTVShortVideo2> videoList = new Gson().fromJson(array.toString(), new TypeToken<List<FunTVShortVideo2>>() { |
| | | }.getType()); |
| | | int totalCount = json.optInt("total"); |
| | | return new Funtv2ResultVO(totalCount, videoList); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public static FunTVShortVideo2 getVideoDetail(String vid) { |
| | | String url = "http://papi.funshion.com/cp/syncmv"; |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("mtype", "video"); |
| | | params.put("id", vid); |
| | | |
| | | try { |
| | | String result = baseRequest(url, params); |
| | | JSONObject json = JSONObject.fromObject(result); |
| | | if (json.optInt("code") == 0) { |
| | | JSONArray array = json.optJSONArray("datas"); |
| | | List<FunTVShortVideo2> videoList = new Gson().fromJson(array.toString(), new TypeToken<List<FunTVShortVideo2>>() { |
| | | }.getType()); |
| | | if (videoList != null && videoList.size() > 0) |
| | | return videoList.get(0); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | params.put("ctime", System.currentTimeMillis() + ""); |
| | | params.put("appid", APP_ID); |
| | | params.put("sign", org.yeshi.utils.StringUtil.Md5(APP_ID + "_" + params.get("ctime") + "_" + APP_SECRET)); |
| | | String result = HttpUtil.get(url, params); |
| | | System.out.println(result); |
| | | JSONObject json = JSONObject.fromObject(result); |
| | | if (json.optInt("retcode") == 200) { |
| | | return json.optJSONObject("data").optString("auth_code"); |
| | | } |
| | | return null; |
| | | } |