| | |
| | | import javax.xml.parsers.DocumentBuilder;
|
| | | import javax.xml.parsers.DocumentBuilderFactory;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | import org.apache.commons.httpclient.HttpClient;
|
| | | import org.apache.commons.httpclient.methods.GetMethod;
|
| | | import org.jsoup.Connection;
|
| | |
| | | import org.springframework.stereotype.Component;
|
| | | import org.w3c.dom.NamedNodeMap;
|
| | | import org.w3c.dom.NodeList;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | | import org.yeshi.utils.NumberUtil;
|
| | | import org.yeshi.utils.entity.ProxyIP;
|
| | | import org.yeshi.utils.taobao.TbImgUtil;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.GsonBuilder;
|
| | | import com.google.gson.reflect.TypeToken;
|
| | | import com.yeshi.fanli.entity.bus.user.CollectionGoods;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.common.ImageInfo;
|
| | | import com.yeshi.fanli.entity.goods.CommonGoods;
|
| | | import com.yeshi.fanli.entity.taobao.ScanHistory;
|
| | | import com.yeshi.fanli.entity.taobao.SearchFilter;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoCoupon;
|
| | |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
| | | import com.yeshi.fanli.goods.CommonGoods;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.goods.TaoBaoLinkService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
|
| | |
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TaoBaoHttpUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | | import org.yeshi.utils.NumberUtil;
|
| | | import org.yeshi.utils.taobao.TbImgUtil;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Component
|
| | | public class TaoBaoUtil {
|
| | |
| | | return list;
|
| | | }
|
| | |
|
| | | public static TaoBaoGoodsBriefExtra getTaoBaoGoodsBriefExtra(TaoBaoGoodsBrief tb, String proportion,
|
| | | String fcRateStr, String pid) {
|
| | | public static TaoBaoGoodsBriefExtra getTaoBaoGoodsBriefExtra(TaoBaoGoodsBrief tb, String proportion, String pid) {
|
| | | TaoBaoGoodsBriefExtra tg = new TaoBaoGoodsBriefExtra();
|
| | | tg.setId(tb.getId());
|
| | | tg.setAuctionId(tb.getAuctionId());
|
| | |
| | | tg.setReservePrice(tb.getReservePrice());
|
| | | tg.setUserType(tb.getUserType());
|
| | | tg.setShopTitle(tb.getShopTitle());
|
| | | tg.setState(tb.getState()); // 状态:2018-12-03
|
| | | if (tb.getCouponAmount().compareTo(BigDecimal.valueOf(0)) == 1) {
|
| | | TaoBaoQuanInfo quanInfo = new TaoBaoQuanInfo();
|
| | | quanInfo.setCouponAmount(tb.getCouponAmount());
|
| | |
| | | tg.setTaoBaoQuanInfo(quanInfo);
|
| | | }
|
| | | TaoBaoHongBaoInfo hongBaoInfo = new TaoBaoHongBaoInfo();
|
| | | BigDecimal fcRate = BigDecimal.valueOf(1);
|
| | | String eventRate = tb.getEventRate();
|
| | | BigDecimal rate = BigDecimal.valueOf(0);
|
| | | if (eventRate == null) {
|
| | | rate = tb.getTkRate();
|
| | | } else {
|
| | | rate = new BigDecimal(eventRate);
|
| | | if (fcRateStr != null) {
|
| | | fcRate = (new BigDecimal(fcRateStr).divide(BigDecimal.valueOf(100)));
|
| | | }
|
| | | }
|
| | |
|
| | | hongBaoInfo.setRate("最高40%");
|
| | |
|
| | |
| | | tg.setId(tb.getId());
|
| | | tg.setAuctionId(tb.getAuctionId());
|
| | | tg.setBiz30day(tb.getBiz30day());
|
| | | tg.setSalesCount(TaoBaoUtil.getSaleCount(tb.getBiz30day()));
|
| | | tg.setTitle(tb.getTitle());
|
| | | tg.setPictUrl(tb.getPictUrl() + "_200x200");
|
| | | tg.setPictUrl(tb.getPictUrl());
|
| | | tg.setZkPrice(tb.getZkPrice());
|
| | | tg.setAuctionUrl(tb.getAuctionUrl());
|
| | | tg.setReservePrice(tb.getReservePrice());
|
| | | tg.setUserType(tb.getUserType());
|
| | | tg.setImgList(tb.getImgList());
|
| | |
|
| | | if (tb.getCouponAmount().compareTo(BigDecimal.valueOf(0)) == 1) {
|
| | | TaoBaoQuanInfo quanInfo = new TaoBaoQuanInfo();
|
| | |
| | | tg.setTaoBaoQuanInfo(quanInfo);
|
| | | }
|
| | |
|
| | | Map<String, String> convertMap = taoBaoUtil.manageService.convertMap();
|
| | | String proportion = convertMap.get("hongbao_goods_proportion");
|
| | | String fcRateStr = convertMap.get("hongbao_fc_ratio");
|
| | | BigDecimal proportion = taoBaoUtil.manageService.getFanLiRate();
|
| | | TaoBaoHongBaoInfo hongBaoInfo = new TaoBaoHongBaoInfo();
|
| | | String eventRate = tb.getEventRate();
|
| | | BigDecimal rate = BigDecimal.valueOf(0);
|
| | | if (eventRate != null) {
|
| | | rate = new BigDecimal(eventRate);
|
| | | } else {
|
| | | rate = tb.getTkRate();
|
| | | }
|
| | | BigDecimal fcRate = new BigDecimal(fcRateStr);
|
| | |
|
| | | String tkMktStatus = tb.getTkMktStatus();
|
| | | if ("1".equals(tkMktStatus)) {
|
| | | hongBaoInfo.setType(1);
|
| | |
| | |
|
| | | hongBaoInfo.setRate("最高40%");
|
| | |
|
| | | String hongbao = getGoodsHongBaoInfo(tb, new BigDecimal(proportion));
|
| | | String hongbao = getGoodsHongBaoInfo(tb, proportion);
|
| | | if (!hongbao.contains("最高"))
|
| | | hongBaoInfo.setHongbao(new BigDecimal(hongbao.replace("¥", "")));
|
| | | else
|
| | |
| | | target.setAccessible(true);
|
| | | if (target.getName().equalsIgnoreCase(field.getName())) {
|
| | | field.set(tb, target.get(sh));
|
| | | break;
|
| | | }
|
| | | }
|
| | | } catch (IllegalArgumentException e) {
|
| | | e.printStackTrace();
|
| | | } catch (IllegalAccessException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | return tb;
|
| | | }
|
| | |
|
| | | public static TaoBaoGoodsBrief getTaoBaoGoodsBrief(CollectionGoods sh) {
|
| | | TaoBaoGoodsBrief tb = new TaoBaoGoodsBrief();
|
| | | Field[] fields = tb.getClass().getDeclaredFields();
|
| | | Field[] shFields = sh.getClass().getDeclaredFields();
|
| | | for (int i = 0; i < fields.length; i++) {
|
| | | Field field = fields[i];
|
| | | field.setAccessible(true);
|
| | | try {
|
| | | for (Field target : shFields) {
|
| | | target.setAccessible(true);
|
| | | if (target.getName().equalsIgnoreCase(field.getName())) {
|
| | | if (!"createtime".equalsIgnoreCase(field.getName()))
|
| | | field.set(tb, target.get(sh));
|
| | | break;
|
| | | }
|
| | | }
|
| | |
| | | }
|
| | | return parsePhoneTmAndTb(id);
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, "无法解析到淘宝商品ID", burl);
|
| | | } catch (Exception e1) {
|
| | | }
|
| | | LogHelper.error("无法解析到淘宝商品ID:"+burl);
|
| | | return null;
|
| | | }
|
| | |
|
| | |
| | | return taoBaoGoodsBrief;
|
| | | }
|
| | |
|
| | | public static CollectionGoods getCollectionGoods(long auctionId, UserInfo userInfo) {
|
| | | TaoBaoGoodsBrief taoBaoGoodsBrief = null;
|
| | | try {
|
| | | taoBaoGoodsBrief = TaoKeApiUtil.searchGoodsDetail(auctionId);
|
| | | } catch (TaobaoGoodsDownException e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | CollectionGoods collectionGoods = new CollectionGoods();
|
| | | Field[] fields = taoBaoGoodsBrief.getClass().getDeclaredFields();
|
| | | Field[] shFields = collectionGoods.getClass().getDeclaredFields();
|
| | | for (int i = 0; i < fields.length; i++) {
|
| | | Field field = fields[i];
|
| | | field.setAccessible(true);
|
| | | try {
|
| | | for (Field target : shFields) {
|
| | | target.setAccessible(true);
|
| | | if (target.getName().equalsIgnoreCase(field.getName())) {
|
| | | if (!field.getName().equalsIgnoreCase("createTime"))
|
| | | target.set(collectionGoods, field.get(taoBaoGoodsBrief));
|
| | | break;
|
| | | }
|
| | | }
|
| | | } catch (IllegalArgumentException e) {
|
| | | e.printStackTrace();
|
| | | } catch (IllegalAccessException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | collectionGoods.setUserInfo(userInfo);
|
| | | return collectionGoods;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取商品的用户分成比例
|
| | | *
|
| | |
| | | * @return
|
| | | */
|
| | | public static String getGoodsHongBaoInfo(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) {
|
| | | // 营销计划
|
| | | // if ("1".equalsIgnoreCase(goodsBrief.getTkMktStatus())) {
|
| | | // return "最高40%";
|
| | | // } else {
|
| | | // 计算返利
|
| | | // 无券
|
| | | return "¥" + getGoodsHongBaoMoney(goodsBrief, rate).toString();
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取淘宝商品该获得多少佣金
|
| | | * |
| | | * @param goodsBrief
|
| | | * @param rate
|
| | | * @return
|
| | | */
|
| | | public static BigDecimal getGoodsHongBaoMoney(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) {
|
| | | if (StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo())
|
| | | || goodsBrief.getCouponInfo().trim().equalsIgnoreCase("无")) {
|
| | | return "¥" + goodsBrief.getZkPrice().multiply(goodsBrief.getTkRate()).divide(new BigDecimal(10000))
|
| | | .multiply(rate).setScale(2, BigDecimal.ROUND_DOWN);
|
| | |
|
| | | return goodsBrief.getZkPrice().multiply(goodsBrief.getTkRate()).divide(new BigDecimal(10000)).multiply(rate)
|
| | | .setScale(2, BigDecimal.ROUND_DOWN);
|
| | | } else// 有券
|
| | | {
|
| | | List<BigDecimal> list = TaoBaoCouponUtil.getCouponInfo(goodsBrief.getCouponInfo());
|
| | |
| | | if (startFee.compareTo(goodsBrief.getZkPrice()) <= 0
|
| | | && goodsBrief.getZkPrice().compareTo(couponAccount) > 0) {
|
| | | BigDecimal finalPrice = goodsBrief.getZkPrice().subtract(couponAccount);
|
| | | return "¥" + finalPrice.multiply(goodsBrief.getTkRate()).divide(new BigDecimal(10000)).multiply(rate)
|
| | | return finalPrice.multiply(goodsBrief.getTkRate()).divide(new BigDecimal(10000)).multiply(rate)
|
| | | .setScale(2, BigDecimal.ROUND_DOWN);
|
| | |
|
| | | } else {// 不能用券
|
| | | return "¥" + goodsBrief.getZkPrice().multiply(goodsBrief.getTkRate()).divide(new BigDecimal(10000))
|
| | | return goodsBrief.getZkPrice().multiply(goodsBrief.getTkRate()).divide(new BigDecimal(10000))
|
| | | .multiply(rate).setScale(2, BigDecimal.ROUND_DOWN);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // }
|
| | |
|
| | | // 获取券的红包显示
|
| | |
| | |
|
| | | long startTime = System.currentTimeMillis();
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("itemNumId", auctionId + "");
|
| | | data.put("id", auctionId + "");
|
| | | String url = "";
|
| | | try {
|
| | | url = String.format(
|
| | | "https://acs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?data=%s&qq-pf-to=pcqq.group",
|
| | | URLEncoder.encode(data.toString(), "UTF-8"));
|
| | | "https://h5api.m.taobao.com/h5/mtop.taobao.detail.getdesc/6.0/?data=%s&callback=GoodsLogic.showTuwen&_=%s",
|
| | | URLEncoder.encode(data.toString(), "UTF-8"), System.currentTimeMillis() + "");
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | String result = HttpUtil.get(url);
|
| | | result = result.replace("GoodsLogic.showTuwen(", "").replace(")", "");
|
| | | data = JSONObject.fromObject(result);
|
| | | String moduleDescUrl = data.optJSONObject("data").optJSONObject("item").optString("moduleDescUrl");
|
| | | if (!StringUtil.isNullOrEmpty(moduleDescUrl)) {
|
| | | String pcDescContent = data.optJSONObject("data").optString("pcDescContent");
|
| | | System.out.println(pcDescContent);
|
| | | if (!StringUtil.isNullOrEmpty(pcDescContent)) {
|
| | | try {
|
| | | result = HttpUtil.get("http:" + moduleDescUrl);
|
| | | JSONObject resultJSON = JSONObject.fromObject(result);
|
| | | JSONArray itemsArray = resultJSON.optJSONObject("data").optJSONArray("children");
|
| | | for (int i = 0; i < itemsArray.size(); i++) {
|
| | | // picUrl
|
| | | JSONObject params = itemsArray.optJSONObject(i).optJSONObject("params");
|
| | | if (params.keySet().contains("picUrl")) {
|
| | | String pictureUrl = params.optString("picUrl");
|
| | | JSONObject sizeJSON = params.optJSONObject("size");
|
| | | int width = sizeJSON.optInt("width");
|
| | | int height = sizeJSON.optInt("height");
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(pictureUrl))
|
| | | imgList.add(new ImageInfo(pictureUrl, width, height));
|
| | | Document doc = Jsoup.parse(pcDescContent);
|
| | | Elements eles = doc.getElementsByTag("img");
|
| | | for (int i = 0; i < eles.size(); i++) {
|
| | | String imgSrc = eles.get(i).attr("src");
|
| | | if (imgSrc.endsWith(".jpg")) {
|
| | | if (!imgSrc.startsWith("http"))
|
| | | imgSrc = "https:" + imgSrc;
|
| | | imgList.add(new ImageInfo(imgSrc, 0, 0));
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | |
| | | * @return
|
| | | */
|
| | |
|
| | | public static List<ImageInfo> getTBDetailImageWithSizev2(Long auctionId) {
|
| | | public static List<ImageInfo> getTBDetailImageWithSizev2(Long auctionId, ProxyIP ip) {
|
| | | List<ImageInfo> imgList = new ArrayList<>();
|
| | | try {
|
| | | Map<String, String> headers = new HashMap<>();
|
| | | headers.put("User-Agent",
|
| | | "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1");
|
| | | headers.put("Referer", "https://detail.tmall.com/item.htm?id=" + auctionId);
|
| | | String url = String.format("https://hws.m.taobao.com/cache/desc/5.0?id=" + auctionId);
|
| | | String result = HttpUtil.get(url);
|
| | | JSONObject data = JSONObject.fromObject(result);
|
| | | String result = HttpUtil.get(url, headers, ip);
|
| | | if (!StringUtil.isNullOrEmpty(result)) {
|
| | | JSONObject data = JSONObject.fromObject(result);
|
| | |
|
| | | JSONArray array = data.optJSONObject("wdescContent").optJSONArray("pages");
|
| | | if (array != null) {
|
| | | String html = "";
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | String itemStr = array.optString(i).replace("<img", "<a").replace("</img>", "<a>");
|
| | | html += itemStr;
|
| | | }
|
| | | Document doc = Jsoup.parse(html);
|
| | | Elements items = doc.getElementsByTag("a");
|
| | | for (int i = 0; i < items.size(); i++) {
|
| | | ImageInfo img = new ImageInfo();
|
| | | Element item = items.get(i);
|
| | | if (StringUtil.isNullOrEmpty(item.ownText()))
|
| | | continue;
|
| | | if (!StringUtil.isNullOrEmpty(item.attr("size"))) {
|
| | | img.setWidth(Integer.parseInt(item.attr("size").split("x")[0]));
|
| | | img.setHeight(Integer.parseInt(item.attr("size").split("x")[1]));
|
| | | JSONArray array = data.optJSONObject("wdescContent").optJSONArray("pages");
|
| | | if (array != null) {
|
| | | String html = "";
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | String itemStr = array.optString(i).replace("<img", "<a").replace("</img>", "<a>");
|
| | | html += itemStr;
|
| | | }
|
| | | if (item.ownText().startsWith("http"))
|
| | | img.setPicture(item.ownText().trim());
|
| | | else
|
| | | img.setPicture("http:" + item.ownText().trim());
|
| | | imgList.add(img);
|
| | | Document doc = Jsoup.parse(html);
|
| | | Elements items = doc.getElementsByTag("a");
|
| | | for (int i = 0; i < items.size(); i++) {
|
| | | ImageInfo img = new ImageInfo();
|
| | | Element item = items.get(i);
|
| | | if (StringUtil.isNullOrEmpty(item.ownText()))
|
| | | continue;
|
| | | if (!StringUtil.isNullOrEmpty(item.attr("size"))) {
|
| | | img.setWidth(Integer.parseInt(item.attr("size").split("x")[0]));
|
| | | img.setHeight(Integer.parseInt(item.attr("size").split("x")[1]));
|
| | | }
|
| | | if (item.ownText().startsWith("http"))
|
| | | img.setPicture(item.ownText().trim());
|
| | | else
|
| | | img.setPicture("http:" + item.ownText().trim());
|
| | | if (img != null && img.getPicture() != null && img.getPicture().endsWith(".jpg"))
|
| | | imgList.add(img);
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | |
|