| | |
| | | package com.yeshi.fanli.util.jd;
|
| | |
|
| | | import java.io.BufferedReader;
|
| | | import java.io.IOException;
|
| | | import java.io.InputStream;
|
| | | import java.io.InputStreamReader;
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.math.BigDecimal;
|
| | | import java.net.URLEncoder;
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | public static String getJDGoodsJS() {
|
| | | InputStream input = JDUtil.class.getClassLoader().getResourceAsStream("jdGoods.js");
|
| | | StringBuilder sb = new StringBuilder();
|
| | | String line;
|
| | | BufferedReader br = new BufferedReader(new InputStreamReader(input));
|
| | | try {
|
| | | while ((line = br.readLine()) != null) {
|
| | | sb.append(line);
|
| | | }
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return sb.toString();
|
| | | }
|
| | |
|
| | | static String jdGoodsJs = null;
|
| | | static ScriptEngine engine = null;
|
| | | static {
|
| | | if (jdGoodsJs == null)
|
| | | jdGoodsJs = getJDGoodsJS();
|
| | | ScriptEngineManager manager = new ScriptEngineManager();
|
| | | engine = manager.getEngineByName("javascript");
|
| | | try {
|
| | | engine.eval(jdGoodsJs);
|
| | | } catch (Exception e) {
|
| | | }
|
| | | }
|
| | |
|
| | | public static String getJDGoodsId(String url) {
|
| | | try {
|
| | | if (engine instanceof Invocable) {
|
| | | Invocable in = (Invocable) engine;
|
| | | Object goodsId = in.invokeFunction("getGoodsId", url);
|
| | | if (goodsId!=null)
|
| | | return goodsId.toString().trim();
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | }
|