From 9a78d406f8b821117c78a1bc717fe4b5813656b1 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 06 八月 2019 09:57:51 +0800 Subject: [PATCH] 首页底部推荐,详情页猜你喜欢异常保护 --- fanli/src/main/java/com/yeshi/fanli/util/jd/JDUtil.java | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/jd/JDUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/jd/JDUtil.java index 95750f4..ff47881 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/jd/JDUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/jd/JDUtil.java @@ -524,5 +524,28 @@ return null; } + + public static String getJDGoodsId(String url) { + try { + if (url.startsWith("https://item.m.jd.com/product/") || url.startsWith("http://item.m.jd.com/product/") + || url.startsWith("https://item.jd.com/") || url.startsWith("http://item.jd.com/")) { + String preUrl = url.split("\\?")[0]; + String index = preUrl.split("/")[preUrl.split("/").length - 1]; + index = index.split("\\.")[0]; + return index.trim(); + } else if (url.startsWith("https://item.m.jd.com/ware/view.action?")) { + String preUrl = url.substring(url.indexOf("?") + 1, url.length()); + String[] sts = preUrl.split("&"); + for (String st : sts) { + if (st.startsWith("wareId=")) { + return st.split("=")[1].trim(); + } + } + } + + } catch (Exception e) { + } + return null; + } } -- Gitblit v1.8.0