| | |
| | | import java.net.URLDecoder;
|
| | | import java.net.URLEncoder;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
| | | import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
|
| | | import org.apache.commons.httpclient.methods.GetMethod;
|
| | | import org.apache.commons.httpclient.params.HttpMethodParams;
|
| | | import org.hibernate.cache.spi.NaturalIdCacheKey;
|
| | | import org.jsoup.Connection;
|
| | | import org.jsoup.Jsoup;
|
| | | import org.jsoup.nodes.Document;
|
| | |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoShop;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
|
| | | import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetail;
|
| | | import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | |
| | | import com.yeshi.fanli.util.TaoBaoConstant;
|
| | | import com.yeshi.fanli.util.TaoBaoHttpUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
| | | // labels.add(new ClientTextStyleVO("标签内容", "#00FF00"));
|
| | | // tg.setLabels(labels);
|
| | | // }
|
| | | return tg;
|
| | | return loadYuShouInfo(tg, tb);
|
| | | }
|
| | |
|
| | | private static TaoBaoGoodsBriefExtra loadYuShouInfo(TaoBaoGoodsBriefExtra extra, TaoBaoGoodsBrief goods) {
|
| | | if (goods != null && extra != null) {
|
| | | if (isYUShou(goods)) {// 预售商品
|
| | | // extra.setZkPrice(new BigDecimal(goods.getPresaleDeposit()));
|
| | | // 预售
|
| | | if (extra.getLabels() == null)
|
| | | extra.setLabels(new ArrayList<>());
|
| | | extra.getLabels().add(new ClientTextStyleVO("预售", "#FF2B4E"));
|
| | | }
|
| | | }
|
| | | return extra;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 是否为预售商品
|
| | | * |
| | | * @param goods
|
| | | * @return
|
| | | */
|
| | | public static boolean isYUShou(TaoBaoGoodsBrief goods) {
|
| | | if (!StringUtil.isNullOrEmpty(goods.getPresaleDeposit())
|
| | | && !StringUtil.isNullOrEmpty(goods.getPresaleStartTime())
|
| | | && !StringUtil.isNullOrEmpty(goods.getPresaleEndTime())) {
|
| | | long startTime = Long.parseLong(goods.getPresaleStartTime());
|
| | | long endTime = Long.parseLong(goods.getPresaleEndTime());
|
| | | long now = System.currentTimeMillis();
|
| | | if (now >= startTime && now < endTime) {
|
| | | return true;
|
| | | }
|
| | | }
|
| | |
|
| | | return false;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | return tg;
|
| | | }
|
| | |
|
| | | public static TaoBaoGoodsBrief getTaoBaoGoodsBrief(String id) {
|
| | | Map<String, String> params = new HashMap<String, String>();
|
| | | params.put("q", String.format("http://item.taobao.com/item.htm?id=%s", id));
|
| | | params.put("_t", System.currentTimeMillis() + "");
|
| | | params.put("auctionTag", "");
|
| | | params.put("perPageSize", 40 + "");
|
| | | params.put("t", System.currentTimeMillis() + "");
|
| | | String result = TaoBaoHttpUtil.get(SEARCH_URL, params);
|
| | | result = result.replace("</span>", "").replace("<span class=H>", "");
|
| | | TaoBaoSearchResult presult = parseTaoBao(result);
|
| | | if (presult != null && presult.getTaoBaoGoodsBriefs().size() > 0) {
|
| | | // TaoBaoGoodsBrief taoBaoGoodsBrief =
|
| | | // presult.getTaoBaoGoodsBriefs().get(0);
|
| | |
|
| | | return presult.getTaoBaoGoodsBriefs().get(0);
|
| | | } else
|
| | | return null;
|
| | | /**
|
| | | * 获取未参与推广的淘宝商品详情
|
| | | * @Title: getTaoBaoGoodsBrief
|
| | | * @Description: |
| | | * @param id
|
| | | * @return |
| | | * TaoBaoGoodsBrief 包含(标题与图片)
|
| | | * @throws
|
| | | */
|
| | | public static TaoBaoGoodsBrief getTaoBaoGoodsBriefNotInPub(Long id) {
|
| | | TaoBaoGoodsBrief tb = TaoBaoUtil.getTmallGoodsInfo(id+"");
|
| | | return tb;
|
| | | }
|
| | |
|
| | | public static List<String> getSuguestSearch(String key) {
|
| | |
| | | */
|
| | | public static BigDecimal getGoodsHongBaoMoney(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) {
|
| | | BigDecimal money = null;
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo())
|
| | | || goodsBrief.getCouponInfo().trim().equalsIgnoreCase("无")) {
|
| | | money = MoneyBigDecimalUtil.mul(
|
| | |
| | | return taoBaoGoods;
|
| | | }
|
| | |
|
| | | public static TaoBaoGoodsBrief convert(DaTaoKeDetail detail) {
|
| | | TaoBaoGoodsBrief taoBaoGoods = new TaoBaoGoodsBrief();
|
| | | taoBaoGoods.setAuctionId(detail.getGoodsId());
|
| | | taoBaoGoods.setBiz30day(detail.getSalesNum());
|
| | | taoBaoGoods.setCouponAmount(detail.getQuanPrice());
|
| | | taoBaoGoods.setCouponInfo(String.format("满%s元减%s元", detail.getQuanCondition(),
|
| | | MoneyBigDecimalUtil.getWithNoZera(detail.getQuanPrice())));
|
| | | taoBaoGoods.setCouponLeftCount(detail.getQuanSurplus());
|
| | | taoBaoGoods.setCouponStartFee(new BigDecimal(detail.getQuanCondition()));
|
| | | if (detail.getQuanReceive() != null)
|
| | | taoBaoGoods.setCouponTotalCount(detail.getQuanSurplus() + detail.getQuanReceive());
|
| | | taoBaoGoods.setPictUrl(detail.getPic());
|
| | | taoBaoGoods.setPictUrlWhite(detail.getPic());
|
| | | taoBaoGoods.setSellerId(detail.getSellerId());
|
| | | taoBaoGoods.setShopTitle("");
|
| | | taoBaoGoods.setTitle(detail.getdTitle());
|
| | | taoBaoGoods.setUserType(detail.getIsTmall());
|
| | | taoBaoGoods.setZkPrice(detail.getOrgPrice());
|
| | | taoBaoGoods.setTkRate(detail.getCommission());
|
| | | taoBaoGoods.setTkCommFee(new BigDecimal("0"));
|
| | | taoBaoGoods.setState(0);
|
| | | return taoBaoGoods;
|
| | | }
|
| | |
|
| | | public static TaoBaoGoodsBrief convert(DaTaoKeDetailV2 detail) {
|
| | | TaoBaoGoodsBrief taoBaoGoods = new TaoBaoGoodsBrief();
|
| | | taoBaoGoods.setAuctionId(detail.getGoodsId());
|
| | |
| | | return url;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取淘宝的商品详情
|
| | | * |
| | | * @param actionId
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoGoodsBrief getSimpleGoodsBrief(Long actionId) {
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("itemNumId", actionId + "");
|
| | |
|
| | | String url = "";
|
| | | try {
|
| | | url = String.format("https://acs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?data=%s",
|
| | | url = String.format(
|
| | | "http://acs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?data=%s&qq-pf-to=pcqq.group",
|
| | | URLEncoder.encode(data.toString(), "UTF-8"));
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | String result = HttpUtil.get(url);
|
| | | String result = null;
|
| | | try {
|
| | | Connection.Response doc = Jsoup.connect(url).ignoreContentType(true).timeout(1000 * 10)
|
| | | .userAgent(
|
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362")
|
| | | .header("Accept", "text/html, application/xhtml+xml, application/xml; q=0.9, */*; q=0.8")
|
| | | .header("Accept-Language", "zh-CN").header("Host", "acs.m.taobao.com")
|
| | | .header("Upgrade-Insecure-Requests", "1")
|
| | | .header("Cookie",
|
| | | "_cc_=VFC%2FuZ9ajQ%3D%3D; isg=BLu7TvdFYk89dV4DMXO7XNRGU58lEM8SDjV-ja14l7rRDNvuNeBfYtlOJmznNycK; thw=cn; miid=1490566681358073134; x=e%3D1%26p%3D*%26s%3D0%26c%3D0%26f%3D0%26g%3D0%26t%3D0%26__ll%3D-1%26_ato%3D0; cna=ZW8rFCpNP1gCAWpXAiKqMzqi; tracknick=tb23001560; l=cBxbffilq1UJdAFCBOCanurza77OSdAYYuPzaNbMi_5NE6T1BR7Ok6G1vF96VsWdOW8B4NSiTkp9-etkZ3Znq9SpXUJ1.; tg=0; _w_app_lg=19; WAPFDFDTGFG=%2B4cMKKP%2B8PI%2BtNYpkiAuTPLkiJB1kcwi")
|
| | | .execute();
|
| | | result = doc.body();
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | |
|
| | | JSONObject resultOBJ = JSONObject.fromObject(result);
|
| | | if (resultOBJ.optJSONObject("data") != null) {
|
| | | data = resultOBJ.optJSONObject("data");
|
| | | JSONObject item = data.optJSONObject("item");
|
| | | JSONObject seller = data.optJSONObject("seller");
|
| | | TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
|
| | | goods.setAuctionId(item.optLong("itemId"));
|
| | | goods.setTitle(item.optString("title"));
|
| | | if (item.optJSONArray("images") != null && item.optJSONArray("images").size() > 0) {
|
| | | String picture = item.optJSONArray("images").optString(0);
|
| | | goods.setPictUrl(picture.startsWith("http") ? picture : "https:" + picture);
|
| | | if (data != null) {
|
| | | JSONObject item = data.optJSONObject("item");
|
| | | if (item != null) {
|
| | | JSONObject seller = data.optJSONObject("seller");
|
| | | TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
|
| | | goods.setTitle(item.optString("title"));
|
| | | goods.setAuctionId(item.optLong("itemId"));
|
| | | goods.setTitle(item.optString("title"));
|
| | | if (item.optJSONArray("images") != null && item.optJSONArray("images").size() > 0) {
|
| | | String picture = item.optJSONArray("images").optString(0);
|
| | | goods.setPictUrl(picture.startsWith("http") ? picture : "https:" + picture);
|
| | | }
|
| | | if (seller != null) {
|
| | | goods.setSellerId(seller.optLong("shopId"));
|
| | | String shopType = seller.optString("shopType");
|
| | | if ("B".equalsIgnoreCase(shopType)) {
|
| | | goods.setUserType(1);
|
| | | } else
|
| | | goods.setUserType(0);
|
| | | goods.setShopTitle(seller.optString("shopName"));
|
| | | }
|
| | | return goods;
|
| | | }
|
| | | }
|
| | | goods.setSellerId(seller.optLong("shopId"));
|
| | | String shopType = seller.optString("shopType");
|
| | | if ("B".equalsIgnoreCase(shopType)) {
|
| | | goods.setUserType(1);
|
| | | } else
|
| | | goods.setUserType(0);
|
| | |
|
| | | goods.setShopTitle(seller.optString("shopName"));
|
| | | return goods;
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
| | | return token;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 提取自有格式的淘口令
|
| | | * |
| | | * @param str
|
| | | * @return
|
| | | */
|
| | | public static String parseSystemTaoToken(String str) {
|
| | | String pattern = "(\\({1}[A-Za-z0-9]+\\){1})";
|
| | | Pattern r = Pattern.compile(pattern);
|
| | | Matcher m = r.matcher(str);
|
| | | while (m.find()) {
|
| | | String group = m.group(0);
|
| | | if (!StringUtil.isNullOrEmpty(group) && group.length() >= 10)
|
| | | return group;
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | public static boolean isSpecialGoods(Integer materialLibType) {
|
| | | if (materialLibType != null && materialLibType == 1)
|
| | | return true;
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 从文本中提取淘口令
|
| | | * @Title: getTokenListFromText
|
| | | * @Description: |
| | | * @param str
|
| | | * @return |
| | | * List<String> 返回类型
|
| | | * @throws
|
| | | */
|
| | | public static List<String> getTokenListFromText(String str) {
|
| | | String[] marks = new String[] { "₳", "¥", "¥", "€", "\\$", "₴", "¢", "₤" };
|
| | |
|
| | | return getTokenListFromText(str, Arrays.asList(marks));
|
| | | }
|
| | |
|
| | | public static List<String> getTokenListFromText(String str, List<String> markList) {
|
| | | List<String> expressList = new ArrayList<>();
|
| | | for (String st : markList) {
|
| | | expressList.add(String.format("(%s{1}[A-Za-z0-9]{11,13}+%s{1})", st, st));
|
| | | }
|
| | | String pattern = StringUtil.concat(expressList, "|");
|
| | | Pattern r = Pattern.compile(pattern);
|
| | | Matcher m = r.matcher(str);
|
| | | List<String> urlList = new ArrayList<>();
|
| | | while (m.find()) {
|
| | | urlList.add(m.group());
|
| | | }
|
| | | return urlList;
|
| | | }
|
| | |
|
| | | }
|