fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java
@@ -181,7 +181,6 @@ } JSONObject root = new JSONObject(); root.put("type", 2); JSONObject data = new JSONObject(); data.put("title", text); @@ -253,8 +252,15 @@ String pddId = PinDuoDuoUtil.getPDDGoodsId(text); if (!StringUtil.isNullOrEmpty(pddId)) { PDDGoodsDetail goods = PinDuoDuoApiUtil.getGoodsDetail(Long.parseLong(pddId)); if (goods != null) if (goods != null) { commonGoods = CommonGoodsFactory.create(goods); } else { type = 4; goods = PinDuoDuoUtil.getPDDGoodsInfo("26478646158"); commonGoods = new CommonGoods(); commonGoods.setTitle(goods.getGoodsName()); commonGoods.setPicture(goods.getGoodsThumbnailUrl()); } } } } fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java
@@ -10,6 +10,7 @@ import javax.annotation.Resource; import org.springframework.cache.annotation.Cacheable; import org.springframework.core.task.TaskExecutor; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import org.yeshi.utils.tencentcloud.COSManager; @@ -68,6 +69,10 @@ @Resource private BrandShopCaheService brandShopCaheService; @Resource(name = "taskExecutor") private TaskExecutor executor; @Override public void saveObject(MultipartFile file, BrandInfo record) throws BrandInfoException { String name = record.getName(); @@ -118,6 +123,17 @@ record.setUpdateTime(new Date()); brandInfoMapper.updateByPrimaryKey(record); } if (state == 1) { executor.execute(new Runnable() { @Override public void run() { int goodsTotal = brandGoodsCaheService.addBrandGoods(record); record.setGoodsTotal(goodsTotal); brandInfoMapper.updateByPrimaryKeySelective(record); } }); } } fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoUtil.java
@@ -525,5 +525,58 @@ } return null; } public static PDDGoodsDetail getPDDGoodsInfo(String id) { try { Document doc = Jsoup.connect("http://yangkeduo.com/goods.html?goods_id=" + id) .userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36").get(); Elements els = doc.getElementsByTag("script"); for (int i = 0; i < els.size(); i++) { if (els.get(i).html().contains("window.rawData")) { String dataJS = els.get(i).html().replace("window.", "var "); dataJS += "function getData(){return JSON.stringify(rawData);}"; ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("javascript"); try { engine.eval(dataJS); if (engine instanceof Invocable) { Invocable in = (Invocable) engine; String jsonStr = in.invokeFunction("getData").toString(); JSONObject json = JSONObject.fromObject(jsonStr); JSONObject goods = json.optJSONObject("store").optJSONObject("initDataObj") .optJSONObject("goods"); String imageData = goods.optString("viewImageData"); imageData = imageData.replace("[", "").replace("]", ""); String[] images = imageData.split(","); String image = images[0].trim(); if (image.startsWith("\"")) image =image.substring(1, image.length()-1); if (image.endsWith("\"")) image =image.substring(0, image.length()-2); PDDGoodsDetail goodsDetail = new PDDGoodsDetail(); goodsDetail.setGoodsImageUrl("http:" + image); goodsDetail.setGoodsThumbnailUrl("http:" + image); goodsDetail.setGoodsName(goods.optString("goodsName")); goodsDetail.setGoodsId(goods.optLong("goodsID")); return goodsDetail; } } catch (Exception e) { e.printStackTrace(); } break; } } } catch (Exception e1) { e1.printStackTrace(); } return null; } }