| | |
| | | package com.yeshi.fanli.controller.h5;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.io.PrintWriter;
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.script.Invocable;
|
| | | import javax.script.ScriptEngine;
|
| | | import javax.script.ScriptEngineManager;
|
| | |
|
| | | import org.jsoup.Jsoup;
|
| | | import org.jsoup.nodes.Document;
|
| | | import org.jsoup.select.Elements;
|
| | | import org.springframework.stereotype.Controller;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.GsonBuilder;
|
| | | import com.yeshi.fanli.entity.accept.AcceptData;
|
| | | import com.yeshi.fanli.entity.xcx.StrategyPicture;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.user.StrategyPictureService;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | /**
|
| | | * 动态
|
| | | * |
| | | * @author Administrator
|
| | | *
|
| | | */
|
| | | @Controller
|
| | | @RequestMapping("api/h5/v1/gonglue")
|
| | | public class GongLueController {
|
| | |
|
| | | @Resource
|
| | | private StrategyPictureService strategtPictureService;
|
| | |
|
| | | @Resource
|
| | | private ConfigService configService;
|
| | |
|
| | | /**
|
| | | * 获取攻略列表
|
| | | * |
| | | * @param acceptData
|
| | | * @param callBack
|
| | | * @param type
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "listGongLue")
|
| | | public void listGongLue(AcceptData acceptData, String callback, int type, PrintWriter out) {
|
| | | List<StrategyPicture> list = null;
|
| | | if (type == StrategyPicture.TYPE_TEXT)
|
| | | list = strategtPictureService.getTextStrategyPictureListCache();
|
| | | else
|
| | | list = strategtPictureService.getVideoStrategyPictureListCache();
|
| | |
|
| | | Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
| | | if (StringUtil.isNullOrEmpty(callback)) {
|
| | | List<StrategyPicture> newList = new ArrayList<StrategyPicture>();
|
| | | newList.addAll(list);
|
| | | if (acceptData != null && "ios".equalsIgnoreCase(acceptData.getPlatform())
|
| | | && !StringUtil.isNullOrEmpty(acceptData.getVersion())
|
| | | && configService.iosOnLining(Integer.parseInt(acceptData.getVersion())))
|
| | | for (int i = 0; i < newList.size(); i++) {
|
| | | if (newList.get(i).getTitle().contains("赚钱")) {
|
| | | newList.remove(i);
|
| | | i--;
|
| | | }
|
| | | }
|
| | | out.print(JsonUtil.loadTrueResult(gson.toJson(newList)));
|
| | | } else
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(gson.toJson(list))));
|
| | | }
|
| | |
|
| | | @RequestMapping(value = "getPlayUrl")
|
| | | public void getPlayUrl(AcceptData acceptData, String callBack, long id, PrintWriter out) {
|
| | |
|
| | | }
|
| | |
|
| | | /**
|
| | | * 解析bilibili的播放链接
|
| | | * |
| | | * @param url
|
| | | * @return
|
| | | */
|
| | | public static String parseBiliBiliPlayUrl(String url) {
|
| | | try {
|
| | | Document doc = Jsoup.connect(url).header("Host", "m.bilibili.com")
|
| | | .header("User-Agent",
|
| | | "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1")
|
| | | .get();
|
| | | Elements els = doc.getElementsByTag("script");
|
| | | for (int i = 0; i < els.size(); i++) {
|
| | | String html = els.get(i).html();
|
| | | if (html.contains("window.__INITIAL_STATE__=")) {
|
| | | html = html.replace("window.", "windowData.");
|
| | | html = "var windowData={};" + html;
|
| | | String dataJS = html + "\n"
|
| | | + " function getData(){return windowData.__INITIAL_STATE__.reduxAsyncConnect.videoInfo.initUrl;}";
|
| | | ScriptEngineManager manager = new ScriptEngineManager();
|
| | | ScriptEngine engine = manager.getEngineByName("javascript");
|
| | | try {
|
| | | engine.eval(dataJS);
|
| | | if (engine instanceof Invocable) {
|
| | | Invocable in = (Invocable) engine;
|
| | | String playUrl = in.invokeFunction("getData").toString();
|
| | | if (!playUrl.startsWith("http"))
|
| | | playUrl = "http:" + playUrl;
|
| | | return playUrl;
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | return null;
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.controller.h5; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.script.Invocable; |
| | | import javax.script.ScriptEngine; |
| | | import javax.script.ScriptEngineManager; |
| | | |
| | | import com.yeshi.fanli.util.SystemInfoUtil; |
| | | import org.jsoup.Jsoup; |
| | | import org.jsoup.nodes.Document; |
| | | import org.jsoup.select.Elements; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.yeshi.utils.JsonUtil; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.yeshi.fanli.entity.accept.AcceptData; |
| | | import com.yeshi.fanli.entity.xcx.StrategyPicture; |
| | | import com.yeshi.fanli.service.inter.config.ConfigService; |
| | | import com.yeshi.fanli.service.inter.user.StrategyPictureService; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | |
| | | /** |
| | | * 动态 |
| | | * |
| | | * @author Administrator |
| | | * |
| | | */ |
| | | @Controller |
| | | @RequestMapping("api/h5/v1/gonglue") |
| | | public class GongLueController { |
| | | |
| | | @Resource |
| | | private StrategyPictureService strategtPictureService; |
| | | |
| | | @Resource |
| | | private ConfigService configService; |
| | | |
| | | /** |
| | | * 获取攻略列表 |
| | | * |
| | | * @param acceptData |
| | | * @param type |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "listGongLue") |
| | | public void listGongLue(AcceptData acceptData, String callback, int type, PrintWriter out) { |
| | | List<StrategyPicture> list = null; |
| | | if (type == StrategyPicture.TYPE_TEXT) |
| | | list = strategtPictureService.getTextStrategyPictureListCache(); |
| | | else |
| | | list = strategtPictureService.getVideoStrategyPictureListCache(); |
| | | |
| | | Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); |
| | | if (StringUtil.isNullOrEmpty(callback)) { |
| | | List<StrategyPicture> newList = new ArrayList<StrategyPicture>(); |
| | | newList.addAll(list); |
| | | if (acceptData != null && "ios".equalsIgnoreCase(acceptData.getPlatform()) |
| | | && !StringUtil.isNullOrEmpty(acceptData.getVersion()) |
| | | && configService.iosOnLining(Integer.parseInt(acceptData.getVersion()), SystemInfoUtil.getSystem(acceptData))) |
| | | for (int i = 0; i < newList.size(); i++) { |
| | | if (newList.get(i).getTitle().contains("赚钱")) { |
| | | newList.remove(i); |
| | | i--; |
| | | } |
| | | } |
| | | out.print(JsonUtil.loadTrueResult(gson.toJson(newList))); |
| | | } else |
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(gson.toJson(list)))); |
| | | } |
| | | |
| | | @RequestMapping(value = "getPlayUrl") |
| | | public void getPlayUrl(AcceptData acceptData, String callBack, long id, PrintWriter out) { |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 解析bilibili的播放链接 |
| | | * |
| | | * @param url |
| | | * @return |
| | | */ |
| | | public static String parseBiliBiliPlayUrl(String url) { |
| | | try { |
| | | Document doc = Jsoup.connect(url).header("Host", "m.bilibili.com") |
| | | .header("User-Agent", |
| | | "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1") |
| | | .get(); |
| | | Elements els = doc.getElementsByTag("script"); |
| | | for (int i = 0; i < els.size(); i++) { |
| | | String html = els.get(i).html(); |
| | | if (html.contains("window.__INITIAL_STATE__=")) { |
| | | html = html.replace("window.", "windowData."); |
| | | html = "var windowData={};" + html; |
| | | String dataJS = html + "\n" |
| | | + " function getData(){return windowData.__INITIAL_STATE__.reduxAsyncConnect.videoInfo.initUrl;}"; |
| | | ScriptEngineManager manager = new ScriptEngineManager(); |
| | | ScriptEngine engine = manager.getEngineByName("javascript"); |
| | | try { |
| | | engine.eval(dataJS); |
| | | if (engine instanceof Invocable) { |
| | | Invocable in = (Invocable) engine; |
| | | String playUrl = in.invokeFunction("getData").toString(); |
| | | if (!playUrl.startsWith("http")) |
| | | playUrl = "http:" + playUrl; |
| | | return playUrl; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | } |