| | |
| | | import java.io.InputStreamReader;
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.math.BigDecimal;
|
| | | import java.net.URLDecoder;
|
| | | import java.net.URLEncoder;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.HashMap;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.regex.Matcher;
|
| | | import java.util.regex.Pattern;
|
| | |
|
| | | import javax.script.Invocable;
|
| | | import javax.script.ScriptEngine;
|
| | |
| | | import org.jsoup.select.Elements;
|
| | | import org.yeshi.utils.BigDecimalUtil;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | | import org.yeshi.utils.NumberUtil;
|
| | |
|
| | | import com.yeshi.fanli.dto.GoodsClassDTO;
|
| | | import com.yeshi.fanli.dto.douyin.DouYinGoods;
|
| | | import com.yeshi.fanli.dto.jd.JDCommissionInfo;
|
| | | import com.yeshi.fanli.dto.jd.JDCouponInfo;
|
| | | import com.yeshi.fanli.dto.jd.JDPingouInfo;
|
| | |
| | | import com.yeshi.fanli.dto.jd.JDSearchResult;
|
| | | import com.yeshi.fanli.dto.jd.JDShopInfo;
|
| | | import com.yeshi.fanli.entity.jd.JDGoods;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.tag.PageEntity;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 通过链接id
|
| | | * |
| | | * @param url
|
| | | * @return
|
| | | */
|
| | | public static String getJDGoodsIdByWeiXin(String url) {
|
| | | if (StringUtil.isNullOrEmpty(url)) |
| | | if (StringUtil.isNullOrEmpty(url) || url.indexOf("jd.com") < 0)
|
| | | return null;
|
| | | |
| | |
|
| | | try {
|
| | | String id = null;
|
| | | int indexOf = url.indexOf("?");
|
| | | url = url.substring(indexOf + 1, url.length()-1);
|
| | | url = url.substring(indexOf + 1, url.length() - 1);
|
| | | String[] temp = url.split("&");
|
| | | for (int i =0; i < temp.length; i ++) {
|
| | | String content = temp[i];
|
| | | for (int i = 0; i < temp.length; i++) {
|
| | | String content = temp[i];
|
| | | if (content.startsWith("sku")) {
|
| | | id = content.split("=")[content.split("=").length-1];
|
| | | id = content.split("=")[content.split("=").length - 1];
|
| | | break;
|
| | | } |
| | | }
|
| | | }
|
| | | return id;
|
| | | } catch (Exception e) {
|
| | |
| | | }
|
| | | return null;
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * 根据 u.jd短连接获取真实的商品id
|
| | | * |
| | | * @param url
|
| | | * @return
|
| | | */
|
| | | public static String getJDGoodsIdByUJD(String url) {
|
| | | try {
|
| | | String body = HttpUtil.get(url);
|
| | | Document doc = Jsoup.parse(body);
|
| | | Elements els = doc.getElementsByTag("script");
|
| | | for (int i = 0; i < els.size(); i++) {
|
| | | String content = els.get(i).html();
|
| | | if (content.indexOf("var hrl") > -1) {
|
| | | ScriptEngineManager manager = new ScriptEngineManager();
|
| | | ScriptEngine engine = manager.getEngineByName("javascript");
|
| | |
|
| | | int indexOf = content.indexOf("var hrl");
|
| | | content = content.substring(indexOf, content.length());
|
| | |
|
| | | int indexOf2 = content.indexOf(";");
|
| | | content = content.substring(0, indexOf2 + 1);
|
| | |
|
| | | String js = "function getData(){return JSON.stringify(hrl);}" + content;
|
| | |
|
| | | engine.eval(js);
|
| | | if (engine instanceof Invocable) {
|
| | | Invocable in = (Invocable) engine;
|
| | | String data = in.invokeFunction("getData").toString();
|
| | | String link = data.substring(1, data.length() - 1);
|
| | | // 将链接中未encode的参数encode
|
| | | String param = link.split("\\?")[1];
|
| | | String host = link.split("\\?")[0];
|
| | | String[] params = param.split("&");
|
| | | String paramStr = "";
|
| | | for (String p : params) {
|
| | | String value = p.substring(p.indexOf("=") + 1);
|
| | | String key = p.substring(0, p.indexOf("="));
|
| | | if (URLDecoder.decode(value, "UTF-8").equalsIgnoreCase(value)) {
|
| | | value = URLEncoder.encode(value, "UTF-8");
|
| | | }
|
| | | paramStr += key + "=" + value + "&";
|
| | | }
|
| | | link = host + "?" + paramStr;
|
| | | String realLink = HttpUtil.getLocation(link);
|
| | | Map<String, String> paramsMap = new HashMap<>();
|
| | |
|
| | | param = realLink.split("\\?")[1];
|
| | | params = param.split("&");
|
| | | for (String p : params) {
|
| | | String value = p.substring(p.indexOf("=") + 1);
|
| | | String key = p.substring(0, p.indexOf("="));
|
| | | paramsMap.put(key, value);
|
| | | }
|
| | | if (!StringUtil.isNullOrEmpty(paramsMap.get("sku"))) {
|
| | | return paramsMap.get("sku");
|
| | | }
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(paramsMap.get("wareId"))) {
|
| | | return paramsMap.get("wareId");
|
| | | }
|
| | |
|
| | | // 判断纯数字大于4位的返回
|
| | | for (Iterator<String> its = paramsMap.keySet().iterator(); its.hasNext();) {
|
| | | String key = its.next();
|
| | | String value = paramsMap.get(key);
|
| | | if (NumberUtil.isNumeric(value) && value.length() >= 4) {
|
| | | return value;
|
| | | }
|
| | | }
|
| | | String id = JDUtil.getJDGoodsId(realLink);
|
| | | if (!StringUtil.isNullOrEmpty(id)) {
|
| | | return id;
|
| | | }
|
| | | LogHelper.error("京东短接解析失败:" + url);
|
| | | return null;
|
| | | }
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | LogHelper.errorDetailInfo(e, "京东短链获取商品ID失败:", url);
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 查询天猫商品图片、标题
|
| | | *
|
| | |
| | | return getShowCouponInfo(goods.getCouponInfoList(), price);
|
| | | }
|
| | |
|
| | | public static List<String> getJDShortLinksFromText(String text) {
|
| | | String regex = "(https://u\\.jd\\.com/)[0-9A-Za-z]{1,20}";
|
| | | Pattern pattern = Pattern.compile(regex);
|
| | | Matcher m = pattern.matcher(text);
|
| | | List<String> urlList = new ArrayList<>();
|
| | | while (m.find()) {
|
| | | urlList.add(m.group());
|
| | | }
|
| | | return urlList;
|
| | | }
|
| | |
|
| | | }
|