| | |
| | | import java.math.BigDecimal;
|
| | | import java.net.URLEncoder;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | |
|
| | | import org.jsoup.Jsoup;
|
| | |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoHead;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
|
| | | import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetail;
|
| | | 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 com.yeshi.fanli.util.TimeUtil;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
| | | *
|
| | | */
|
| | | public class DaTaoKeUtil {
|
| | |
|
| | | static final String[] commonEmojis = new String[] { "😀", // 笑嘻嘻
|
| | | "😁", // 笑嘻嘻的脸,含笑的眼睛
|
| | | "😃", // 开口笑脸
|
| | | "😄", // 开口笑脸和微笑的眼睛
|
| | | "😆", // 开口笑紧闭的眼睛
|
| | | "😉", // 眨眼表情
|
| | | "😊", // 面带微笑的眼睛
|
| | | "😋", // 品尝美味食物表情
|
| | | "😎", // 太阳镜笑脸
|
| | | "😍", // 面带心形眼睛
|
| | | "😘", // 飞吻表情
|
| | | "😗", // 亲吻表情
|
| | | "😙", // 含笑亲吻表情
|
| | | "😚", // 闭眼亲吻表情
|
| | | "☺", // 笑脸
|
| | | "😇", // 光环笑脸
|
| | | "😐", // 中性面
|
| | | "😏", // 傻笑
|
| | | "😮", // 张着嘴
|
| | | "😛", // 吐舌头
|
| | | "😜", // 吐舌头,眨眼眼
|
| | | "😝", // 闭眼吐舌头
|
| | | "👅", // 舌头
|
| | | "👄", // 口
|
| | | "👀", // 眼睛
|
| | | "❤", // 心
|
| | | "💓", // 跳动的心
|
| | | "💕", // 两颗心
|
| | | "💗", // 成长的心
|
| | | "💝", // 扎丝带的心形礼盒
|
| | | "💞", // 旋转心
|
| | | "💐", // 花束
|
| | | "🌸", // 樱花
|
| | | "🌹", // 玫瑰
|
| | | "🌺", // 槿
|
| | | "🌻", // 向日葵
|
| | | "🌼", // 开花
|
| | | "🌷", // 郁金香
|
| | | "🍇", // 葡萄
|
| | | "🍈", // 瓜
|
| | | "🍉", // 西瓜
|
| | | "🍊", // 柑橘
|
| | | "🍋", // 柠檬
|
| | | "🍌", // 香蕉
|
| | | "🍍", // 菠萝
|
| | | "🍎", // 红苹果
|
| | | "🍏", // 青苹果
|
| | | "🍐", // 梨
|
| | | "🍑", // 桃子
|
| | | "🍒", // 樱桃
|
| | | "🍓", // 草莓
|
| | | "🌿", // 枝叶
|
| | | "🍀", // 四叶草
|
| | | "🍁", // 枫叶
|
| | | "🍂", // 落叶
|
| | | "🍃", // 叶子在风中飘落
|
| | | "☘", // 三叶草(酢浆草)
|
| | | "☀", // 太阳光芒四射
|
| | | "🌞", // 太阳人脸
|
| | | "⭐", // 星星,五角星
|
| | | "🌟",// 发光的星星
|
| | | };
|
| | |
|
| | | static final String[] timeEmojis = new String[] { "🕛", // 十二点
|
| | | "🕧", // 十二点半
|
| | | "🕐", // 一点钟
|
| | | "🕜", // 一点半
|
| | | "🕑", // 两点
|
| | | "🕝", // 两点半
|
| | | "🕒", // 三点钟
|
| | | "🕞", // 三点半
|
| | | "🕓", // 四点钟
|
| | | "🕟", // 四点半
|
| | | "🕔", // 五时
|
| | | "🕠", // 五点半
|
| | | "🕕", // 六点
|
| | | "🕡", // 六点半
|
| | | "🕖", // 七点
|
| | | "🕢", // 七点半
|
| | | "🕗", // 八点
|
| | | "🕣", // 八点半
|
| | | "🕘", // 九点钟
|
| | | "🕤", // 九点半
|
| | | "🕙", // 的十点
|
| | | "🕥", // 十点半
|
| | | "🕚", // 十一点
|
| | | "🕦",// 十一点半
|
| | | };
|
| | |
|
| | | public static List<GoodsClass> goodsClasses;
|
| | | static {
|
| | |
| | | *
|
| | | * @return
|
| | | */
|
| | | public static List<TaoBaoGoodsBrief> getDingDongQiang() {
|
| | | List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
|
| | | public static List<DaTaoKeDetail> getDingDongQiang() {
|
| | | List<DaTaoKeDetail> goodsList = new ArrayList<>();
|
| | | try {
|
| | | Document doc = Jsoup.connect("http://dataoke.yeshitv.com/index.php?r=ddq/wap")
|
| | | Document doc = Jsoup.connect("http://www.dataoke.com/ddq")
|
| | | .userAgent(
|
| | | "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Mobile Safari/537.36")
|
| | | .get();
|
| | | Elements els = doc.getElementsByTag("script");
|
| | | for (int i = 0; i < els.size(); i++) {
|
| | | Element item = els.get(i);
|
| | | if (item.toString().length() > 5000) {
|
| | | String html = item.html();
|
| | | int endIndex = html.indexOf("} ;") + 1;
|
| | | int startIndex = html.indexOf("data =");
|
| | | String json = html.substring(startIndex + "data =".length(), endIndex).trim();
|
| | | JSONObject root = JSONObject.fromObject(json);
|
| | | Iterator<String> keys = root.keySet().iterator();
|
| | | List<String> ids = new ArrayList<>();
|
| | | while (keys.hasNext()) {
|
| | | String key = keys.next();
|
| | | JSONArray array = root.optJSONObject(key).optJSONArray("list");
|
| | | for (int j = 0; j < array.size(); j++) {
|
| | | if (TimeUtil.convertToTimeTemp(array.optJSONObject(j).optString("paiqi"),
|
| | | "yyyy-MM-dd HH:mm:ss") < System.currentTimeMillis())
|
| | | ids.add(array.optJSONObject(j).optString("id"));
|
| | | }
|
| | | }
|
| | | Collections.shuffle(ids);
|
| | | List<Long> goodsIdList = new ArrayList<>();
|
| | | ids.parallelStream().forEach(id -> {
|
| | | try {
|
| | | long auctionId = getAuctionId(Long.parseLong(id));
|
| | | goodsIdList.add(auctionId);
|
| | | } catch (Exception e) {
|
| | | }
|
| | | });
|
| | |
|
| | | goodsIdList.parallelStream().forEach(goods -> {
|
| | | try {
|
| | | TaoBaoGoodsBrief gds = TaoKeApiUtil.searchGoodsDetail(goods);
|
| | | if (gds != null)
|
| | | goodsList.add(gds);
|
| | | } catch (Exception e) {
|
| | |
|
| | | }
|
| | |
|
| | | });
|
| | |
|
| | | }
|
| | |
|
| | | Elements items = doc.getElementsByClass("main").get(0).getElementsByClass("clearfix").get(0)
|
| | | .getElementsByTag("li");
|
| | | for (int i = 0; i < items.size(); i++) {
|
| | | DaTaoKeDetail detail = new DaTaoKeDetail();
|
| | | String id = items.get(i).getElementsByTag("a").get(0).attr("href").split("\\?")[1].replace("id=", "");
|
| | | detail.setId(Long.parseLong(id));
|
| | | goodsList.add(detail);
|
| | | }
|
| | | } catch (Exception e) {
|
| | |
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | return goodsList;
|
| | |
|
| | | }
|
| | |
|
| | | //
|
| | |
| | | }
|
| | |
|
| | | private static List<DaTaoKeDetail> parseCurrent(String url) {
|
| | |
|
| | | List<DaTaoKeDetail> list = new ArrayList<>();
|
| | | try {
|
| | | Document doc = Jsoup.connect(url)
|
| | | .userAgent(
|
| | |
| | | .getElementsByTag("b").get(0).text();
|
| | |
|
| | | System.out.println(id + "-" + currentSale);
|
| | | DaTaoKeDetail detail = new DaTaoKeDetail();
|
| | | detail.setId(id);
|
| | | detail.setSalesNum(Integer.parseInt(currentSale));
|
| | | list.add(detail);
|
| | |
|
| | | }
|
| | |
|
| | |
| | | }
|
| | |
|
| | | // TODO 需要返回值
|
| | | return null;
|
| | | return list;
|
| | | }
|
| | |
|
| | | // 获取实时榜单
|
| | |
| | | * @param cid
|
| | | * @return
|
| | | */
|
| | | public static List<DaTaoKeDetail> getCurrentSalesRank(Long cid) {
|
| | | public static List<DaTaoKeDetail> getCurrentSalesRank(Integer cid) {
|
| | | String url = null;
|
| | | if (cid == null)
|
| | | url = "http://www.dataoke.com/top_sell";
|
| | |
| | | * @param cid
|
| | | * @return
|
| | | */
|
| | | public static List<DaTaoKeDetail> getCurrentDaySalesRank(Long cid) {
|
| | | public static List<DaTaoKeDetail> getCurrentDaySalesRank(Integer cid) {
|
| | | String url = null;
|
| | | if (cid == null)
|
| | | url = "http://www.dataoke.com/top_all";
|
| | |
| | | return parseCurrent(url);
|
| | | }
|
| | |
|
| | | private static String getRandomCommonEmoji() {
|
| | | return commonEmojis[(int) (Math.random() * commonEmojis.length)];
|
| | | }
|
| | |
|
| | | public static String getDesc(DaTaoKeDetail detail) {
|
| | |
|
| | | // 标题+券后价+包邮+描述
|
| | | String desc = detail.getdTitle();
|
| | | desc += "\n";
|
| | | desc += String.format("券后价%s【%s元】包邮秒杀 ", Math.random() > 0.5 ? "💰" : "",
|
| | | MoneyBigDecimalUtil.getWithNoZera(detail.getPrice()).toString())
|
| | | + (Math.random() > 0.5 ? getRandomCommonEmoji() : "");
|
| | | desc += "\n";
|
| | | // desc += detail.getIntroduce();
|
| | | String introduce = detail.getIntroduce().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, DaTaoKeDetail detail) {
|
| | | if (detail != null && goods != null) {
|
| | | // 重新设置标题与券价格
|
| | | goods.setTitle(detail.getdTitle());
|
| | | if (!StringUtil.isNullOrEmpty(detail.getPic()))
|
| | | goods.setPictUrlWhite(detail.getPic());
|
| | | }
|
| | | return goods;
|
| | | }
|
| | |
|
| | | 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;
|
| | | }
|
| | |
|
| | | }
|