From 42411e4a26461229c6bca6e89ca55e98a80f5a4e Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 30 九月 2021 18:08:17 +0800
Subject: [PATCH] bug修改
---
fanli/src/main/java/com/yeshi/fanli/util/taobao/DaTaoKeUtil.java | 1428 +++++++++++++++++++++++++++++++----------------------------
1 files changed, 749 insertions(+), 679 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/util/taobao/DaTaoKeUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/taobao/DaTaoKeUtil.java
index e5155e0..4281691 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/taobao/DaTaoKeUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/taobao/DaTaoKeUtil.java
@@ -1,679 +1,749 @@
-package com.yeshi.fanli.util.taobao;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.math.BigDecimal;
-import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.script.Invocable;
-import javax.script.ScriptEngine;
-import javax.script.ScriptEngineManager;
-
-import org.jsoup.Jsoup;
-import org.jsoup.nodes.Document;
-import org.jsoup.nodes.Element;
-import org.jsoup.select.Elements;
-
-import com.yeshi.fanli.dto.dataoke.DingDongQiangDTO;
-import com.yeshi.fanli.dto.dataoke.DingDongTime;
-import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
-import com.yeshi.fanli.entity.taobao.TaoBaoCoupon;
-import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
-import com.yeshi.fanli.entity.taobao.TaoBaoHead;
-import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
-import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
-import com.yeshi.fanli.tag.PageEntity;
-import com.yeshi.fanli.util.MoneyBigDecimalUtil;
-import com.yeshi.fanli.util.StringUtil;
-
-import net.sf.json.JSONArray;
-import net.sf.json.JSONObject;
-
-/**
- * 澶ф窐瀹pi鎺ュ彛
- *
- * @author Administrator
- *
- */
-public class DaTaoKeUtil {
-
- static final String[] commonEmojis = new String[] { "馃榾", // 绗戝樆鍢�
- "馃榿", // 绗戝樆鍢荤殑鑴革紝鍚瑧鐨勭溂鐫�
- "馃槂", // 寮�鍙g瑧鑴�
- "馃槃", // 寮�鍙g瑧鑴稿拰寰瑧鐨勭溂鐫�
- "馃槅", // 寮�鍙g瑧绱ч棴鐨勭溂鐫�
- "馃槈", // 鐪ㄧ溂琛ㄦ儏
- "馃槉", // 闈㈠甫寰瑧鐨勭溂鐫�
- "馃構", // 鍝佸皾缇庡懗椋熺墿琛ㄦ儏
- "馃槑", // 澶槼闀滅瑧鑴�
- "馃槏", // 闈㈠甫蹇冨舰鐪肩潧
- "馃槝", // 椋炲惢琛ㄦ儏
- "馃槜", // 浜插惢琛ㄦ儏
- "馃槞", // 鍚瑧浜插惢琛ㄦ儏
- "馃槡", // 闂溂浜插惢琛ㄦ儏
- "鈽�", // 绗戣劯
- "馃槆", // 鍏夌幆绗戣劯
- "馃槓", // 涓�ч潰
- "馃槒", // 鍌荤瑧
- "馃槷", // 寮犵潃鍢�
- "馃槢", // 鍚愯垖澶�
- "馃槣", // 鍚愯垖澶达紝鐪ㄧ溂鐪�
- "馃槤", // 闂溂鍚愯垖澶�
- "馃憛", // 鑸屽ご
- "馃憚", // 鍙�
- "馃憖", // 鐪肩潧
- "鉂�", // 蹇�
- "馃挀", // 璺冲姩鐨勫績
- "馃挄", // 涓ら蹇�
- "馃挆", // 鎴愰暱鐨勫績
- "馃挐", // 鎵庝笣甯︾殑蹇冨舰绀肩洅
- "馃挒", // 鏃嬭浆蹇�
- "馃拹", // 鑺辨潫
- "馃尭", // 妯辫姳
- "馃尮", // 鐜懓
- "馃尯", // 妲�
- "馃尰", // 鍚戞棩钁�
- "馃尲", // 寮�鑺�
- "馃尫", // 閮侀噾棣�
- "馃崌", // 钁¤悇
- "馃崍", // 鐡�
- "馃崏", // 瑗跨摐
- "馃崐", // 鏌戞
- "馃崑", // 鏌犳
- "馃崒", // 棣欒晧
- "馃崓", // 鑿犺悵
- "馃崕", // 绾㈣嫻鏋�
- "馃崗", // 闈掕嫻鏋�
- "馃崘", // 姊�
- "馃崙", // 妗冨瓙
- "馃崚", // 妯辨
- "馃崜", // 鑽夎帗
- "馃尶", // 鏋濆彾
- "馃崁", // 鍥涘彾鑽�
- "馃崄", // 鏋彾
- "馃崅", // 钀藉彾
- "馃崈", // 鍙跺瓙鍦ㄩ涓钀�
- "鈽�", // 涓夊彾鑽�(閰㈡祮鑽�)
- "鈽�", // 澶槼鍏夎姃鍥涘皠
- "馃尀", // 澶槼浜鸿劯
- "猸�", // 鏄熸槦锛屼簲瑙掓槦
- "馃専",// 鍙戝厜鐨勬槦鏄�
- };
-
- static final String[] timeEmojis = new String[] { "馃暃", // 鍗佷簩鐐�
- "馃暓", // 鍗佷簩鐐瑰崐
- "馃晲", // 涓�鐐归挓
- "馃暅", // 涓�鐐瑰崐
- "馃晳", // 涓ょ偣
- "馃暆", // 涓ょ偣鍗�
- "馃晵", // 涓夌偣閽�
- "馃暈", // 涓夌偣鍗�
- "馃晸", // 鍥涚偣閽�
- "馃暉", // 鍥涚偣鍗�
- "馃晹", // 浜旀椂
- "馃暊", // 浜旂偣鍗�
- "馃晻", // 鍏偣
- "馃暋", // 鍏偣鍗�
- "馃晼", // 涓冪偣
- "馃暍", // 涓冪偣鍗�
- "馃晽", // 鍏偣
- "馃暎", // 鍏偣鍗�
- "馃晿", // 涔濈偣閽�
- "馃暏", // 涔濈偣鍗�
- "馃暀", // 鐨勫崄鐐�
- "馃暐", // 鍗佺偣鍗�
- "馃暁", // 鍗佷竴鐐�
- "馃暒",// 鍗佷竴鐐瑰崐
- };
-
- static final String[] evaluateEmojis = new String[] {
- "馃挓",
- "馃尭",
- "馃嵏",
- "馃嵑",
- "馃摙",
- "鉂�",
- "馃挐",
- "馃拫",
- "馃憶",
- "馃惥",
- "馃尮",
- "馃敟",
- "馃帀",
- "馃巵",
- "馃崶",
- "馃嵀",
- "馃尯",
- "馃憫",
- "鉁�",
- "馃挮",
- "馃嵒",
- "馃巿",
- "馃挜",
- "馃挄",
- "馃挒",
- "馃挵",
- "馃拰",
- "馃挱",
- "馃尲",
- "馃崁"
- };
-
-
-
- public static List<GoodsClass> goodsClasses;
- static {
- goodsClasses = new ArrayList<>();
- goodsClasses.add(new GoodsClass(4L, "灞呭鏃ョ敤"));
- goodsClasses.add(new GoodsClass(6L, "缇庨"));
- goodsClasses.add(new GoodsClass(2L, "姣嶅┐"));
- goodsClasses.add(new GoodsClass(3L, "缇庡"));
- goodsClasses.add(new GoodsClass(1L, "濂宠"));
- goodsClasses.add(new GoodsClass(8L, "鏁扮爜瀹剁數"));
- goodsClasses.add(new GoodsClass(7L, "鏂囧ū杞﹀搧"));
- goodsClasses.add(new GoodsClass(10L, "鍐呰。"));
- goodsClasses.add(new GoodsClass(14L, "瀹惰瀹剁汉"));
- goodsClasses.add(new GoodsClass(5L, "闉嬪搧"));
- goodsClasses.add(new GoodsClass(9L, "鐢疯"));
- goodsClasses.add(new GoodsClass(12L, "閰嶉グ"));
- goodsClasses.add(new GoodsClass(13L, "鎴峰杩愬姩"));
- goodsClasses.add(new GoodsClass(11L, "绠卞寘"));
- }
-
- public static final String HOST = "http://dataoke.yeshitv.com";
-
- public static void search(String key) {
- String header = "Mozilla/5.0 (Linux; Android 6.0; M5 Note Build/MRA58K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043024 Safari/537.36 MicroMessenger/6.5.4.1000 NetType/WIFI Language/zh_CN";
- try {
- String searchUrl = String.format("http://dataoke.yeshitv.com/index.php?r=%s&kw=%s",
- URLEncoder.encode("index/search", "UTF-8"));
- Document root = Jsoup.connect(searchUrl).header("User-Agent", header).timeout(60000).get();
- Elements items = root.getElementsByAttributeValue("class", "goods-list").get(0)
- .getElementsByAttributeValue("class", "goods-item");
- if (items.size() > 0) {
- String code = getTKL(HOST + items.get(0).getElementsByTag("a").attr("href"));
- int count = 1;
- while (com.yeshi.fanli.util.StringUtil.isNullOrEmpty(code) && count < items.size() && count < 5) {
- code = getTKL(HOST + items.get(count).getElementsByTag("a").attr("href"));
- count++;
- }
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- // 鑾峰彇娣樺彛锟�?
- public static String getTKL(String url) {
- String header = "Mozilla/5.0 (Linux; Android 6.0; M5 Note Build/MRA58K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043024 Safari/537.36 MicroMessenger/6.5.4.1000 NetType/WIFI Language/zh_CN";
- try {
- Document root = Jsoup.connect(url).header("User-Agent", header).timeout(60000).get();
- return root.getElementsByAttributeValue("class", "tuwen-tkl").get(0)
- .getElementsByAttributeValue("class", "tkl").get(0).getElementById("code1_ios").text().trim();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public static List<GoodsClass> getGoodsType() {
- List<GoodsClass> list = new ArrayList<>();
- String[] names = new String[] { "濂宠", "鐢疯", "鍐呰。", "姣嶅┐", "鍖栧鍝�", "灞呭", "闉嬪寘閰嶉グ", "缇庨", "鏂囦綋杞﹀搧", "鏁扮爜瀹剁數" };
- int[] ids = new int[] { 1, 9, 10, 2, 3, 4, 5, 6, 7, 8 };
- for (int i = 0; i < names.length; i++) {
- GoodsClass gc = new GoodsClass();
- gc.setId(Long.parseLong(ids[i] + ""));
- gc.setName(names[i]);
- list.add(gc);
- }
- return list;
- }
-
- public static TaoBaoSearchResult getGoodsByType(int type) {
- TaoBaoSearchResult result = new TaoBaoSearchResult();
- result.setNavList(null);
- List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
- JSONArray array = getGoods("http://dataoke.yeshitv.com/index.php?r=index/cat&cid=" + type);
- for (int i = 0; i < array.size(); i++) {
- JSONObject data = array.optJSONObject(i);
- TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
- goods.setAuctionId(data.optLong("url"));
- goods.setBiz30day(data.optInt("nums"));
- goods.setPictUrl(data.optString("img").split(".jpg")[0] + ".jpg");
- goods.setCouponAmount(new BigDecimal(data.optString("quan")));
- goods.setZkPrice(new BigDecimal(data.optString("beforPrice")));
- goods.setCouponStartFee(new BigDecimal(0));
- goods.setTitle(data.optString("title"));
- goods.setTkCommFee(new BigDecimal(0));
- goods.setTkRate(new BigDecimal(0));
- goodsList.add(goods);
- }
- PageEntity pe = new PageEntity(1, 20, 1000);
- result.setPageEntity(pe);
- result.setTaoBaoGoodsBriefs(goodsList);
- TaoBaoHead head = new TaoBaoHead();
- head.setDocsfound(1000);
- result.setTaoBaoHead(head);
-
- return result;
- }
-
- public static TaoBaoSearchResult searchByKey(String kw) {
- TaoBaoSearchResult result = new TaoBaoSearchResult();
- result.setNavList(null);
- List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
- JSONArray array = null;
- try {
- array = getGoods("http://dataoke.yeshitv.com/index.php?r=l&kw=" + URLEncoder.encode(kw, "UTF-8"));
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
-
- for (int i = 0; i < array.size(); i++) {
- JSONObject data = array.optJSONObject(i);
- TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
- goods.setAuctionId(data.optLong("url"));
- goods.setBiz30day(data.optInt("nums"));
- goods.setPictUrl(data.optString("img").split(".jpg")[0] + ".jpg");
- goods.setCouponAmount(new BigDecimal(data.optString("quan")));
- goods.setZkPrice(new BigDecimal(data.optString("beforPrice")));
- goods.setCouponStartFee(new BigDecimal(0));
- goods.setTitle(data.optString("title"));
- goods.setTkCommFee(new BigDecimal(0));
- goods.setTkRate(new BigDecimal(0));
- goodsList.add(goods);
- }
- PageEntity pe = new PageEntity(1, 20, 1000);
- result.setPageEntity(pe);
- result.setTaoBaoGoodsBriefs(goodsList);
- TaoBaoHead head = new TaoBaoHead();
- head.setDocsfound(1000);
- result.setTaoBaoHead(head);
-
- return result;
- }
-
- public static JSONArray getGoods(String pageUrl) {
- if (pageUrl == null)
- return null;
-
- Document doc = null;
- try {
- doc = Jsoup.connect(pageUrl)
- .userAgent(
- "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1")
- .get();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- if (null == doc) {
- return null;
- }
-
- Elements elements = doc.getElementsByClass("goods-item");
- JSONArray jsa = new JSONArray();
-
- for (int i = 0; i < elements.size(); i++) {
- JSONObject obj = new JSONObject();
- Element element = elements.get(i);
-
- String img = element.getElementsByAttributeValue("class", "img").get(0).getElementsByTag("img").get(0)
- .attr("data-original");
- if (StringUtil.isNullOrEmpty(img))
- img = element.getElementsByAttributeValue("class", "img").get(0).getElementsByTag("img").get(0)
- .attr("src");
- if (img.startsWith("//")) {
- img = "http:" + img;
- }
- String title = element.getElementsByAttributeValue("class", "title").get(0)
- .getElementsByAttributeValue("class", "text").get(0).text();
- String price = element.getElementsByAttributeValue("class", "price-wrapper").get(0)
- .getElementsByAttributeValue("class", "price").get(0).text().replace("锟�", "");
- String coupon = element.getElementsByClass("img").get(0).getElementsByClass("coupon-wrapper").get(0)
- .getElementsByTag("b").get(0).text().replace("鍏�", "");
- String afterPrice = price + "";
- String beforePrice = Float.parseFloat(price) + Float.parseFloat(coupon) + "";
- String nums = element.getElementsByAttributeValue("class", "sold-num").get(0).text();
- String[] chars = element.getElementsByAttributeValue("class", "img").get(0).attr("href").split("id=");
- String id = chars[1].split("&u=")[0];
-
- String quanMoney = element.getElementsByClass("coupon-wrapper").get(0).getElementsByTag("b").get(0).text();
-
- obj.put("img", img);
- obj.put("title", title);
- obj.put("afterPrice", afterPrice);
- obj.put("beforPrice", beforePrice);
- obj.put("nums", nums);
- obj.put("url", id);
- obj.put("quan", quanMoney);
- jsa.add(obj);
- }
- return jsa;
- }
-
- public static long getAuctionId(long id) {
- Document doc = null;
- try {
- doc = Jsoup.connect("http://dataoke.yeshitv.com/index.php?r=p/dnew&id=" + id + "&type=0&version=2")
- .userAgent(
- "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1")
- .get();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- String href = "";
- Elements as = doc.getElementsByClass("goods_shop_cart").get(0).getElementsByTag("a");
- if (as != null)
- for (int i = 0; i < as.size(); i++) {
- if (as.get(i).attr("href").contains("uland.taobao.com/coupon/edetail")) {
- href = as.get(i).attr("href");
- break;
- }
- }
-
- String[] sts = href.split("&");
- for (String st : sts) {
- if (st.contains("itemId="))
- return Long.parseLong(st.replace("itemId=", ""));
- }
- return 0;
- }
-
- public static List<Long> get9K9List(int page) {
-
- String url = "";
-
- Document doc = null;
-
- // for (String st : sts) {
- // if (st.contains("itemId="))
- // return Long.parseLong(st.replace("itemId=", ""));
- // }
- // return 0;
- return null;
- }
-
- /**
- * 澶ф窐瀹㈠彯鍜氭姠鏁版嵁
- *
- * @return
- */
- public static List<DingDongQiangDTO> getDingDongQiang() {
- List<DingDongQiangDTO> list = new ArrayList<>();
- Document doc = null;
- try {
- doc = Jsoup.connect("http://www.dataoke.com/ddq").userAgent("").get();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- if (doc == null)
- return new ArrayList<>();
- Elements els = doc.getElementsByTag("script");
- for (int i = 0; i < els.size(); i++) {
- String content = els.get(i).html();
- if (content.indexOf("var dataDef") > -1) {
- ScriptEngineManager manager = new ScriptEngineManager();
- ScriptEngine engine = manager.getEngineByName("javascript");
- try {
- String js = "function getData(){return JSON.stringify(dataDef);} var test1='--';function test2(res){};"
- + content.replace("$(window).load", "test2").replace("window.location.search.", "test1.");
- engine.eval(js);
- if (engine instanceof Invocable) {
- Invocable in = (Invocable) engine;
- String data = in.invokeFunction("getData").toString();
- System.out.println(data);
- JSONObject dataJson = JSONObject.fromObject(data);
- for (Iterator<String> its = dataJson.keys(); its.hasNext();) {
- String key = its.next();
- JSONArray array = dataJson.optJSONArray(key);
- List<DaTaoKeDetailV2> detailList = new ArrayList<>();
- for (int n = 0; n < array.size(); n++) {
- DaTaoKeDetailV2 v2 = new DaTaoKeDetailV2();
- v2.setId(array.optJSONObject(n).optLong("id"));
- detailList.add(v2);
- }
- list.add(new DingDongQiangDTO(key, detailList));
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- return list;
- }
-
- public static List<TaoBaoCoupon> getRecommendCouple() {
- List<TaoBaoCoupon> couponList = new ArrayList<>();
-
- TaoBaoSearchResult result = new TaoBaoSearchResult();
- result.setNavList(null);
- JSONArray array = getGoods("http://dataoke.yeshitv.com/index.php?r=index/wap&u=487704");
- for (int i = 0; i < array.size(); i++) {
- JSONObject data = array.optJSONObject(i);
- TaoBaoCoupon coupon = new TaoBaoCoupon();
- coupon.setAuctionId(data.optString("url"));
- coupon.setAuctionUrl("");
- coupon.setCouponAmount(new BigDecimal(data.optString("quan")));
- coupon.setCouponCount(data.optInt("nums"));
- coupon.setCouponinfo("");
- coupon.setHongbao(new BigDecimal(0));
- coupon.setPictUrl(data.optString("img").split(".jpg")[0] + ".jpg");
- coupon.setTitle(data.optString("title"));
- coupon.setZkPrice(new BigDecimal(data.optString("beforPrice")));
- coupon.setCouponStartFee(new BigDecimal(0));
- coupon.setQuanPrice(new BigDecimal(data.optString("afterPrice")));
- couponList.add(coupon);
- }
-
- return couponList;
- }
-
- private static List<DaTaoKeDetailV2> parseCurrent(String url) {
-
- List<DaTaoKeDetailV2> list = new ArrayList<>();
- try {
- Document doc = Jsoup.connect(url)
- .userAgent(
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36")
- .get();
- Elements items = doc.getElementsByClass("goods-list").get(0).getElementsByClass("goods-item");
- for (int i = 0; i < items.size(); i++) {
- Long id = Long.parseLong(items.get(i).attr("id").replace("goods-items_", ""));
- String currentSale = items.get(i).getElementsByClass("goods-item-content").get(0)
- .getElementsByClass("goods-info").get(0).getElementsByClass("tg-show").get(0)
- .getElementsByTag("b").get(0).text();
-
- System.out.println(id + "-" + currentSale);
- DaTaoKeDetailV2 detail = new DaTaoKeDetailV2();
- detail.setId(id);
- detail.setMonthSales(Integer.parseInt(currentSale));
- list.add(detail);
-
- }
-
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- // TODO 闇�瑕佽繑鍥炲��
- return list;
- }
-
- // 鑾峰彇瀹炴椂姒滃崟
- /**
- * 鑾峰彇瀹炴椂閿�閲忔
- *
- * @param cid
- * @return
- */
- public static List<DaTaoKeDetailV2> getCurrentSalesRank(Integer cid) {
- String url = null;
- if (cid == null)
- url = "http://www.dataoke.com/top_sell";
- else
- url = String.format("http://www.dataoke.com/top_sell?cid=%s&type=1", cid);
- return parseCurrent(url);
- }
-
- /**
- * 鍏ㄥぉ閿�閲忔
- *
- * @param cid
- * @return
- */
- public static List<DaTaoKeDetailV2> getCurrentDaySalesRank(Integer cid) {
- String url = null;
- if (cid == null)
- url = "http://www.dataoke.com/top_all";
- else
- url = String.format("http://www.dataoke.com/top_all?cid=%s", cid);
- return parseCurrent(url);
- }
-
- /**
- * 鑾峰彇鐑帹姒�
- *
- * @param cid
- * @return
- */
- public static List<DaTaoKeDetailV2> getCurrentHotSalesRank() {
- String url = "http://www.dataoke.com/top_tui";
- return parseCurrent(url);
- }
-
- public static String getRandomCommonEmoji() {
- return commonEmojis[(int) (Math.random() * commonEmojis.length)];
- }
-
-
- public static String getEvaluateEmojis() {
- return evaluateEmojis[(int) (Math.random() * evaluateEmojis.length)];
- }
-
- public static String getDesc(DaTaoKeDetailV2 detail) {
-
- // 鏍囬+鍒稿悗浠�+鍖呴偖+鎻忚堪
- String desc = detail.getDtitle();
- desc += "\n";
- desc += String.format("鍒稿悗浠�%s銆�%s鍏冦�戝寘閭鏉� ", Math.random() > 0.5 ? "馃挵" : "",
- MoneyBigDecimalUtil.getWithNoZera(detail.getActualPrice() ).toString())
- + (Math.random() > 0.5 ? getRandomCommonEmoji() : "");
- desc += "\n";
- // desc += detail.getIntroduce();
- String introduce = detail.getDesc().replace("锛�", ",").replace("銆�", ",").replace("锛�", ",").replace(",",
- ",");
- introduce = introduce.replace(",,,", ",").replace(",,", ",");
-
- String[] sts = introduce.split(",");
- introduce = "";
- for (int i = 0; i < sts.length; i++) {
- if (i % 2 == 1) {// 闇�瑕佹崲琛�
- introduce += sts[i] + (Math.random() > 0.5 ? getRandomCommonEmoji() : i == sts.length - 1 ? "" : "锛�")
- + "\n";
- } else
- introduce += sts[i] + (Math.random() > 0.5 ? getRandomCommonEmoji() : i == sts.length - 1 ? "" : "锛�");
- }
- desc += introduce;
- return desc;
- }
-
-
- public static TaoBaoGoodsBrief filterTaoBaoGoods(TaoBaoGoodsBrief goods, DaTaoKeDetailV2 detail) {
- if (detail != null && goods != null) {
- // 閲嶆柊璁剧疆鏍囬涓庡埜浠锋牸
- goods.setTitle(detail.getDtitle());
- if (!StringUtil.isNullOrEmpty(detail.getMainPic()))
- goods.setPictUrlWhite(detail.getMainPic());
- }
- return goods;
- }
-
- public static DaTaoKeDetailV2 filterDaTaoKe(TaoBaoGoodsBrief goods, DaTaoKeDetailV2 detail) {
- if (goods != null) {
- BigDecimal price = TaoBaoUtil.getAfterUseCouplePrice(goods);
- detail.setOriginalPrice(goods.getZkPrice());
- detail.setActualPrice(price);
- if (goods.getCouponStartFee() != null)
- detail.setCouponConditions(goods.getCouponStartFee() + "");
- detail.setCouponPrice(goods.getCouponAmount());
- return detail;
- }
-
- return detail;
- }
-
- public static List<DingDongTime> getDingDongQiangTime(Calendar nowDate) {
-
- // 鑾峰彇褰撳墠鐨勫皬鏃舵暟
- DingDongTime[] times = new DingDongTime[] { new DingDongTime("0", "00:00"), new DingDongTime("8", "08:00"),
- new DingDongTime("10", "10:00"), new DingDongTime("13", "13:00"), new DingDongTime("15", "15:00"),
- new DingDongTime("17", "17:00"), new DingDongTime("19", "19:00"), new DingDongTime("20", "20:00"),
- new DingDongTime("21", "21:00") };
- Calendar preDate = Calendar.getInstance();
- preDate.setTimeInMillis(nowDate.getTimeInMillis() - 24 * 60 * 60 * 1000L);
-
- Calendar nextDate = Calendar.getInstance();
- nextDate.setTimeInMillis(nowDate.getTimeInMillis() + 24 * 60 * 60 * 1000L);
-
- String preDay = (preDate.get(Calendar.DAY_OF_MONTH) + "").length() < 2
- ? "0" + preDate.get(Calendar.DAY_OF_MONTH) : preDate.get(Calendar.DAY_OF_MONTH) + "";
- String nextDay = (nextDate.get(Calendar.DAY_OF_MONTH) + "").length() < 2
- ? "0" + nextDate.get(Calendar.DAY_OF_MONTH) : nextDate.get(Calendar.DAY_OF_MONTH) + "";
- String nowDay = (nowDate.get(Calendar.DAY_OF_MONTH) + "").length() < 2
- ? "0" + nowDate.get(Calendar.DAY_OF_MONTH) : nowDate.get(Calendar.DAY_OF_MONTH) + "";
-
- int hour = nowDate.get(Calendar.HOUR_OF_DAY);
- int pos = times.length - 1;
- for (int i = 0; i < times.length - 1; i++) {
- if (hour >= Integer.parseInt(times[i].getKey()) && hour < Integer.parseInt(times[i + 1].getKey())) {
- pos = i;
- break;
- }
- }
-
- List<DingDongTime> list = new ArrayList<>();
-
- // 鑾峰彇褰撳墠鏃堕棿涔嬪墠鐨�5涓暟鎹�
- for (int i = 5; i >= 0; i--) {
- int p = pos - i < 0 ? (times.length + pos - i) : pos - i;
- DingDongTime itemData = new DingDongTime(times[p].getKey(), times[p].getValue(), -1);
- if (pos - i < 0)
- itemData.setTime(
- preDay + "" + (itemData.getKey().length() < 2 ? ("0" + itemData.getKey()) : itemData.getKey()));
- else
- itemData.setTime(
- nowDay + "" + (itemData.getKey().length() < 2 ? ("0" + itemData.getKey()) : itemData.getKey()));
-
- if (pos == p)
- itemData.setState(0);
- list.add(itemData);
- }
-
- // 鍚戝悗娣诲姞鍓╀笅鐨�
- if (pos + 1 < times.length)
- for (int i = pos + 1; i < times.length; i++) {
- DingDongTime itemData = new DingDongTime(times[i].getKey(), times[i].getValue(), 1);
- itemData.setTime(
- nowDay + "" + (itemData.getKey().length() < 2 ? ("0" + itemData.getKey()) : itemData.getKey()));
- list.add(itemData);
- }
-
- if (times.length - (pos + 1) < 2) {
- DingDongTime itemData = new DingDongTime(times[0].getKey(), times[0].getValue(), 1);
- itemData.setTime(
- nextDay + "" + (itemData.getKey().length() < 2 ? ("0" + itemData.getKey()) : itemData.getKey()));
- list.add(itemData);
- }
- return list;
- }
-
-}
+package com.yeshi.fanli.util.taobao;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.script.Invocable;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+import org.yeshi.utils.HttpUtil;
+
+import com.yeshi.goods.facade.dto.taobao.dataoke.DingDongQiangDTO;
+import com.yeshi.goods.facade.dto.taobao.dataoke.DingDongTime;
+import com.yeshi.goods.facade.dto.taobao.dataoke.DaTaoKeFilterResult;
+import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
+import com.yeshi.fanli.entity.taobao.TaoBaoCoupon;
+import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
+import com.yeshi.goods.facade.entity.taobao.TaoBaoHead;
+import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
+import com.yeshi.goods.facade.entity.taobao.dataoke.DaTaoKeDetailV2;
+import com.yeshi.common.entity.PageEntity;
+import org.yeshi.utils.MoneyBigDecimalUtil;
+import com.yeshi.fanli.util.StringUtil;
+import org.yeshi.utils.TimeUtil;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+/**
+ * 澶ф窐瀹pi鎺ュ彛
+ *
+ * @author Administrator
+ *
+ */
+public class DaTaoKeUtil {
+
+ static final String[] commonEmojis = new String[] { "馃榾", // 绗戝樆鍢�
+ "馃榿", // 绗戝樆鍢荤殑鑴革紝鍚瑧鐨勭溂鐫�
+ "馃槂", // 寮�鍙g瑧鑴�
+ "馃槃", // 寮�鍙g瑧鑴稿拰寰瑧鐨勭溂鐫�
+ "馃槅", // 寮�鍙g瑧绱ч棴鐨勭溂鐫�
+ "馃槈", // 鐪ㄧ溂琛ㄦ儏
+ "馃槉", // 闈㈠甫寰瑧鐨勭溂鐫�
+ "馃構", // 鍝佸皾缇庡懗椋熺墿琛ㄦ儏
+ "馃槑", // 澶槼闀滅瑧鑴�
+ "馃槏", // 闈㈠甫蹇冨舰鐪肩潧
+ "馃槝", // 椋炲惢琛ㄦ儏
+ "馃槜", // 浜插惢琛ㄦ儏
+ "馃槞", // 鍚瑧浜插惢琛ㄦ儏
+ "馃槡", // 闂溂浜插惢琛ㄦ儏
+ "鈽�", // 绗戣劯
+ "馃槆", // 鍏夌幆绗戣劯
+ "馃槓", // 涓�ч潰
+ "馃槒", // 鍌荤瑧
+ "馃槷", // 寮犵潃鍢�
+ "馃槢", // 鍚愯垖澶�
+ "馃槣", // 鍚愯垖澶达紝鐪ㄧ溂鐪�
+ "馃槤", // 闂溂鍚愯垖澶�
+ "馃憛", // 鑸屽ご
+ "馃憚", // 鍙�
+ "馃憖", // 鐪肩潧
+ "鉂�", // 蹇�
+ "馃挀", // 璺冲姩鐨勫績
+ "馃挄", // 涓ら蹇�
+ "馃挆", // 鎴愰暱鐨勫績
+ "馃挐", // 鎵庝笣甯︾殑蹇冨舰绀肩洅
+ "馃挒", // 鏃嬭浆蹇�
+ "馃拹", // 鑺辨潫
+ "馃尭", // 妯辫姳
+ "馃尮", // 鐜懓
+ "馃尯", // 妲�
+ "馃尰", // 鍚戞棩钁�
+ "馃尲", // 寮�鑺�
+ "馃尫", // 閮侀噾棣�
+ "馃崌", // 钁¤悇
+ "馃崍", // 鐡�
+ "馃崏", // 瑗跨摐
+ "馃崐", // 鏌戞
+ "馃崑", // 鏌犳
+ "馃崒", // 棣欒晧
+ "馃崓", // 鑿犺悵
+ "馃崕", // 绾㈣嫻鏋�
+ "馃崗", // 闈掕嫻鏋�
+ "馃崘", // 姊�
+ "馃崙", // 妗冨瓙
+ "馃崚", // 妯辨
+ "馃崜", // 鑽夎帗
+ "馃尶", // 鏋濆彾
+ "馃崁", // 鍥涘彾鑽�
+ "馃崄", // 鏋彾
+ "馃崅", // 钀藉彾
+ "馃崈", // 鍙跺瓙鍦ㄩ涓钀�
+ "鈽�", // 涓夊彾鑽�(閰㈡祮鑽�)
+ "鈽�", // 澶槼鍏夎姃鍥涘皠
+ "馃尀", // 澶槼浜鸿劯
+ "猸�", // 鏄熸槦锛屼簲瑙掓槦
+ "馃専",// 鍙戝厜鐨勬槦鏄�
+ };
+
+ static final String[] timeEmojis = new String[] { "馃暃", // 鍗佷簩鐐�
+ "馃暓", // 鍗佷簩鐐瑰崐
+ "馃晲", // 涓�鐐归挓
+ "馃暅", // 涓�鐐瑰崐
+ "馃晳", // 涓ょ偣
+ "馃暆", // 涓ょ偣鍗�
+ "馃晵", // 涓夌偣閽�
+ "馃暈", // 涓夌偣鍗�
+ "馃晸", // 鍥涚偣閽�
+ "馃暉", // 鍥涚偣鍗�
+ "馃晹", // 浜旀椂
+ "馃暊", // 浜旂偣鍗�
+ "馃晻", // 鍏偣
+ "馃暋", // 鍏偣鍗�
+ "馃晼", // 涓冪偣
+ "馃暍", // 涓冪偣鍗�
+ "馃晽", // 鍏偣
+ "馃暎", // 鍏偣鍗�
+ "馃晿", // 涔濈偣閽�
+ "馃暏", // 涔濈偣鍗�
+ "馃暀", // 鐨勫崄鐐�
+ "馃暐", // 鍗佺偣鍗�
+ "馃暁", // 鍗佷竴鐐�
+ "馃暒",// 鍗佷竴鐐瑰崐
+ };
+
+ static final String[] evaluateEmojis = new String[] { "馃挓", "馃尭", "馃嵏", "馃嵑", "馃摙", "鉂�", "馃挐", "馃拫", "馃憶", "馃惥",
+ "馃尮", "馃敟", "馃帀", "馃巵", "馃崶", "馃嵀", "馃尯", "馃憫", "鉁�", "馃挮", "馃嵒", "馃巿", "馃挜", "馃挄", "馃挒", "馃挵", "馃拰", "馃挱",
+ "馃尲", "馃崁" };
+
+ public static List<GoodsClass> goodsClasses;
+ static {
+ goodsClasses = new ArrayList<>();
+ goodsClasses.add(new GoodsClass(4L, "灞呭鏃ョ敤"));
+ goodsClasses.add(new GoodsClass(6L, "缇庨"));
+ goodsClasses.add(new GoodsClass(2L, "姣嶅┐"));
+ goodsClasses.add(new GoodsClass(3L, "缇庡"));
+ goodsClasses.add(new GoodsClass(1L, "濂宠"));
+ goodsClasses.add(new GoodsClass(8L, "鏁扮爜瀹剁數"));
+ goodsClasses.add(new GoodsClass(7L, "鏂囧ū杞﹀搧"));
+ goodsClasses.add(new GoodsClass(10L, "鍐呰。"));
+ goodsClasses.add(new GoodsClass(14L, "瀹惰瀹剁汉"));
+ goodsClasses.add(new GoodsClass(5L, "闉嬪搧"));
+ goodsClasses.add(new GoodsClass(9L, "鐢疯"));
+ goodsClasses.add(new GoodsClass(12L, "閰嶉グ"));
+ goodsClasses.add(new GoodsClass(13L, "鎴峰杩愬姩"));
+ goodsClasses.add(new GoodsClass(11L, "绠卞寘"));
+ }
+
+ public static final String HOST = "http://dataoke.yeshitv.com";
+
+ public static void search(String key) {
+ String header = "Mozilla/5.0 (Linux; Android 6.0; M5 Note Build/MRA58K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043024 Safari/537.36 MicroMessenger/6.5.4.1000 NetType/WIFI Language/zh_CN";
+ try {
+ String searchUrl = String.format("http://dataoke.yeshitv.com/index.php?r=%s&kw=%s",
+ URLEncoder.encode("index/search", "UTF-8"));
+ Document root = Jsoup.connect(searchUrl).header("User-Agent", header).timeout(60000).get();
+ Elements items = root.getElementsByAttributeValue("class", "goods-list").get(0)
+ .getElementsByAttributeValue("class", "goods-item");
+ if (items.size() > 0) {
+ String code = getTKL(HOST + items.get(0).getElementsByTag("a").attr("href"));
+ int count = 1;
+ while (com.yeshi.fanli.util.StringUtil.isNullOrEmpty(code) && count < items.size() && count < 5) {
+ code = getTKL(HOST + items.get(count).getElementsByTag("a").attr("href"));
+ count++;
+ }
+ }
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ // 鑾峰彇娣樺彛锟�?
+ public static String getTKL(String url) {
+ String header = "Mozilla/5.0 (Linux; Android 6.0; M5 Note Build/MRA58K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043024 Safari/537.36 MicroMessenger/6.5.4.1000 NetType/WIFI Language/zh_CN";
+ try {
+ Document root = Jsoup.connect(url).header("User-Agent", header).timeout(60000).get();
+ return root.getElementsByAttributeValue("class", "tuwen-tkl").get(0)
+ .getElementsByAttributeValue("class", "tkl").get(0).getElementById("code1_ios").text().trim();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static List<GoodsClass> getGoodsType() {
+ List<GoodsClass> list = new ArrayList<>();
+ String[] names = new String[] { "濂宠", "鐢疯", "鍐呰。", "姣嶅┐", "鍖栧鍝�", "灞呭", "闉嬪寘閰嶉グ", "缇庨", "鏂囦綋杞﹀搧", "鏁扮爜瀹剁數" };
+ int[] ids = new int[] { 1, 9, 10, 2, 3, 4, 5, 6, 7, 8 };
+ for (int i = 0; i < names.length; i++) {
+ GoodsClass gc = new GoodsClass();
+ gc.setId(Long.parseLong(ids[i] + ""));
+ gc.setName(names[i]);
+ list.add(gc);
+ }
+ return list;
+ }
+
+ public static TaoBaoSearchResult getGoodsByType(int type) {
+ TaoBaoSearchResult result = new TaoBaoSearchResult();
+ result.setNavList(null);
+ List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+ JSONArray array = getGoods("http://dataoke.yeshitv.com/index.php?r=index/cat&cid=" + type);
+ for (int i = 0; i < array.size(); i++) {
+ JSONObject data = array.optJSONObject(i);
+ TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
+ goods.setAuctionId(data.optLong("url"));
+ goods.setBiz30day(data.optInt("nums"));
+ goods.setPictUrl(data.optString("img").split(".jpg")[0] + ".jpg");
+ goods.setCouponAmount(new BigDecimal(data.optString("quan")));
+ goods.setZkPrice(new BigDecimal(data.optString("beforPrice")));
+ goods.setCouponStartFee(new BigDecimal(0));
+ goods.setTitle(data.optString("title"));
+ goods.setTkCommFee(new BigDecimal(0));
+ goods.setTkRate(new BigDecimal(0));
+ goodsList.add(goods);
+ }
+ PageEntity pe = new PageEntity(1, 20, 1000);
+ result.setPageEntity(pe);
+ result.setTaoBaoGoodsBriefs(goodsList);
+ TaoBaoHead head = new TaoBaoHead();
+ head.setDocsfound(1000);
+ result.setTaoBaoHead(head);
+
+ return result;
+ }
+
+ public static TaoBaoSearchResult searchByKey(String kw) {
+ TaoBaoSearchResult result = new TaoBaoSearchResult();
+ result.setNavList(null);
+ List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+ JSONArray array = null;
+ try {
+ array = getGoods("http://dataoke.yeshitv.com/index.php?r=l&kw=" + URLEncoder.encode(kw, "UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+
+ for (int i = 0; i < array.size(); i++) {
+ JSONObject data = array.optJSONObject(i);
+ TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
+ goods.setAuctionId(data.optLong("url"));
+ goods.setBiz30day(data.optInt("nums"));
+ goods.setPictUrl(data.optString("img").split(".jpg")[0] + ".jpg");
+ goods.setCouponAmount(new BigDecimal(data.optString("quan")));
+ goods.setZkPrice(new BigDecimal(data.optString("beforPrice")));
+ goods.setCouponStartFee(new BigDecimal(0));
+ goods.setTitle(data.optString("title"));
+ goods.setTkCommFee(new BigDecimal(0));
+ goods.setTkRate(new BigDecimal(0));
+ goodsList.add(goods);
+ }
+ PageEntity pe = new PageEntity(1, 20, 1000);
+ result.setPageEntity(pe);
+ result.setTaoBaoGoodsBriefs(goodsList);
+ TaoBaoHead head = new TaoBaoHead();
+ head.setDocsfound(1000);
+ result.setTaoBaoHead(head);
+
+ return result;
+ }
+
+ public static JSONArray getGoods(String pageUrl) {
+ if (pageUrl == null)
+ return null;
+
+ Document doc = null;
+ try {
+ doc = Jsoup.connect(pageUrl)
+ .userAgent(
+ "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1")
+ .get();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ if (null == doc) {
+ return null;
+ }
+
+ Elements elements = doc.getElementsByClass("goods-item");
+ JSONArray jsa = new JSONArray();
+
+ for (int i = 0; i < elements.size(); i++) {
+ JSONObject obj = new JSONObject();
+ Element element = elements.get(i);
+
+ String img = element.getElementsByAttributeValue("class", "img").get(0).getElementsByTag("img").get(0)
+ .attr("data-original");
+ if (StringUtil.isNullOrEmpty(img))
+ img = element.getElementsByAttributeValue("class", "img").get(0).getElementsByTag("img").get(0)
+ .attr("src");
+ if (img.startsWith("//")) {
+ img = "http:" + img;
+ }
+ String title = element.getElementsByAttributeValue("class", "title").get(0)
+ .getElementsByAttributeValue("class", "text").get(0).text();
+ String price = element.getElementsByAttributeValue("class", "price-wrapper").get(0)
+ .getElementsByAttributeValue("class", "price").get(0).text().replace("锟�", "");
+ String coupon = element.getElementsByClass("img").get(0).getElementsByClass("coupon-wrapper").get(0)
+ .getElementsByTag("b").get(0).text().replace("鍏�", "");
+ String afterPrice = price + "";
+ String beforePrice = Float.parseFloat(price) + Float.parseFloat(coupon) + "";
+ String nums = element.getElementsByAttributeValue("class", "sold-num").get(0).text();
+ String[] chars = element.getElementsByAttributeValue("class", "img").get(0).attr("href").split("id=");
+ String id = chars[1].split("&u=")[0];
+
+ String quanMoney = element.getElementsByClass("coupon-wrapper").get(0).getElementsByTag("b").get(0).text();
+
+ obj.put("img", img);
+ obj.put("title", title);
+ obj.put("afterPrice", afterPrice);
+ obj.put("beforPrice", beforePrice);
+ obj.put("nums", nums);
+ obj.put("url", id);
+ obj.put("quan", quanMoney);
+ jsa.add(obj);
+ }
+ return jsa;
+ }
+
+ public static long getAuctionId(long id) {
+ Document doc = null;
+ try {
+ doc = Jsoup.connect("http://dataoke.yeshitv.com/index.php?r=p/dnew&id=" + id + "&type=0&version=2")
+ .userAgent(
+ "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1")
+ .get();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ String href = "";
+ Elements as = doc.getElementsByClass("goods_shop_cart").get(0).getElementsByTag("a");
+ if (as != null)
+ for (int i = 0; i < as.size(); i++) {
+ if (as.get(i).attr("href").contains("uland.taobao.com/coupon/edetail")) {
+ href = as.get(i).attr("href");
+ break;
+ }
+ }
+
+ String[] sts = href.split("&");
+ for (String st : sts) {
+ if (st.contains("itemId="))
+ return Long.parseLong(st.replace("itemId=", ""));
+ }
+ return 0;
+ }
+
+ public static List<Long> get9K9List(int page) {
+
+ String url = "";
+
+ Document doc = null;
+
+ // for (String st : sts) {
+ // if (st.contains("itemId="))
+ // return Long.parseLong(st.replace("itemId=", ""));
+ // }
+ // return 0;
+ return null;
+ }
+
+ /**
+ * 澶ф窐瀹㈠彯鍜氭姠鏁版嵁
+ *
+ * @return
+ */
+ public static List<DingDongQiangDTO> getDingDongQiang() {
+ List<DingDongQiangDTO> list = new ArrayList<>();
+ Document doc = null;
+ try {
+ doc = Jsoup.connect("http://www.dataoke.com/ddq").userAgent("").get();
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+ if (doc == null)
+ return new ArrayList<>();
+ Elements els = doc.getElementsByTag("script");
+ for (int i = 0; i < els.size(); i++) {
+ String content = els.get(i).html();
+ if (content.indexOf("var dataDef") > -1) {
+ ScriptEngineManager manager = new ScriptEngineManager();
+ ScriptEngine engine = manager.getEngineByName("javascript");
+ try {
+ String js = "function getData(){return JSON.stringify(dataDef);} var test1='--';function test2(res){};"
+ + content.replace("$(window).load", "test2").replace("window.location.search.", "test1.");
+ engine.eval(js);
+ if (engine instanceof Invocable) {
+ Invocable in = (Invocable) engine;
+ String data = in.invokeFunction("getData").toString();
+ System.out.println(data);
+ JSONObject dataJson = JSONObject.fromObject(data);
+ for (Iterator<String> its = dataJson.keys(); its.hasNext();) {
+ String key = its.next();
+ JSONArray array = dataJson.optJSONArray(key);
+ List<DaTaoKeDetailV2> detailList = new ArrayList<>();
+ for (int n = 0; n < array.size(); n++) {
+ DaTaoKeDetailV2 v2 = new DaTaoKeDetailV2();
+ v2.setId(array.optJSONObject(n).optLong("id"));
+ detailList.add(v2);
+ }
+ list.add(new DingDongQiangDTO(key, detailList));
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return list;
+ }
+
+ public static List<TaoBaoCoupon> getRecommendCouple() {
+ List<TaoBaoCoupon> couponList = new ArrayList<>();
+
+ TaoBaoSearchResult result = new TaoBaoSearchResult();
+ result.setNavList(null);
+ JSONArray array = getGoods("http://dataoke.yeshitv.com/index.php?r=index/wap&u=487704");
+ for (int i = 0; i < array.size(); i++) {
+ JSONObject data = array.optJSONObject(i);
+ TaoBaoCoupon coupon = new TaoBaoCoupon();
+ coupon.setAuctionId(data.optString("url"));
+ coupon.setAuctionUrl("");
+ coupon.setCouponAmount(new BigDecimal(data.optString("quan")));
+ coupon.setCouponCount(data.optInt("nums"));
+ coupon.setCouponinfo("");
+ coupon.setHongbao(new BigDecimal(0));
+ coupon.setPictUrl(data.optString("img").split(".jpg")[0] + ".jpg");
+ coupon.setTitle(data.optString("title"));
+ coupon.setZkPrice(new BigDecimal(data.optString("beforPrice")));
+ coupon.setCouponStartFee(new BigDecimal(0));
+ coupon.setQuanPrice(new BigDecimal(data.optString("afterPrice")));
+ couponList.add(coupon);
+ }
+
+ return couponList;
+ }
+
+ private static List<DaTaoKeDetailV2> parseCurrent(String url) {
+
+ List<DaTaoKeDetailV2> list = new ArrayList<>();
+ try {
+ Document doc = Jsoup.connect(url)
+ .userAgent(
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36")
+ .get();
+ Elements items = doc.getElementsByClass("goods-list").get(0).getElementsByClass("goods-item");
+ for (int i = 0; i < items.size(); i++) {
+ Long id = Long.parseLong(items.get(i).attr("id").replace("goods-items_", ""));
+ String currentSale = items.get(i).getElementsByClass("goods-item-content").get(0)
+ .getElementsByClass("goods-info").get(0).getElementsByClass("tg-show").get(0)
+ .getElementsByTag("b").get(0).text();
+
+ System.out.println(id + "-" + currentSale);
+ DaTaoKeDetailV2 detail = new DaTaoKeDetailV2();
+ detail.setId(id);
+ detail.setMonthSales(Integer.parseInt(currentSale));
+ list.add(detail);
+
+ }
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ // TODO 闇�瑕佽繑鍥炲��
+ return list;
+ }
+
+ // 鑾峰彇瀹炴椂姒滃崟
+ /**
+ * 鑾峰彇瀹炴椂閿�閲忔
+ *
+ * @param cid
+ * @return
+ */
+ public static List<DaTaoKeDetailV2> getCurrentSalesRank(Integer cid) {
+ String url = null;
+ if (cid == null)
+ url = "http://www.dataoke.com/top_sell";
+ else
+ url = String.format("http://www.dataoke.com/top_sell?cid=%s&type=1", cid);
+ return parseCurrent(url);
+ }
+
+ /**
+ * 鍏ㄥぉ閿�閲忔
+ *
+ * @param cid
+ * @return
+ */
+ public static List<DaTaoKeDetailV2> getCurrentDaySalesRank(Integer cid) {
+ String url = null;
+ if (cid == null)
+ url = "http://www.dataoke.com/top_all";
+ else
+ url = String.format("http://www.dataoke.com/top_all?cid=%s", cid);
+ return parseCurrent(url);
+ }
+
+ /**
+ * 鑾峰彇鐑帹姒�
+ *
+ * @param cid
+ * @return
+ */
+ public static List<DaTaoKeDetailV2> getCurrentHotSalesRank() {
+ String url = "http://www.dataoke.com/top_tui";
+ return parseCurrent(url);
+ }
+
+ public static String getRandomCommonEmoji() {
+ return commonEmojis[(int) (Math.random() * commonEmojis.length)];
+ }
+
+ public static String getEvaluateEmojis() {
+ return evaluateEmojis[(int) (Math.random() * evaluateEmojis.length)];
+ }
+
+ public static String getDesc(DaTaoKeDetailV2 detail) {
+
+ // 鏍囬+鍒稿悗浠�+鍖呴偖+鎻忚堪
+ String desc = detail.getDtitle();
+ desc += "\n";
+ desc += String.format("鍒稿悗浠�%s銆�%s鍏冦�戝寘閭鏉� ", Math.random() > 0.5 ? "馃挵" : "",
+ MoneyBigDecimalUtil.getWithNoZera(detail.getActualPrice()).toString())
+ + (Math.random() > 0.5 ? getRandomCommonEmoji() : "");
+ desc += "\n";
+ // desc += detail.getIntroduce();
+ String introduce = detail.getDesc().replace("锛�", ",").replace("銆�", ",").replace("锛�", ",").replace(",", ",");
+ introduce = introduce.replace(",,,", ",").replace(",,", ",");
+
+ String[] sts = introduce.split(",");
+ introduce = "";
+ for (int i = 0; i < sts.length; i++) {
+ if (i % 2 == 1) {// 闇�瑕佹崲琛�
+ introduce += sts[i] + (Math.random() > 0.5 ? getRandomCommonEmoji() : i == sts.length - 1 ? "" : "锛�")
+ + "\n";
+ } else
+ introduce += sts[i] + (Math.random() > 0.5 ? getRandomCommonEmoji() : i == sts.length - 1 ? "" : "锛�");
+ }
+ desc += introduce;
+ return desc;
+ }
+
+ public static DaTaoKeFilterResult filterTaoBaoGoods(TaoBaoGoodsBrief goods, DaTaoKeDetailV2 v2,
+ boolean filterCouponInfo) {
+ if (v2 != null && goods != null) {
+ // 閲嶆柊璁剧疆鏍囬涓庡埜浠锋牸
+ goods.setTitle(v2.getDtitle());
+ if (!StringUtil.isNullOrEmpty(v2.getMainPic()))
+ goods.setPictUrlWhite(v2.getMainPic());
+ // 璁剧疆绠�浠�
+
+ goods.setDescription(v2.getDesc());
+ // 濡傛灉娌℃湁鍒镐俊鎭�,鍒欐彁渚涘埜淇℃伅
+ if (canFilterCouponInfo(goods, v2)) {
+ try {
+ long time = System.currentTimeMillis();
+ // 鍒稿湪鏈夋晥鏈熷唴骞朵笖杩樻湁鍓╀綑鍒�
+ if (time >= TimeUtil.convertToTimeTemp(v2.getCouponStartTime(), "yyyy-MM-dd HH:mm:ss")
+ && time <= TimeUtil.convertToTimeTemp(v2.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss")
+ && (v2.getCouponTotalNum() - v2.getCouponReceiveNum()) > 0) {
+ goods.setCouponStartFee(v2.getOriginalPrice());
+
+ goods.setCouponEffectiveEndTime(TimeUtil.getGernalTime(
+ TimeUtil.convertToTimeTemp(v2.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss"),
+ "yyyy-MM-dd"));
+ goods.setCouponEffectiveStartTime(TimeUtil.getGernalTime(
+ TimeUtil.convertToTimeTemp(v2.getCouponStartTime(), "yyyy-MM-dd HH:mm:ss"),
+ "yyyy-MM-dd"));
+
+ goods.setCouponAmount(v2.getCouponPrice());
+ goods.setCouponInfo(
+ String.format("婊�%s鍏冨噺%s鍏�", v2.getOriginalPrice() + "", v2.getCouponPrice() + ""));
+ goods.setCouponLeftCount(v2.getCouponTotalNum() - v2.getCouponReceiveNum());
+ goods.setCouponLink(v2.getCouponLink());
+ goods.setCouponTotalCount(v2.getCouponTotalNum());
+ goods.setShopCoupon(false);
+ goods.setZkPrice(v2.getOriginalPrice());
+ return new DaTaoKeFilterResult(goods, DaTaoKeFilterResult.FILTER_TYPE_PRICE_AND_COUPON);
+ }
+
+ } catch (Exception e) {
+
+ }
+ } else {// 閮芥湁鍒�
+ long time = System.currentTimeMillis();
+ // 鍒稿湪鏈夋晥鏈熷唴骞朵笖杩樻湁鍓╀綑鍒�
+ if (time >= TimeUtil.convertToTimeTemp(v2.getCouponStartTime(), "yyyy-MM-dd HH:mm:ss")
+ && time <= TimeUtil.convertToTimeTemp(v2.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss")
+ && (v2.getCouponTotalNum() - v2.getCouponReceiveNum()) > 0) {
+ // 濡傛灉涓や釜鍒哥殑闈㈤涓�鏍凤紝娣樺疂鍘熶环姣斿ぇ娣樺鍘熶环楂橈紝灏变互澶ф窐瀹㈠師浠蜂负鍑�
+ if (goods.getCouponAmount() != null && v2.getCouponPrice() != null
+ && goods.getCouponAmount().compareTo(v2.getCouponPrice()) == 0) {
+
+ if (goods.getZkPrice().compareTo(v2.getOriginalPrice()) > 0) {
+ goods.setZkPrice(v2.getOriginalPrice());
+ return new DaTaoKeFilterResult(goods, DaTaoKeFilterResult.FILTER_TYPE_PRICE);
+ }
+ }
+ }
+ }
+ }
+ return new DaTaoKeFilterResult(goods, DaTaoKeFilterResult.FILTER_TYPE_NONE);
+ }
+
+ /**
+ * 鏄惁鍙互杩囨护鎺夊埜淇℃伅
+ * @Title: filterCouponInfo
+ * @Description:
+ * @param goods
+ * @param v2
+ * void 杩斿洖绫诲瀷
+ * @throws
+ */
+ public static boolean canFilterCouponInfo(TaoBaoGoodsBrief goods, DaTaoKeDetailV2 v2) {
+ if (StringUtil.isNullOrEmpty(goods.getCouponInfo()) && v2 != null
+ && !StringUtil.isNullOrEmpty(v2.getCouponLink())) {
+ try {
+ long time = System.currentTimeMillis();
+ // 鍒稿湪鏈夋晥鏈熷唴骞朵笖杩樻湁鍓╀綑鍒�
+ if (time >= TimeUtil.convertToTimeTemp(v2.getCouponStartTime(), "yyyy-MM-dd HH:mm:ss")
+ && time <= TimeUtil.convertToTimeTemp(v2.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss")
+ && (v2.getCouponTotalNum() - v2.getCouponReceiveNum()) > 0) {
+ return true;
+ }
+
+ } catch (Exception e) {
+
+ }
+ }
+
+ return false;
+ }
+
+ public static TaoBaoGoodsBrief filterTaoBaoGoods(TaoBaoGoodsBrief goods, DaTaoKeDetailV2 v2) {
+ return filterTaoBaoGoods(goods, v2, false).getGoods();
+ }
+
+ public static DaTaoKeDetailV2 filterDaTaoKe(TaoBaoGoodsBrief goods, DaTaoKeDetailV2 detail) {
+ if (goods != null) {
+ BigDecimal price = TaoBaoUtil.getCouponPrice(goods);
+ detail.setOriginalPrice(goods.getZkPrice());
+ detail.setActualPrice(price);
+ if (goods.getCouponStartFee() != null)
+ detail.setCouponConditions(goods.getCouponStartFee() + "");
+ detail.setCouponPrice(goods.getCouponAmount());
+ return detail;
+ }
+
+ return detail;
+ }
+
+ public static List<DingDongTime> getDingDongQiangTime(Calendar nowDate) {
+
+ // 鑾峰彇褰撳墠鐨勫皬鏃舵暟
+ DingDongTime[] times = new DingDongTime[] { new DingDongTime("0", "00:00"), new DingDongTime("8", "08:00"),
+ new DingDongTime("10", "10:00"), new DingDongTime("13", "13:00"), new DingDongTime("15", "15:00"),
+ new DingDongTime("17", "17:00"), new DingDongTime("19", "19:00"), new DingDongTime("20", "20:00"),
+ new DingDongTime("21", "21:00") };
+ Calendar preDate = Calendar.getInstance();
+ preDate.setTimeInMillis(nowDate.getTimeInMillis() - 24 * 60 * 60 * 1000L);
+
+ Calendar nextDate = Calendar.getInstance();
+ nextDate.setTimeInMillis(nowDate.getTimeInMillis() + 24 * 60 * 60 * 1000L);
+
+ String preDay = (preDate.get(Calendar.DAY_OF_MONTH) + "").length() < 2
+ ? "0" + preDate.get(Calendar.DAY_OF_MONTH) : preDate.get(Calendar.DAY_OF_MONTH) + "";
+ String nextDay = (nextDate.get(Calendar.DAY_OF_MONTH) + "").length() < 2
+ ? "0" + nextDate.get(Calendar.DAY_OF_MONTH) : nextDate.get(Calendar.DAY_OF_MONTH) + "";
+ String nowDay = (nowDate.get(Calendar.DAY_OF_MONTH) + "").length() < 2
+ ? "0" + nowDate.get(Calendar.DAY_OF_MONTH) : nowDate.get(Calendar.DAY_OF_MONTH) + "";
+
+ int hour = nowDate.get(Calendar.HOUR_OF_DAY);
+ int pos = times.length - 1;
+ for (int i = 0; i < times.length - 1; i++) {
+ if (hour >= Integer.parseInt(times[i].getKey()) && hour < Integer.parseInt(times[i + 1].getKey())) {
+ pos = i;
+ break;
+ }
+ }
+
+ List<DingDongTime> list = new ArrayList<>();
+
+ // 鑾峰彇褰撳墠鏃堕棿涔嬪墠鐨�5涓暟鎹�
+ for (int i = 5; i >= 0; i--) {
+ int p = pos - i < 0 ? (times.length + pos - i) : pos - i;
+ DingDongTime itemData = new DingDongTime(times[p].getKey(), times[p].getValue(), -1);
+ if (pos - i < 0)
+ itemData.setTime(
+ preDay + "" + (itemData.getKey().length() < 2 ? ("0" + itemData.getKey()) : itemData.getKey()));
+ else
+ itemData.setTime(
+ nowDay + "" + (itemData.getKey().length() < 2 ? ("0" + itemData.getKey()) : itemData.getKey()));
+
+ if (pos == p)
+ itemData.setState(0);
+ list.add(itemData);
+ }
+
+ // 鍚戝悗娣诲姞鍓╀笅鐨�
+ if (pos + 1 < times.length)
+ for (int i = pos + 1; i < times.length; i++) {
+ DingDongTime itemData = new DingDongTime(times[i].getKey(), times[i].getValue(), 1);
+ itemData.setTime(
+ nowDay + "" + (itemData.getKey().length() < 2 ? ("0" + itemData.getKey()) : itemData.getKey()));
+ list.add(itemData);
+ }
+
+ if (times.length - (pos + 1) < 2) {
+ DingDongTime itemData = new DingDongTime(times[0].getKey(), times[0].getValue(), 1);
+ itemData.setTime(
+ nextDay + "" + (itemData.getKey().length() < 2 ? ("0" + itemData.getKey()) : itemData.getKey()));
+ list.add(itemData);
+ }
+ return list;
+ }
+
+ // 鑾峰彇鎺ㄥ箍鏂囨
+ public static void getPublishDoc(String id) {
+ String url = String.format("http://www.dataoke.com/detailtpl?gid=%s&type=1", id);
+ String response = HttpUtil.get(url);
+ try {
+ JSONObject json = JSONObject.fromObject(new String(response.getBytes("ISO-8859-1"), "UTF-8"));
+ JSONObject data = json.optJSONObject("data");
+ String tpl2 = data.optString("tpl2");
+ tpl2 = tpl2.substring(0, tpl2.indexOf("---------"));
+ System.out.println(tpl2.replace("</br>", "\n").trim());
+ } catch (Exception e) {
+
+ }
+
+ }
+
+}
--
Gitblit v1.8.0