| | |
| | | package com.yeshi.fanli.util.taobao;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.lang.reflect.Type;
|
| | | import java.math.BigDecimal;
|
| | | import java.net.URLDecoder;
|
| | | import java.net.URLEncoder;
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | | import java.util.regex.Matcher;
|
| | | import java.util.regex.Pattern;
|
| | |
|
| | | import javax.annotation.PostConstruct;
|
| | | import javax.annotation.Resource;
|
| | | import javax.script.Invocable;
|
| | | import javax.script.ScriptEngine;
|
| | | import javax.script.ScriptEngineManager;
|
| | | import javax.xml.parsers.DocumentBuilder;
|
| | | import javax.xml.parsers.DocumentBuilderFactory;
|
| | |
|
| | | import org.apache.commons.httpclient.HttpClient;
|
| | | import org.apache.commons.httpclient.HttpException;
|
| | | import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
|
| | | import org.apache.commons.httpclient.methods.GetMethod;
|
| | | import org.apache.commons.httpclient.params.HttpMethodParams;
|
| | | import org.jsoup.Connection;
|
| | | import org.jsoup.Jsoup;
|
| | | import org.jsoup.nodes.Document;
|
| | | import org.jsoup.nodes.Element;
|
| | | import org.jsoup.select.Elements;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Component;
|
| | | import org.w3c.dom.NamedNodeMap;
|
| | | import org.w3c.dom.NodeList;
|
| | | import org.yeshi.utils.BigDecimalUtil;
|
| | | 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.common.ImageInfo;
|
| | | import com.yeshi.fanli.entity.goods.CommonGoods;
|
| | | import com.yeshi.fanli.entity.taobao.SearchFilter;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoCoupon;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoHead;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoHongBaoInfo;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoLink;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoProvince;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoQuanInfo;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchNav;
|
| | | 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.service.inter.goods.TaoBaoLinkService;
|
| | | import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
|
| | | import com.yeshi.fanli.tag.PageEntity;
|
| | | import com.yeshi.fanli.util.AESUtil;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | 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;
|
| | |
|
| | | @Component
|
| | | public class TaoBaoUtil {
|
| | |
|
| | | @Autowired
|
| | | private HongBaoManageService manageService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoLinkService taoBaoLinkService;
|
| | |
|
| | | private static TaoBaoUtil taoBaoUtil;
|
| | |
|
| | | @PostConstruct
|
| | | public void init() {
|
| | | taoBaoUtil = this;
|
| | | taoBaoUtil.manageService = this.manageService;
|
| | | taoBaoUtil.taoBaoLinkService = this.taoBaoLinkService;
|
| | | }
|
| | |
|
| | | public final static int SORT_PRICE_HIGH_TO_LOW = 3;// 价格从高到低
|
| | | public final static int SORT_PRICE_LOW_TO_HIGH = 4;// 价格从低到高
|
| | |
|
| | | public static final int SORT_TKRATE_LOW_TO_HIGH = 1;// 淘客佣金比率低到高
|
| | | public static final int SORT_TKRATE_HIGH_TO_LOW = 2;// 淘客佣金比率高到低
|
| | |
|
| | | public static final int SORT_TOTAL_COMMI_LOW_TO_HIGH = 5;// 总支出佣金低到高
|
| | | public static final int SORT_TOTAL_COMMI_HIGH_TO_LOW = 6;// 总支出佣金高到低
|
| | |
|
| | | public static final int SORT_TOTAL_SALES_LOW_TO_HIGH = 10;// 累计推广量低到高
|
| | | public static final int SORT_TOTAL_SALES_HIGH_TO_LOW = 11;// 累计推广量高到低
|
| | |
|
| | | public static final int SORT_SALE_COMMISSION = 7;// 月支出佣金从高到低
|
| | |
|
| | | public final static int SORT_SALE_LOW_TO_HIGH = 8;// 销量从低到高
|
| | |
|
| | | public final static int SORT_SALE_HIGH_TO_LOW = 9;// 销量从高到低
|
| | | public final static int SORT_DEFAULT = 0;// 销量从高到低
|
| | |
|
| | | public final static int SORT_FILTER_FROM_ALL = 0;// 淘宝天猫
|
| | | public final static int SORT_FILTER_FROM_TMALL = 1;// 天猫
|
| | |
|
| | | private final static int PAGESIZE = 20;
|
| | |
|
| | | public final static String SEARCH_URL = "http://pub.alimama.com/items/search.json";
|
| | | private static final String NZJH_URL = "http://pub.alimama.com/items/channel/nzjh.json";
|
| | | private static final String MUYING_URL = "http://pub.alimama.com/items/channel/muying.json";
|
| | | private static final String QQHD_URL = "http://pub.alimama.com/items/channel/qqhd.json";
|
| | | private static final String IFS_URL = "http://pub.alimama.com/items/channel/ifs.json";
|
| | | private static final String QBB_URL = "http://pub.alimama.com/items/channel/qbb.json";
|
| | | private static final String HCH_URL = "http://pub.alimama.com/items/channel/hch.json";
|
| | | private static final String CDJ_URL = "http://pub.alimama.com/items/channel/cdj.json";
|
| | | private static final String JYJ_URL = "http://pub.alimama.com/items/channel/jyj.json";
|
| | | private static final String KDC_URL = "http://pub.alimama.com/items/channel/kdc.json";
|
| | | private static final String DIY_URL = "http://pub.alimama.com/items/channel/diy.json";
|
| | | private static final String K9_URL = "http://pub.alimama.com/items/channel/9k9.json";
|
| | | private static final String K20_URL = "http://pub.alimama.com/items/channel/20k.json";
|
| | | private static final String TEHUI_URL = "http://pub.alimama.com/items/channel/tehui.json";
|
| | |
|
| | | private static final String TB_ITEM_URL = "http://gw.api.taobao.com/router/rest";
|
| | |
|
| | | public static final String TB_URL = "http://item.taobao.com/item.htm?id=%s";
|
| | | public static final String TM_PHONE_URL = "https://detail.m.tmall.com/item.htm?id=%s";
|
| | | public static final String TB_H5_URL = "http://h5.m.taobao.com/awp/core/detail.htm?id=%s";
|
| | |
|
| | | private static final Map<Integer, String> channelMap = new HashMap<Integer, String>();
|
| | | private static final Map<Integer, String> urlMap = new HashMap<Integer, String>();
|
| | |
|
| | | private static List<TaoBaoProvince> taoBaoProvinceList = null;
|
| | |
|
| | | static {
|
| | | channelMap.put(0, "");// 普通
|
| | | channelMap.put(1, "nzjh");// 女装尖货
|
| | | channelMap.put(2, "muying");// 母婴热推
|
| | | channelMap.put(3, "qqhd");// 高佣活动
|
| | | channelMap.put(4, "ifs");// ifashion
|
| | | channelMap.put(5, "qbb");// 亲宝贝
|
| | | channelMap.put(6, "hch");// 淘宝汇吃
|
| | | channelMap.put(7, "cdj");// 潮电街
|
| | | channelMap.put(8, "jyj");// 极有家
|
| | | channelMap.put(9, "kdc");// 酷动城
|
| | | channelMap.put(10, "diy");// 淘宝DIY
|
| | | channelMap.put(11, "9k9");// 超值9块9
|
| | | channelMap.put(12, "20k");// 20元封顶
|
| | | channelMap.put(13, "tehui");// 特价好货
|
| | |
|
| | | urlMap.put(0, SEARCH_URL);
|
| | | urlMap.put(1, NZJH_URL);
|
| | | urlMap.put(2, MUYING_URL);
|
| | | urlMap.put(3, QQHD_URL);
|
| | | urlMap.put(4, IFS_URL);
|
| | | urlMap.put(5, QBB_URL);
|
| | | urlMap.put(6, HCH_URL);
|
| | | urlMap.put(7, CDJ_URL);
|
| | | urlMap.put(8, JYJ_URL);
|
| | | urlMap.put(9, KDC_URL);
|
| | | urlMap.put(10, DIY_URL);
|
| | | urlMap.put(11, K9_URL);
|
| | | urlMap.put(12, K20_URL);
|
| | | urlMap.put(13, TEHUI_URL);
|
| | | }
|
| | |
|
| | | public static TaoBaoSearchResult search(SearchFilter filter, boolean proxy) {
|
| | | if (filter.getKey().startsWith("http://") || filter.getKey().startsWith("https://")) {
|
| | | String[] sts = filter.getKey().split("\\?")[1].split("&");
|
| | | for (String st : sts) {
|
| | | if (st.contains("id=")) {
|
| | | String id = st.replace("id=", "").trim();
|
| | | TaoBaoGoodsBrief tb = null;
|
| | | try {
|
| | | tb = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(id));
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
|
| | | goodsList.add(tb);
|
| | | TaoBaoSearchResult result = new TaoBaoSearchResult();
|
| | | result.setTaoBaoGoodsBriefs(goodsList);
|
| | | result.setNavList(new ArrayList<>());
|
| | | TaoBaoHead taoBaoHead = new TaoBaoHead();
|
| | | taoBaoHead.setDocsfound(1);
|
| | | result.setTaoBaoHead(taoBaoHead);
|
| | | return result;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | List<Long> cateList = null;
|
| | | if (!StringUtil.isNullOrEmpty(filter.getCateIds())) {
|
| | | cateList = new ArrayList<>();
|
| | | for (String c : filter.getCateIds().split(","))
|
| | | cateList.add(Long.parseLong(c));
|
| | | }
|
| | | return TaoKeApiUtil.searchWuLiao(filter);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 淘宝联盟网页搜索商品
|
| | | * |
| | | * @param filter
|
| | | * @param config
|
| | | * -联盟配置
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoSearchResult searchFromAlimamaWeb(SearchFilter filter, TaoBaoUnionConfig config) {
|
| | | Map<String, String> params = new HashMap<String, String>();
|
| | | params.put("q", filter.getKey());
|
| | | params.put("_t", System.currentTimeMillis() + "");
|
| | | params.put("toPage", filter.getPage() + "");
|
| | | params.put("auctionTag", "");
|
| | | params.put("perPageSize", filter.getPageSize() == 0 ? PAGESIZE + "" : filter.getPageSize() + "");
|
| | | params.put("shopTag", filter.getShopTag() + "");
|
| | | params.put("t", System.currentTimeMillis() + "");
|
| | | params.put("_tb_token_", "test");
|
| | | params.put("yxjh", "-1");
|
| | | params.put("queryType", "2");
|
| | | String shopTag = filter.getShopTag();
|
| | | if (shopTag != null) {
|
| | | String[] split = shopTag.split(",");
|
| | | for (String tag : split) {
|
| | | params.put(tag, "1");
|
| | | }
|
| | | }
|
| | |
|
| | | if (filter.isTmall()) {
|
| | | params.put("userType", "1");
|
| | | }
|
| | |
|
| | | if (filter.isBaoYou()) {
|
| | | params.put("freeShipment", "1");
|
| | | }
|
| | |
|
| | | if (filter.getStartPrice() != null) {
|
| | | params.put("startPrice", filter.getStartPrice() + "");
|
| | | }
|
| | | if (filter.getEndPrice() != null) {
|
| | | params.put("endPrice", filter.getEndPrice() + "");
|
| | | }
|
| | | if (!StringUtil.isNullOrEmpty(filter.getCateIds()))
|
| | | params.put("catIds", filter.getCateIds());
|
| | |
|
| | | if (filter.getParams() != null && filter.getParams().size() > 0) {
|
| | | Set<String> set = filter.getParams();
|
| | | StringBuffer sb = new StringBuffer();
|
| | | int i = 0;
|
| | | for (String ids : set) {
|
| | | if (i == 0) {
|
| | | sb.append(ids);
|
| | | } else {
|
| | | sb.append(";" + ids);
|
| | | }
|
| | | i++;
|
| | | }
|
| | | params.put("pidvid", sb.toString());
|
| | | }
|
| | | if (filter.getSort() > 0) {
|
| | | params.put("sortType", filter.getSort() + "");
|
| | | // params.put("queryType", "0");
|
| | | }
|
| | |
|
| | | Map<String, String> headers = new HashMap<>();
|
| | | // headers.put("cookie",
|
| | | // TaoBaoOrderUtil.getTaoBaoCookie(config.getAccount()));
|
| | |
|
| | | headers.put("referer", "https://pub.alimama.com/promo/search/index.htm");
|
| | |
|
| | | headers.put("User-Agent",
|
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36");
|
| | |
|
| | | String result = TaoBaoHttpUtil.get(SEARCH_URL, params, headers, true);
|
| | | if (result == null || "".equals(result)) {
|
| | | return null;
|
| | | }
|
| | | result = result.replace("</span>", "").replace("<span class=H>", "");
|
| | | if (result.contains("<!DOCTYPE html>")) {
|
| | | TaoBaoSearchResult presult = new TaoBaoSearchResult();
|
| | | presult.setNavList(new ArrayList<TaoBaoSearchNav>());
|
| | | presult.setTaoBaoGoodsBriefs(new ArrayList<TaoBaoGoodsBrief>());
|
| | | TaoBaoHead taoBaoHead = new TaoBaoHead();
|
| | | taoBaoHead.setDocsfound(0);
|
| | | presult.setTaoBaoHead(taoBaoHead);
|
| | | return presult;
|
| | | }
|
| | | TaoBaoSearchResult presult = parseTaoBao(result);
|
| | | presult.setKey(filter.getKey());
|
| | | return presult;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 淘宝联盟网页搜索商品
|
| | | * |
| | | * @param filter
|
| | | * @param config
|
| | | * -联盟配置
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoSearchResult searchAlimamaWeb(SearchFilter filter, TaoBaoUnionConfig config, Integer typeNum) {
|
| | |
|
| | | Map<String, String> params = new HashMap<String, String>();
|
| | |
|
| | | if (typeNum != null && !typeNum.equals(0)) {
|
| | | if (channelMap.get(typeNum) != null) {
|
| | | params.put("channel", channelMap.get(typeNum));
|
| | | }
|
| | | }
|
| | |
|
| | | params.put("toPage", filter.getPage() + "");
|
| | | params.put("perPageSize", filter.getPageSize() == 0 ? PAGESIZE + "" : filter.getPageSize() + "");
|
| | |
|
| | | if (typeNum != null && typeNum == 3) {
|
| | | // 查询类目
|
| | | String catIds = filter.getCateIds();
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(catIds)) {
|
| | | // 高佣时根据类目id查询
|
| | | params.put("catIds", catIds); // 类目
|
| | | params.put("level", "1");// 默认一级
|
| | | } else {
|
| | | // 查询条件
|
| | | String key = filter.getKey();
|
| | | if (!StringUtil.isNullOrEmpty(key)) {
|
| | | params.put("q", filter.getKey());
|
| | | }
|
| | | }
|
| | |
|
| | | } else {
|
| | | // 查询条件
|
| | | String key = filter.getKey();
|
| | | if (!StringUtil.isNullOrEmpty(key)) {
|
| | | params.put("q", filter.getKey());
|
| | | }
|
| | | }
|
| | |
|
| | | // 排序字段 3 价格高到低 4 价格低到高
|
| | | // 9 销量高到低 1 收入比率高到低 5 月推广量高到低 7月支出佣金高到低
|
| | | // 13 活动开始时间由近到远 11 活动剩余时间长到短 12 活动剩余时间短到长
|
| | |
|
| | | int sort = filter.getSort();
|
| | | if (sort > 0) {
|
| | | params.put("sortType", sort + "");
|
| | | }
|
| | |
|
| | | // 是否天猫
|
| | | if (filter.isTmall()) {
|
| | | params.put("userType", "1");
|
| | | }
|
| | |
|
| | | // 使用含优惠券
|
| | | int quan = filter.getQuan();
|
| | | if (quan == 1) {
|
| | | params.put("shopTag", "dpyhq");
|
| | | params.put("dpyhq", "1");
|
| | | } /*
|
| | | * else { params.put("shopTag", ""); }
|
| | | */
|
| | |
|
| | | // 销量
|
| | | String startBiz30day = filter.getStartBiz30day();
|
| | | if (!StringUtil.isNullOrEmpty(startBiz30day)) {
|
| | | params.put("startBiz30day", startBiz30day);
|
| | | }
|
| | |
|
| | | // 佣金比例小值
|
| | | int startTkRate = filter.getStartTkRate();
|
| | | if (startTkRate > 0) {
|
| | | params.put("startTkRate", startTkRate / 100 + "");
|
| | | }
|
| | |
|
| | | // 佣金比例大值
|
| | | int endTkRate = filter.getEndTkRate();
|
| | | if (endTkRate > 0) {
|
| | | params.put("endTkRate", endTkRate + "");
|
| | | }
|
| | |
|
| | | // 起始价格
|
| | | if (filter.getStartPrice() != null) {
|
| | |
|
| | | params.put("startPrice", filter.getStartPrice() + "");
|
| | | }
|
| | |
|
| | | // 截止价格
|
| | | if (filter.getEndPrice() != null) {
|
| | | params.put("endPrice", filter.getEndPrice() + "");
|
| | | }
|
| | |
|
| | | if (filter.getParams() != null && filter.getParams().size() > 0) {
|
| | | Set<String> set = filter.getParams();
|
| | | StringBuffer sb = new StringBuffer();
|
| | | int i = 0;
|
| | | for (String ids : set) {
|
| | | if (i == 0) {
|
| | | sb.append(ids);
|
| | | } else {
|
| | | sb.append(";" + ids);
|
| | | }
|
| | | i++;
|
| | | }
|
| | | params.put("pidvid", sb.toString());
|
| | | }
|
| | |
|
| | | params.put("t", System.currentTimeMillis() + "");
|
| | | params.put("_tb_token_", "e430bae750a11");
|
| | |
|
| | | Map<String, String> headers = new HashMap<>();
|
| | |
|
| | | headers.put("referer", "https://pub.alimama.com/promo/search/index.htm");
|
| | |
|
| | | headers.put("User-Agent",
|
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36");
|
| | |
|
| | | String cookie = TaoBaoOrderUtil.getTaoBaoCookie(config.getAccount());
|
| | | headers.put("Cookie", cookie);
|
| | |
|
| | | String url = SEARCH_URL;
|
| | |
|
| | | if (typeNum != null && !typeNum.equals(0)) {
|
| | | url = urlMap.get(typeNum);
|
| | | }
|
| | |
|
| | | String result = TaoBaoHttpUtil.get(url, params, headers, true);
|
| | | if (result == null || "".equals(result)) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | result = result.replace("</span>", "").replace("<span class=H>", "");
|
| | | if (result.contains("<!DOCTYPE html>")) {
|
| | | TaoBaoSearchResult presult = new TaoBaoSearchResult();
|
| | |
|
| | | presult.setNavList(new ArrayList<TaoBaoSearchNav>());
|
| | | presult.setTaoBaoGoodsBriefs(new ArrayList<TaoBaoGoodsBrief>());
|
| | |
|
| | | TaoBaoHead taoBaoHead = new TaoBaoHead();
|
| | | taoBaoHead.setDocsfound(0);
|
| | | presult.setTaoBaoHead(taoBaoHead);
|
| | |
|
| | | return presult;
|
| | | }
|
| | | TaoBaoSearchResult presult = parseTaoBao(result);
|
| | | presult.setKey(filter.getKey());
|
| | |
|
| | | return presult;
|
| | | }
|
| | |
|
| | | public static TaoBaoSearchResult search(SearchFilter filter) {
|
| | | return search(filter, false);
|
| | | }
|
| | |
|
| | | public static TaoBaoSearchResult search2(SearchFilter filter, TaoBaoUnionConfig config) {
|
| | |
|
| | | if (filter.getKey().startsWith("http://") || filter.getKey().startsWith("https://")) {
|
| | | String[] sts = filter.getKey().split("\\?")[1].split("&");
|
| | | for (String st : sts) {
|
| | | if (st.contains("id=")) {
|
| | | String id = st.replace("id=", "").trim();
|
| | | TaoBaoGoodsBrief tb = null;
|
| | | try {
|
| | | tb = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(id));
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
|
| | | goodsList.add(tb);
|
| | | TaoBaoSearchResult result = new TaoBaoSearchResult();
|
| | | result.setTaoBaoGoodsBriefs(goodsList);
|
| | | result.setNavList(new ArrayList<>());
|
| | | TaoBaoHead taoBaoHead = new TaoBaoHead();
|
| | | taoBaoHead.setDocsfound(1);
|
| | | result.setTaoBaoHead(taoBaoHead);
|
| | | result.setPageEntity(new PageEntity());
|
| | | return result;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | List<Long> cateList = null;
|
| | | if (!StringUtil.isNullOrEmpty(filter.getCateIds())) {
|
| | | cateList = new ArrayList<>();
|
| | | for (String c : filter.getCateIds().split(","))
|
| | | cateList.add(Long.parseLong(c));
|
| | | }
|
| | |
|
| | | if (1 > 0)
|
| | | return TaoKeApiUtil.searchWuLiao(filter);
|
| | |
|
| | | Map<String, String> params = new HashMap<String, String>();
|
| | | String key = filter.getKey();
|
| | | if (key != null) {
|
| | | params.put("q", filter.getKey());
|
| | | }
|
| | | params.put("_t", System.currentTimeMillis() + "");
|
| | | params.put("toPage", filter.getPage() + "");
|
| | | params.put("perPageSize", PAGESIZE + "");
|
| | | params.put("auctionTag", "");
|
| | | params.put("shopTag", "");
|
| | | params.put("queryType", "2");
|
| | | params.put("t", System.currentTimeMillis() + "");
|
| | | params.put("_tb_token_", "owxj2i1mfTXq");
|
| | | int type = filter.getType();
|
| | | params.put("channel", channelMap.get(type));
|
| | | if (filter.getSort() > 0) {
|
| | | params.put("sortType", filter.getSort() + "");
|
| | | // params.put("queryType", "0");
|
| | | }
|
| | | String result = TaoBaoHttpUtil.tbGet(urlMap.get(type), params, config.getAccount());
|
| | | result = result.replace("</span>", "").replace("<span class=H>", "");
|
| | | TaoBaoSearchResult presult = parseTaoBao(result);
|
| | | presult.setKey(filter.getKey());
|
| | | return presult;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 9块9 19块9的列表
|
| | | * |
| | | * @param filter
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoSearchResult search3(SearchFilter filter, TaoBaoUnionConfig config) {
|
| | | Map<String, String> params = new HashMap<String, String>();
|
| | | String key = filter.getKey();
|
| | | if (key != null) {
|
| | | params.put("q", filter.getKey());
|
| | | }
|
| | | params.put("_t", System.currentTimeMillis() + "");
|
| | | params.put("toPage", filter.getPage() + "");
|
| | | params.put("perPageSize", PAGESIZE + "");
|
| | | params.put("auctionTag", "");
|
| | | params.put("shopTag", "");
|
| | | params.put("queryType", "2");
|
| | | params.put("t", System.currentTimeMillis() + "");
|
| | | params.put("_tb_token_", "owxj2i1mfTXq");
|
| | | int type = filter.getType();
|
| | | params.put("channel", channelMap.get(type));
|
| | | if (filter.getSort() > 0) {
|
| | | params.put("sortType", filter.getSort() + "");
|
| | | // params.put("queryType", "0");
|
| | | }
|
| | | String result = TaoBaoHttpUtil.tbGet(urlMap.get(type), params, config.getAccount());
|
| | | result = result.replace("</span>", "").replace("<span class=H>", "");
|
| | | TaoBaoSearchResult presult = parseTaoBao(result);
|
| | | presult.setKey(filter.getKey());
|
| | | return presult;
|
| | | }
|
| | |
|
| | | public static TaoBaoSearchResult parseTaoBao(String result) {
|
| | | TaoBaoSearchResult resu = new TaoBaoSearchResult();
|
| | | List<TaoBaoGoodsBrief> list = new ArrayList<TaoBaoGoodsBrief>();
|
| | | JSONObject root = null;
|
| | | try {
|
| | | root = JSONObject.fromObject(result);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | resu.setTaoBaoGoodsBriefs(list);
|
| | | return resu;
|
| | | }
|
| | | Gson gson = new GsonBuilder().create();
|
| | | if (root.optBoolean("ok")) {
|
| | | JSONArray array = root.optJSONObject("data").optJSONArray("pageList");
|
| | | if (array != null) {
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | list.add(gson.fromJson(array.optJSONObject(i).toString(), TaoBaoGoodsBrief.class));
|
| | | }
|
| | | }
|
| | | JSONObject head = root.optJSONObject("data").optJSONObject("head");
|
| | | Type headType = new TypeToken<TaoBaoHead>() {
|
| | | }.getType();
|
| | | TaoBaoHead taoBaoHead = gson.fromJson(head.toString(), headType);
|
| | | resu.setTaoBaoHead(taoBaoHead);
|
| | |
|
| | | JSONArray navArray = root.optJSONObject("data").optJSONArray("navigator");
|
| | | Type type = new TypeToken<ArrayList<TaoBaoSearchNav>>() {
|
| | | }.getType();
|
| | | if (navArray != null) {
|
| | | List<TaoBaoSearchNav> navList = gson.fromJson(navArray.toString(), type);
|
| | | for (TaoBaoSearchNav taoBaoSearchNav : navList) {
|
| | | String tbtype = taoBaoSearchNav.getType();
|
| | | if (!"category".equalsIgnoreCase(tbtype)) {
|
| | | taoBaoSearchNav.setSelector(1);
|
| | | }
|
| | | }
|
| | | resu.setNavList(navList);
|
| | | }
|
| | | JSONObject paginatorObject = root.optJSONObject("data").optJSONObject("paginator");
|
| | | if (paginatorObject != null) {
|
| | | int count = (Integer) paginatorObject.get("items");
|
| | | int totalPage = (Integer) paginatorObject.get("pages");
|
| | | PageEntity pe = new PageEntity();
|
| | | pe.setTotalCount(count);
|
| | | pe.setPageSize(PAGESIZE);
|
| | | pe.setTotalPage(totalPage);
|
| | | resu.setPageEntity(pe);
|
| | | }
|
| | | }
|
| | | for (TaoBaoGoodsBrief taoBaoGoodsBrief : list) {
|
| | | String pictUrl = taoBaoGoodsBrief.getPictUrl();
|
| | | if (!pictUrl.contains("http:") && !pictUrl.contains("https:")) {
|
| | | taoBaoGoodsBrief.setPictUrl("http:" + pictUrl);
|
| | | }
|
| | | }
|
| | | resu.setTaoBaoGoodsBriefs(list);
|
| | |
|
| | | PageEntity pageEntity = resu.getPageEntity();
|
| | | if (pageEntity == null) {
|
| | | PageEntity entity = new PageEntity();
|
| | | resu.setPageEntity(entity);
|
| | | }
|
| | |
|
| | | return resu;
|
| | | }
|
| | |
|
| | | public static List<TaoBaoSearchNav> getBaseNav() {
|
| | | List<TaoBaoSearchNav> list = new ArrayList<TaoBaoSearchNav>();
|
| | |
|
| | | // 设置宝贝类型(淘宝天猫/天猫)
|
| | | // TaoBaoSearchNav shopType = new TaoBaoSearchNav();
|
| | | // shopType.setLevel(1);
|
| | | // shopType.setId(2);
|
| | | // shopType.setName("宝贝类型");
|
| | | // shopType.setType("shoptype");
|
| | | // shopType.setFlag("shoptype");
|
| | | // shopType.setSelector(0);
|
| | | // List<TaoBaoSearchNav> shopTypeChildList = new
|
| | | // ArrayList<TaoBaoSearchNav>();
|
| | | // shopTypeChildList.add(new TaoBaoSearchNav(0, "all", 21, 2, "淘宝天猫",
|
| | | // ""));
|
| | | // shopTypeChildList.add(new TaoBaoSearchNav(0, "tmall", 22, 2, "天猫",
|
| | | // ""));
|
| | | // shopType.setSubIds(shopTypeChildList);
|
| | | // list.add(shopType);
|
| | |
|
| | | // 是否有券
|
| | | // TaoBaoSearchNav quanType = new TaoBaoSearchNav();
|
| | | // quanType.setLevel(1);
|
| | | // quanType.setId(3);
|
| | | // quanType.setName("是否有券");
|
| | | // quanType.setType("quantype");
|
| | | // quanType.setFlag("quantype");
|
| | | // quanType.setSelector(0);
|
| | | // List<TaoBaoSearchNav> quanTypeChildList = new
|
| | | // ArrayList<TaoBaoSearchNav>();
|
| | | // quanTypeChildList.add(new TaoBaoSearchNav(0, "quan", 31, 2, "有券",
|
| | | // ""));
|
| | | // quanTypeChildList
|
| | | // .add(new TaoBaoSearchNav(0, "noquan", 32, 2, "无券", ""));
|
| | | // quanType.setSubIds(quanTypeChildList);
|
| | | // list.add(quanType);
|
| | |
|
| | | // 是否有红包
|
| | | // TaoBaoSearchNav hongbaoType = new TaoBaoSearchNav();
|
| | | // hongbaoType.setLevel(1);
|
| | | // hongbaoType.setId(4);
|
| | | // hongbaoType.setName("是否有红包");
|
| | | // hongbaoType.setType("hongbaotype");
|
| | | // hongbaoType.setFlag("hongbaotype");
|
| | | // hongbaoType.setSelector(0);
|
| | | // List<TaoBaoSearchNav> hongbaoChildList = new
|
| | | // ArrayList<TaoBaoSearchNav>();
|
| | | // hongbaoChildList
|
| | | // .add(new TaoBaoSearchNav(0, "hongbao", 41, 2, "有红包", ""));
|
| | | // hongbaoChildList.add(new TaoBaoSearchNav(0, "nohongbao", 42, 2,
|
| | | // "无红包",
|
| | | // ""));
|
| | | // hongbaoType.setSubIds(hongbaoChildList);
|
| | | // list.add(hongbaoType);
|
| | |
|
| | | // 设置发货地
|
| | | // TaoBaoSearchNav address = new TaoBaoSearchNav();
|
| | | // address.setLevel(1);
|
| | | // address.setId(1);
|
| | | // address.setName("店铺所在地");
|
| | | // address.setType("loc");
|
| | | // address.setFlag("loc");
|
| | | // List<TaoBaoSearchNav> addressChildList = new
|
| | | // ArrayList<TaoBaoSearchNav>();
|
| | | //
|
| | | // list.add(address);
|
| | |
|
| | | return list;
|
| | | }
|
| | |
|
| | | public static TaoBaoGoodsBriefExtra getTaoBaoGoodsBriefExtra(TaoBaoGoodsBrief tb, String proportion, String pid) {
|
| | | TaoBaoGoodsBriefExtra tg = new TaoBaoGoodsBriefExtra();
|
| | | tg.setId(tb.getId());
|
| | | tg.setAuctionId(tb.getAuctionId());
|
| | | tg.setBiz30day(tb.getBiz30day());
|
| | | tg.setSalesCount(TaoBaoUtil.getSaleCount(tb.getBiz30day()));
|
| | | tg.setTitle(tb.getTitle());
|
| | | if (!StringUtil.isNullOrEmpty(tb.getPictUrlWhite()))
|
| | | tg.setPictUrl(TbImgUtil.getTBSize320Img(tb.getPictUrlWhite()));
|
| | | else
|
| | | tg.setPictUrl(TbImgUtil.getTBSize320Img(tb.getPictUrl()));
|
| | | tg.setZkPrice(tb.getZkPrice());
|
| | | tg.setAuctionUrl(tb.getAuctionUrl());
|
| | | tg.setReservePrice(tb.getReservePrice());
|
| | | tg.setUserType(tb.getUserType());
|
| | | tg.setShopTitle(tb.getShopTitle());
|
| | | tg.setTkRate(tb.getTkRate());
|
| | | tg.setSellerId(tb.getSellerId());
|
| | | tg.setState(tb.getState()); // 状态:2018-12-03
|
| | | if (tb.getCouponAmount().compareTo(BigDecimal.valueOf(0)) > 0) {
|
| | |
|
| | | tg.setCoupon(true);// 有券
|
| | |
|
| | | TaoBaoQuanInfo quanInfo = new TaoBaoQuanInfo();
|
| | | quanInfo.setCouponAmount(tb.getCouponAmount());
|
| | | String couponEffectiveEndTime = tb.getCouponEffectiveEndTime();
|
| | | long endtime = TimeUtil.convertDateToTemp(couponEffectiveEndTime);
|
| | | quanInfo.setCouponEffectiveEndTime(endtime + 1000 * 60 * 60 * 24L + "");
|
| | | quanInfo.setCouponEffectiveStartTime(TimeUtil.convertDateToTemp(tb.getCouponEffectiveStartTime()) + "");
|
| | | quanInfo.setCouponInfo(tb.getCouponInfo());
|
| | | quanInfo.setCouponLeftCount(tb.getCouponLeftCount());
|
| | | quanInfo.setCouponLink(
|
| | | TaoBaoCouponUtil.getCoupleUrl(tb.getCouponActivityId(), pid, tb.getAuctionId() + ""));
|
| | | quanInfo.setCouponPrice(MoneyBigDecimalUtil.sub(tg.getZkPrice(), tb.getCouponAmount()));
|
| | | quanInfo.setCouponStartFee(tb.getCouponStartFee());
|
| | | quanInfo.setCouponTotalCount(tb.getCouponTotalCount());
|
| | | tg.setTaoBaoQuanInfo(quanInfo);
|
| | | }
|
| | | TaoBaoHongBaoInfo hongBaoInfo = new TaoBaoHongBaoInfo();
|
| | |
|
| | | hongBaoInfo.setRate("最高40%");
|
| | |
|
| | | String hongbao = getGoodsHongBaoInfo(tb, new BigDecimal(proportion));
|
| | | if (hongbao.contains("最高")) {
|
| | | hongBaoInfo.setType(1);
|
| | | hongBaoInfo.setHongbao(new BigDecimal(0));
|
| | | } else {
|
| | | hongBaoInfo.setRate(hongbao);
|
| | | hongBaoInfo.setHongbao(new BigDecimal(hongbao.replace("¥", "")));
|
| | | }
|
| | |
|
| | | tg.setBaoyou(true);
|
| | |
|
| | | if (tb.getUserType() == 1)
|
| | | tg.setShopType(2);
|
| | | else
|
| | | tg.setShopType(1);
|
| | |
|
| | | if (tb.getCouponAmount().compareTo(BigDecimal.valueOf(0)) == 1)
|
| | | tg.setShowType(3);
|
| | | else
|
| | | tg.setShowType(2);
|
| | |
|
| | | int showType = tg.getShowType();
|
| | | if (showType == 3 || showType == 1) {
|
| | | BigDecimal sub = tg.getZkPrice().subtract(tb.getCouponStartFee());
|
| | | if (sub.compareTo(BigDecimal.valueOf(0)) >= 0) {
|
| | | BigDecimal quanPrice = MoneyBigDecimalUtil.sub(tg.getZkPrice(), tb.getCouponAmount());
|
| | | tg.setQuanPrice(quanPrice);
|
| | | } else {
|
| | | tg.setQuanPrice(tg.getZkPrice());
|
| | | }
|
| | | }
|
| | |
|
| | | tg.setTaoBaoHongBaoInfo(hongBaoInfo);
|
| | |
|
| | | tg.setMoneyType(1);
|
| | | tg.setSalesType(1);
|
| | | // 测试使用
|
| | | // tg.setSalesType(Math.random() > 0.5 ? tg.getSalesType() : 3);
|
| | | // if(Constant.IS_TEST)
|
| | | // {
|
| | | // List<ClientTextStyleVO> labels = new ArrayList<>();
|
| | | // labels.add(new ClientTextStyleVO("标签内容", "#F14242"));
|
| | | // labels.add(new ClientTextStyleVO("标签内容", "#00FF00"));
|
| | | // tg.setLabels(labels);
|
| | | // }
|
| | | 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;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取淘宝推广链接
|
| | | * |
| | | * @param auctionId
|
| | | * @param pid
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoLink getTbLink(long auctionId, String pid, TaoBaoUnionConfig config) {
|
| | | TaoBaoLink tbk = null;
|
| | | String cookie = TaoBaoOrderUtil.getTaoBaoCookie(config.getAccount());
|
| | | String adzoneid = pid.split("_")[3];
|
| | | String siteId = pid.split("_")[2];
|
| | | Map<String, String> headers = new HashMap<>();
|
| | |
|
| | | headers.put("Cookie", cookie);
|
| | | headers.put("Referer", "http://pub.alimama.com/promo/search/index.htm");
|
| | | headers.put("User-Agent",
|
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36");
|
| | | headers.put("Cookie", cookie);
|
| | | headers.put("X-Requested-With", "XMLHttpRequest");
|
| | |
|
| | | String json = TaoBaoHttpUtil.proxyGet("http://pub.alimama.com/common/code/getAuctionCode.json?auctionid="
|
| | | + auctionId + "&adzoneid=" + adzoneid + "&siteid=" + siteId + "&scenes=1", cookie);
|
| | | System.out.println(json);
|
| | | if (json == null || "".equals(json.trim())) {
|
| | | LogHelper.taoBaoLinkError("获取推广链接失败:" + auctionId);
|
| | | return null;
|
| | | }
|
| | |
|
| | | JSONObject data;
|
| | | try {
|
| | | data = JSONObject.fromObject(json);
|
| | | } catch (Exception e) {
|
| | | LogHelper.taoBaoLinkError("获取推广链接失败:" + auctionId);
|
| | | return null;
|
| | | }
|
| | |
|
| | | if (data.optBoolean("ok")) {
|
| | | tbk = new TaoBaoLink();
|
| | | JSONObject dat = data.optJSONObject("data");
|
| | | String couponLink = dat.optString("couponLink");
|
| | | String clickUrl = dat.optString("clickUrl");
|
| | | String taoToken = dat.optString("taoToken");
|
| | | tbk.setCouponLink(couponLink);
|
| | | tbk.setClickUrl(clickUrl);
|
| | | tbk.setTaoToken(taoToken);
|
| | | tbk.setAuctionId(auctionId);
|
| | | return tbk;
|
| | | } else {
|
| | | LogHelper.taoBaoLinkError("获取推广链接失败:" + auctionId);
|
| | | }
|
| | | // 如果json返回的是false,说明cookie失效
|
| | | TaoBaoOrderUtil.reportCookieInvalid(config.getAccount());
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取推广用的淘口令
|
| | | * |
| | | * @param auctionId
|
| | | * @param pid
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoLink getTbLinkForShare(long auctionId, String pid, TaoBaoUnionConfig config) {
|
| | | TaoBaoLink tbk = null;
|
| | | String cookie = TaoBaoOrderUtil.getTaoBaoCookie(config.getAccount());
|
| | | selfAdzoneCreate(pid, cookie);
|
| | | String adzoneid = pid.split("_")[3];
|
| | | String siteId = pid.split("_")[2];
|
| | | Map<String, String> headers = new HashMap<>();
|
| | |
|
| | | headers.put("Cookie", cookie);
|
| | | headers.put("Referer", "http://pub.alimama.com/promo/search/index.htm");
|
| | | headers.put("User-Agent",
|
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36");
|
| | | headers.put("Cookie", cookie);
|
| | | headers.put("X-Requested-With", "XMLHttpRequest");
|
| | |
|
| | | String json = TaoBaoHttpUtil.proxyGet("http://pub.alimama.com/common/code/getAuctionCode.json?auctionid="
|
| | | + auctionId + "&adzoneid=" + adzoneid + "&siteid=" + siteId + "&scenes=1", cookie);
|
| | | System.out.println(json);
|
| | | LogHelper.test(json);
|
| | | if (json == null || "".equals(json.trim())) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | JSONObject data;
|
| | | try {
|
| | | data = JSONObject.fromObject(json);
|
| | | } catch (Exception e) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | if (data.optBoolean("ok")) {
|
| | | tbk = new TaoBaoLink();
|
| | | JSONObject dat = data.optJSONObject("data");
|
| | | String couponLink = dat.optString("couponLink");
|
| | | String clickUrl = dat.optString("clickUrl");
|
| | | String taoToken = dat.optString("taoToken");
|
| | | tbk.setCouponLink(couponLink);
|
| | | tbk.setClickUrl(clickUrl);
|
| | | tbk.setTaoToken(taoToken);
|
| | | tbk.setAuctionId(auctionId);
|
| | |
|
| | | return tbk;
|
| | | }
|
| | | // 如果json返回的是false,说明cookie失效
|
| | | TaoBaoOrderUtil.reportCookieInvalid(config.getAccount());
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 通过优惠券链接获取淘口令
|
| | | * |
| | | * @param picture
|
| | | * @param title
|
| | | * @param activityId
|
| | | * @param auctionId
|
| | | * @param pid
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoLink getTbLinkWithCoupon(String picture, String title, String activityId, long auctionId,
|
| | | String pid) {
|
| | | activityId = StringUtil.isNullOrEmpty(activityId) ? "da75a5880d4c41ab88a82256b069a38c" : activityId;
|
| | | String url = String.format("https://uland.taobao.com/coupon/edetail?activityId=%s&pid=%s&itemId=%s", activityId,
|
| | | pid, auctionId + "");
|
| | | String tbk = TaoKeApiUtil.getTKToken(picture, title, url);
|
| | | if (StringUtil.isNullOrEmpty(tbk))
|
| | | LogHelper.error("生成淘口令失败(优惠券链接):" + auctionId);
|
| | | TaoBaoLink taoBaoLink = new TaoBaoLink();
|
| | | taoBaoLink.setAuctionId(auctionId);
|
| | | taoBaoLink.setClickUrl(url);
|
| | | taoBaoLink.setCouponLink(url);
|
| | | taoBaoLink.setTaoToken(tbk);
|
| | | return taoBaoLink;
|
| | | }
|
| | |
|
| | | private static void selfAdzoneCreate(String pid, String cookie) {
|
| | | String[] sts = cookie.split(";");
|
| | | String tbToken = "";
|
| | | for (String st : sts) {
|
| | | if (st.contains("_tb_token_")) {
|
| | | tbToken = st.replace("_tb_token_=", "");
|
| | | break;
|
| | | }
|
| | | }
|
| | | String adzoneid = pid.split("_")[3];
|
| | | String siteId = pid.split("_")[2];
|
| | | String url = "http://pub.alimama.com/common/adzone/selfAdzoneCreate.json";
|
| | | Map<String, String> params = new HashMap<>();
|
| | | params.put("tag", "29");
|
| | | params.put("gcid", "8");
|
| | | params.put("siteid", siteId);
|
| | | params.put("selectact", "sel");
|
| | | params.put("adzoneid", adzoneid);
|
| | | params.put("t", System.currentTimeMillis() + "");
|
| | | params.put("_tb_token_", tbToken);
|
| | |
|
| | | Map<String, String> headers = new HashMap<>();
|
| | | headers.put("Cookie", cookie);
|
| | | headers.put("Referer", "http://pub.alimama.com/promo/search/index.htm");
|
| | | headers.put("User-Agent",
|
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36");
|
| | | headers.put("Cookie", cookie);
|
| | | headers.put("X-Requested-With", "XMLHttpRequest");
|
| | | String result = TaoBaoHttpUtil.post(url, params, headers);
|
| | | System.out.println(result);
|
| | | }
|
| | |
|
| | | public static TaoBaoGoodsBriefExtra getTaoBaoGoodsBriefExtra(TaoBaoGoodsBrief tb, TaoBaoUnionConfig config) {
|
| | | TaoBaoGoodsBriefExtra tg = new TaoBaoGoodsBriefExtra();
|
| | | 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());
|
| | | 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();
|
| | | quanInfo.setCouponAmount(tb.getCouponAmount());
|
| | | String couponEffectiveEndTime = tb.getCouponEffectiveEndTime();
|
| | | long endtime = TimeUtil.convertDateToTemp(couponEffectiveEndTime);
|
| | | quanInfo.setCouponEffectiveEndTime(endtime + 1000 * 60 * 60 * 24L + "");
|
| | | quanInfo.setCouponEffectiveStartTime(TimeUtil.convertDateToTemp(tb.getCouponEffectiveStartTime()) + "");
|
| | | quanInfo.setCouponInfo(tb.getCouponInfo());
|
| | | quanInfo.setCouponLeftCount(tb.getCouponLeftCount());
|
| | | String pid = config.getDefaultPid();
|
| | | quanInfo.setCouponLink(
|
| | | TaoBaoCouponUtil.getCoupleUrl(tb.getCouponActivityId(), pid, tb.getAuctionId() + ""));
|
| | | quanInfo.setCouponPrice(tb.getZkPrice().subtract(tb.getCouponAmount()));
|
| | | quanInfo.setCouponStartFee(tb.getCouponStartFee());
|
| | | quanInfo.setCouponTotalCount(tb.getCouponTotalCount());
|
| | | tg.setTaoBaoQuanInfo(quanInfo);
|
| | | }
|
| | |
|
| | | BigDecimal proportion = taoBaoUtil.manageService.getFanLiRate();
|
| | | TaoBaoHongBaoInfo hongBaoInfo = new TaoBaoHongBaoInfo();
|
| | | String tkMktStatus = tb.getTkMktStatus();
|
| | | if ("1".equals(tkMktStatus)) {
|
| | | hongBaoInfo.setType(1);
|
| | | }
|
| | |
|
| | | hongBaoInfo.setRate("最高40%");
|
| | |
|
| | | String hongbao = getGoodsHongBaoInfo(tb, proportion);
|
| | | if (!hongbao.contains("最高"))
|
| | | hongBaoInfo.setHongbao(new BigDecimal(hongbao.replace("¥", "")));
|
| | | else
|
| | | hongBaoInfo.setHongbao(new BigDecimal(0));
|
| | |
|
| | | tg.setBaoyou(true);
|
| | |
|
| | | if (tb.getUserType() == 1)
|
| | | tg.setShopType(2);
|
| | | else
|
| | | tg.setShopType(1);
|
| | |
|
| | | if (tb.getCouponAmount().compareTo(BigDecimal.valueOf(0)) == 1)
|
| | | tg.setShowType(3);
|
| | | else
|
| | | tg.setShowType(2);
|
| | |
|
| | | int showType = tg.getShowType();
|
| | | if (showType == 3 || showType == 1) {
|
| | | BigDecimal sub = tg.getZkPrice().subtract(tb.getCouponStartFee());
|
| | | if (sub.compareTo(BigDecimal.valueOf(0)) >= 0) {
|
| | | BigDecimal quanPrice = tg.getZkPrice().subtract(tb.getCouponAmount());
|
| | | tg.setQuanPrice(quanPrice);
|
| | | } else {
|
| | | tg.setQuanPrice(tg.getZkPrice());
|
| | | }
|
| | | }
|
| | | tg.setTaoBaoHongBaoInfo(hongBaoInfo);
|
| | |
|
| | | tg.setMoneyType(1);
|
| | | tg.setSalesType(1);
|
| | | // 测试使用
|
| | | // tg.setMoneyType(Math.random() > 0.5 ? 1 : 2);
|
| | | // tg.setSalesType(Math.random() > 0.5 ? 1 : 2);
|
| | | // tg.setSalesType(Math.random() > 0.5 ? tg.getSalesType() : 3);
|
| | | // List<ClientTextStyleVO> labels = new ArrayList<>();
|
| | | // labels.add(new ClientTextStyleVO("标签内容", "#F14242"));
|
| | | // labels.add(new ClientTextStyleVO("标签内容", "#000000"));
|
| | | // tg.setLabels(labels);
|
| | |
|
| | | 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;
|
| | | }
|
| | |
|
| | | public static List<String> getSuguestSearch(String key) {
|
| | | try {
|
| | | String url = String.format("https://suggest.taobao.com/sug?code=utf-8&q=%s&_=1486720576511",
|
| | | URLEncoder.encode(key, "UTF-8"));
|
| | | HttpClient client = new HttpClient();
|
| | | GetMethod gm = new GetMethod(url);
|
| | | client.executeMethod(gm);
|
| | | String result = gm.getResponseBodyAsString();
|
| | | JSONObject obj = JSONObject.fromObject(result);
|
| | | if (obj != null) {
|
| | | JSONArray array = obj.optJSONArray("result");
|
| | | List<String> list = new ArrayList<String>();
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | list.add(array.optJSONArray(i).optString(0));
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | public static List<String> getTbImg(String auctionId) {
|
| | | if (!NumberUtil.isNumeric(auctionId))
|
| | | return new ArrayList<>();
|
| | | TaoBaoGoodsBrief taoBaoGoodsBrief = null;
|
| | | try {
|
| | | taoBaoGoodsBrief = TaoKeApiUtil.getSimpleGoodsInfo(Long.parseLong(auctionId));
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | List<String> list = new ArrayList<String>();
|
| | | if (taoBaoGoodsBrief == null)
|
| | | return list;
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(taoBaoGoodsBrief.getPictUrl()))
|
| | | list.add(taoBaoGoodsBrief.getPictUrl());
|
| | | if (taoBaoGoodsBrief.getImgList() != null && taoBaoGoodsBrief.getImgList().size() > 0)
|
| | | list.addAll(taoBaoGoodsBrief.getImgList());
|
| | | return list;
|
| | | }
|
| | |
|
| | | public static TaoBaoGoodsBrief isAlimama(String auctionId) {
|
| | | if (StringUtil.isNullOrEmpty(auctionId) || !NumberUtil.isNumeric(auctionId))
|
| | | return null;
|
| | | TaoBaoGoodsBrief tb = null;
|
| | | try {
|
| | | tb = TaoKeApiUtil.getSimpleGoodsInfo(Long.parseLong(auctionId));
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return tb;
|
| | | }
|
| | |
|
| | | public static List<TaoBaoGoodsBriefExtra> getTaoBaoGoodsBriefExtraList(List<TaoBaoCoupon> list) {
|
| | | List<TaoBaoGoodsBriefExtra> tbxs = new ArrayList<TaoBaoGoodsBriefExtra>();
|
| | | TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra = null;
|
| | | TaoBaoQuanInfo taobaoQuanInfo = null;
|
| | | TaoBaoHongBaoInfo taobaoHongbaoInfo = null;
|
| | | for (TaoBaoCoupon taoBaoCoupon : list) {
|
| | | taoBaoGoodsBriefExtra = new TaoBaoGoodsBriefExtra();
|
| | | taobaoQuanInfo = new TaoBaoQuanInfo();
|
| | | taobaoQuanInfo.setCouponAmount(taoBaoCoupon.getCouponAmount());
|
| | | taobaoQuanInfo.setCouponInfo(taoBaoCoupon.getCouponinfo());
|
| | | taobaoQuanInfo.setCouponPrice(taoBaoCoupon.getQuanPrice());
|
| | | taobaoQuanInfo.setCouponLink(taoBaoCoupon.getCouponLink());
|
| | | taobaoHongbaoInfo = new TaoBaoHongBaoInfo();
|
| | | taobaoHongbaoInfo.setHongbao(taoBaoCoupon.getHongbao());
|
| | | taobaoHongbaoInfo.setRate("¥" + taoBaoCoupon.getHongbao().toString());
|
| | |
|
| | | taoBaoGoodsBriefExtra.setTaoBaoHongBaoInfo(taobaoHongbaoInfo);
|
| | | taoBaoGoodsBriefExtra.setTaoBaoQuanInfo(taobaoQuanInfo);
|
| | |
|
| | | taoBaoGoodsBriefExtra.setAuctionId(Long.parseLong(taoBaoCoupon.getAuctionId()));
|
| | | taoBaoGoodsBriefExtra.setAuctionUrl(taoBaoCoupon.getAuctionUrl());
|
| | | taoBaoGoodsBriefExtra.setBaoyou(true);
|
| | | taoBaoGoodsBriefExtra.setBiz30day(taoBaoCoupon.getBiz30day());
|
| | | taoBaoGoodsBriefExtra.setPictUrl(taoBaoCoupon.getPictUrl());
|
| | | taoBaoGoodsBriefExtra.setQuanPrice(taoBaoCoupon.getQuanPrice());
|
| | |
|
| | | int shopType = taoBaoCoupon.getShopType();
|
| | | taoBaoGoodsBriefExtra.setShopType(shopType);
|
| | | taoBaoGoodsBriefExtra.setShowType(taoBaoCoupon.getShowType());
|
| | |
|
| | | taoBaoGoodsBriefExtra.setTitle(taoBaoCoupon.getTitle());
|
| | | taoBaoGoodsBriefExtra.setReservePrice(taoBaoCoupon.getZkPrice());
|
| | | taoBaoGoodsBriefExtra.setZkPrice(taoBaoCoupon.getZkPrice());
|
| | | taoBaoGoodsBriefExtra.setSellerId(taoBaoCoupon.getSellerId());
|
| | | tbxs.add(taoBaoGoodsBriefExtra);
|
| | | }
|
| | |
|
| | | return tbxs;
|
| | | }
|
| | |
|
| | | public static TaoBaoGoodsBrief parsePhoneShareUrlByTM(String murl) {
|
| | | if (!murl.contains("http://zmnxbc.com")) { // 手机天猫分享
|
| | | return null;
|
| | | }
|
| | | TaoBaoGoodsBrief taobao;
|
| | | try {
|
| | | Connection connect = Jsoup.connect(murl);
|
| | | Document document = connect.get();
|
| | | org.jsoup.nodes.Element element = document.getElementsByTag("head").get(0).getElementsByTag("Script")
|
| | | .get(2);
|
| | | String html = element.html();
|
| | | String json = html.substring(html.indexOf("{"), html.lastIndexOf("}") + 1);
|
| | | JSONObject data = JSONObject.fromObject(json);
|
| | | String auctionId = data.optString("bizId");
|
| | | TaoBaoGoodsBrief alimama = isAlimama(auctionId);
|
| | | if (alimama != null) {
|
| | | return alimama;
|
| | | }
|
| | | String price = data.optString("itemPrice", "0");
|
| | | String title = data.optString("content");
|
| | | String url = data.optJSONArray("actionRule").optJSONObject(0).optString("url");
|
| | | Document document2 = Jsoup.connect("http:" + url).get();
|
| | | org.jsoup.nodes.Element element2 = document2.getElementById("s-showcase").getElementsByClass("scroller")
|
| | | .get(0);
|
| | | Elements elements = element2.getElementsByClass("item");
|
| | | List<String> imgStrs = new ArrayList<String>();
|
| | | for (org.jsoup.nodes.Element e : elements) {
|
| | | org.jsoup.nodes.Element img = e.getElementsByTag("img").get(0);
|
| | | String attr = img.attr("src");
|
| | | if (attr == "") {
|
| | | attr = img.attr("data-src");
|
| | | }
|
| | | if (!attr.contains("http:")) {
|
| | | attr = "http:" + attr;
|
| | | }
|
| | | imgStrs.add(attr);
|
| | | }
|
| | | taobao = new TaoBaoGoodsBrief();
|
| | | taobao.setAuctionId(Long.parseLong(auctionId));
|
| | | taobao.setTitle(title);
|
| | | taobao.setZkPrice(new BigDecimal(price));
|
| | | taobao.setImgList(imgStrs);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | return null;
|
| | | }
|
| | | return taobao;
|
| | | }
|
| | |
|
| | | public static TaoBaoGoodsBrief parsePhoneShareUrlByTB(String burl) {
|
| | | try {
|
| | | Connection connect = Jsoup.connect(burl);
|
| | | Document document = connect.get();
|
| | | org.jsoup.nodes.Element element = document.getElementsByTag("head").get(0).getElementsByTag("Script")
|
| | | .get(1);
|
| | | String html = element.toString();
|
| | | int index = html.indexOf("var url = ");
|
| | | int endIndex = html.lastIndexOf("'");
|
| | | html = html.substring(index, endIndex);
|
| | | int index2 = html.indexOf("'");
|
| | | html = html.substring(index2 + 1);
|
| | | int indexId = html.indexOf("id=");
|
| | | String id = "";
|
| | | if (html.contains("a.m.taobao.com")) {
|
| | | indexId = html.indexOf("com/i");
|
| | | html = html.substring(indexId);
|
| | | html = html.substring(5, html.indexOf("."));
|
| | | id = html;
|
| | | } else {
|
| | | String reg = "[?|&]{1}[i]{1}[d]{1}[=]{1}\\d+[&]?";
|
| | | Pattern p = Pattern.compile(reg);
|
| | | Matcher matcher = p.matcher(html);
|
| | | if (matcher.find()) {
|
| | | id = matcher.group();
|
| | | }
|
| | | id = id.substring(id.indexOf("=") + 1, id.lastIndexOf("&"));
|
| | | }
|
| | | TaoBaoGoodsBrief alimama = isAlimama(id);
|
| | |
|
| | | if (alimama != null) {
|
| | | return alimama;
|
| | | }
|
| | | return parsePhoneTmAndTb(id);
|
| | | } catch (Exception e) {
|
| | | LogHelper.error("无法解析到淘宝商品ID:" + burl);
|
| | | return null;
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | public static TaoBaoGoodsBrief parsePhoneTmAndTb(String auctionId) {
|
| | |
|
| | | TaoBaoGoodsBrief taoBaoGoodsBrief = null;
|
| | | try {
|
| | |
|
| | | Connection connect = Jsoup.connect(String.format(TM_PHONE_URL, auctionId));
|
| | | Document document = connect.get();
|
| | | Elements elements = document.getElementsByTag("script");
|
| | | if (elements.size() >= 9) {
|
| | | String json = elements.get(8).toString();
|
| | | json = json.substring(json.indexOf("{"), json.lastIndexOf("}") + 1);
|
| | | JSONObject data = JSONObject.fromObject(json);
|
| | | JSONObject model = data.optJSONObject("defaultModel");
|
| | | JSONObject itemPriceResultDO = model.optJSONObject("itemPriceResultDO");
|
| | | JSONObject priceInfo = itemPriceResultDO.optJSONObject("priceInfo");
|
| | | Set keySet = priceInfo.keySet();
|
| | | String key = (String) keySet.toArray()[0];
|
| | | JSONObject goods = priceInfo.optJSONObject(key);
|
| | | String price = "";
|
| | | if (goods.optJSONArray("promotionList") != null) {
|
| | | price = goods.optJSONArray("promotionList").getJSONObject(0).optString("price");
|
| | | } else {
|
| | | price = goods.optString("price");
|
| | | }
|
| | | List<String> imgs = new ArrayList<String>();
|
| | | Element showcase = document.getElementById("s-showcase");
|
| | | Elements Eleimgs = showcase.getElementsByTag("img");
|
| | | for (Element Eleimg : Eleimgs) {
|
| | | String img = Eleimg.attr("src");
|
| | | if ("".equals(img)) {
|
| | | img = Eleimg.attr("data-src");
|
| | | }
|
| | | if (!img.contains("http")) {
|
| | | img = "http:" + img;
|
| | | }
|
| | | imgs.add(img);
|
| | | }
|
| | | Element stitle = document.getElementById("s-title");
|
| | | String title = stitle.getElementsByTag("h1").get(0).toString().replaceAll("<h1>", "")
|
| | | .replaceAll("</h1>", "");
|
| | | taoBaoGoodsBrief = new TaoBaoGoodsBrief();
|
| | | taoBaoGoodsBrief.setZkPrice(new BigDecimal(price));
|
| | | taoBaoGoodsBrief.setTitle(title);
|
| | | taoBaoGoodsBrief.setImgList(imgs);
|
| | | taoBaoGoodsBrief.setPictUrl(imgs.get(0));
|
| | | taoBaoGoodsBrief.setAuctionId(Long.parseLong(auctionId));
|
| | | taoBaoGoodsBrief.setUserType(1);
|
| | | } else {
|
| | | Connection connect2 = Jsoup.connect(String.format(TB_URL, auctionId));
|
| | | Document document2 = connect2.get();
|
| | | Elements elements2 = document2.getElementsByTag("script");
|
| | | String json = elements2.get(0).toString();
|
| | | json = json.substring(json.indexOf("item:"), json.indexOf("seller:"));
|
| | | json = json.substring(json.indexOf("{"), json.lastIndexOf(","));
|
| | | json = json.substring(json.indexOf("auctionImages"), json.lastIndexOf("]") + 1);
|
| | | json = json.substring(json.indexOf("["));
|
| | | JSONArray array = JSONArray.fromObject(json);
|
| | | List<String> imgs = new ArrayList<String>();
|
| | | for (Object str : array) {
|
| | | String imgStr = String.valueOf(str);
|
| | | if (!imgStr.contains("http")) {
|
| | | imgStr = "http:" + imgStr;
|
| | | }
|
| | | imgs.add(imgStr);
|
| | | }
|
| | | String turl = "https://detailskip.taobao.com/service/getData/1/p1/item/detail/sib.htm?itemId="
|
| | | + auctionId
|
| | | + "&sellerId=0&modules=dynStock,qrcode,viewer,price,duty,xmpPromotion,delivery,upp,activity,fqg,zjys,couponActivity,soldQuantity,contract,tradeContract&callback=onSibRequestSuccess";
|
| | | Map<String, String> params = new HashMap<String, String>();
|
| | | params.put("Referer", "https://item.taobao.com/item.htm?id=" + auctionId);
|
| | | String json2 = TaoBaoHttpUtil.get(turl, params);
|
| | | json2 = json2.substring(json2.indexOf("{"), json2.lastIndexOf("}") + 1);
|
| | | JSONObject data2 = JSONObject.fromObject(json2);
|
| | | String price = data2.optJSONObject("data").optJSONObject("promotion").optJSONObject("promoData")
|
| | | .optJSONArray("def").getJSONObject(0).optString("price");
|
| | | String title = document2.getElementsByTag("title").get(0).toString();
|
| | | title = title.replaceAll("-淘宝网", "").replaceAll("<title>", "").replaceAll("</title>", "");
|
| | | taoBaoGoodsBrief = new TaoBaoGoodsBrief();
|
| | | taoBaoGoodsBrief.setTitle(title);
|
| | | taoBaoGoodsBrief.setPictUrl(imgs.get(0));
|
| | | taoBaoGoodsBrief.setImgList(imgs);
|
| | | taoBaoGoodsBrief.setZkPrice(new BigDecimal(price));
|
| | | taoBaoGoodsBrief.setAuctionId(Long.parseLong(auctionId));
|
| | | taoBaoGoodsBrief.setUserType(0);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | return null;
|
| | | }
|
| | | return taoBaoGoodsBrief;
|
| | | }
|
| | |
|
| | | public static String getGoodsIdByPhoneShareUrl(String burl) {
|
| | | try {
|
| | | Connection connect = Jsoup.connect(burl);
|
| | | Document document = connect.get();
|
| | | org.jsoup.nodes.Element element = document.getElementsByTag("head").get(0).getElementsByTag("Script")
|
| | | .get(1);
|
| | | String html = element.toString();
|
| | | int index = html.indexOf("var url = ");
|
| | | int endIndex = html.lastIndexOf("'");
|
| | | html = html.substring(index, endIndex);
|
| | | int index2 = html.indexOf("'");
|
| | | html = html.substring(index2 + 1);
|
| | | int indexId = html.indexOf("id=");
|
| | | String id = "";
|
| | | if (html.contains("a.m.taobao.com")) {
|
| | | indexId = html.indexOf("com/i");
|
| | | html = html.substring(indexId);
|
| | | html = html.substring(5, html.indexOf("."));
|
| | | id = html;
|
| | | } else {
|
| | | String reg = "[?|&]{1}[i]{1}[d]{1}[=]{1}\\d+[&]?";
|
| | | Pattern p = Pattern.compile(reg);
|
| | | Matcher matcher = p.matcher(html);
|
| | | if (matcher.find()) {
|
| | | id = matcher.group();
|
| | | }
|
| | | id = id.substring(id.indexOf("=") + 1, id.lastIndexOf("&"));
|
| | | }
|
| | | return id;
|
| | | } catch (Exception e) {
|
| | | LogHelper.error("无法解析到淘宝商品ID:" + burl);
|
| | | return null;
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取商品的用户分成比例
|
| | | * |
| | | * @param goodsBrief
|
| | | * 商品详情
|
| | | * @param rate
|
| | | * 用户再次分成比例(0-100)
|
| | | * @return
|
| | | */
|
| | | public static String getGoodsHongBaoInfo(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) {
|
| | | // if (goodsBrief != null && goodsBrief.getMaterialLibType() != null &&
|
| | | // goodsBrief.getMaterialLibType() == 0)
|
| | | // return "¥0.00";
|
| | | // else
|
| | | return "¥" + getGoodsHongBaoMoney(goodsBrief, rate).toString();
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取淘宝商品该获得多少佣金
|
| | | * |
| | | * @param goodsBrief
|
| | | * @param rate
|
| | | * @return
|
| | | */
|
| | | public static BigDecimal getGoodsHongBaoMoney(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) {
|
| | | BigDecimal money = null;
|
| | | if (StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo())
|
| | | || goodsBrief.getCouponInfo().trim().equalsIgnoreCase("无")) {
|
| | | money = MoneyBigDecimalUtil.mul(
|
| | | MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(goodsBrief.getZkPrice(), goodsBrief.getTkRate()),
|
| | | new BigDecimal("0.01")),
|
| | | MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
|
| | | } else// 有券
|
| | | {
|
| | | List<BigDecimal> list = TaoBaoCouponUtil.getCouponInfo(goodsBrief.getCouponInfo());
|
| | | BigDecimal startFee = list.get(0);
|
| | | BigDecimal couponAccount = list.get(1);
|
| | | if (startFee.compareTo(goodsBrief.getZkPrice()) <= 0
|
| | | && goodsBrief.getZkPrice().compareTo(couponAccount) > 0) {
|
| | | BigDecimal finalPrice = goodsBrief.getZkPrice().subtract(couponAccount);
|
| | | money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil
|
| | | .mul(MoneyBigDecimalUtil.mul(finalPrice, goodsBrief.getTkRate()), new BigDecimal("0.01")),
|
| | | MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
|
| | |
|
| | | } else {// 不能用券
|
| | | money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(
|
| | | MoneyBigDecimalUtil.mul(goodsBrief.getZkPrice(), goodsBrief.getTkRate()),
|
| | | new BigDecimal("0.01")), MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
|
| | | }
|
| | | }
|
| | | return BigDecimalUtil.getWithNoZera(money);
|
| | | }
|
| | |
|
| | | // }
|
| | |
|
| | | // 获取券的红包显示
|
| | | public static BigDecimal getCouponHongBaoInfo(TaoBaoCoupon taoBaoCoupon, BigDecimal rate) {
|
| | | // 营销计划
|
| | |
|
| | | // 计算返利
|
| | | // 无券
|
| | |
|
| | | BigDecimal startFee = taoBaoCoupon.getCouponStartFee();
|
| | | BigDecimal couponAccount = taoBaoCoupon.getCouponAmount();
|
| | | if (startFee.compareTo(taoBaoCoupon.getZkPrice()) <= 0
|
| | | && taoBaoCoupon.getZkPrice().compareTo(couponAccount) > 0) {
|
| | | BigDecimal finalPrice = taoBaoCoupon.getZkPrice().subtract(couponAccount);
|
| | | return finalPrice.multiply(new BigDecimal(taoBaoCoupon.getTkRate())).divide(new BigDecimal(10000))
|
| | | .multiply(rate).setScale(2, BigDecimal.ROUND_DOWN);
|
| | | } else {// 不能用券
|
| | | return taoBaoCoupon.getZkPrice().multiply(new BigDecimal(taoBaoCoupon.getTkRate()))
|
| | | .divide(new BigDecimal(10000)).multiply(rate).setScale(2, BigDecimal.ROUND_DOWN);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取分享赚的金额
|
| | | * |
| | | * @param goodsBrief
|
| | | * @param rate
|
| | | * @return
|
| | | */
|
| | |
|
| | | public static BigDecimal getShareGoodsHongBaoInfo(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) {
|
| | | return getGoodsHongBaoMoney(goodsBrief, rate);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 计算商品券后价,没有券则返回原价
|
| | | * |
| | | * @param goodsBrief
|
| | | * @return
|
| | | */
|
| | | public static BigDecimal getAfterUseCouplePrice(TaoBaoGoodsBrief goodsBrief) {
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo()) || "无".equals(goodsBrief.getCouponInfo())) {
|
| | | return goodsBrief.getZkPrice();
|
| | | } else {
|
| | | List<BigDecimal> list = TaoBaoCouponUtil.getCouponInfo(goodsBrief.getCouponInfo());
|
| | | BigDecimal startFee = list.get(0);
|
| | | BigDecimal couponAccount = list.get(1);
|
| | | if (startFee.compareTo(goodsBrief.getZkPrice()) <= 0
|
| | | && goodsBrief.getZkPrice().compareTo(couponAccount) > 0) {
|
| | | BigDecimal finalPrice = goodsBrief.getZkPrice().subtract(couponAccount);
|
| | | return finalPrice;
|
| | | } else {// 不能用券
|
| | | return goodsBrief.getZkPrice();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取图文详情
|
| | | * |
| | | * @param auctionId
|
| | | */
|
| | | public static List<String> getGoodsTextAndImageDetails(Long id) {
|
| | | if (id == null) {
|
| | | return null;
|
| | | }
|
| | | long startTime = System.currentTimeMillis();
|
| | |
|
| | | String url = null;
|
| | | try {
|
| | | url = String.format("http://hws.m.taobao.com/cache/mtop.wdetail.getItemDescx/4.1/?&data=%s&type=jsonp",
|
| | | URLEncoder.encode("{\"item_num_id\":\"" + id + "\"}", "UTF-8"));
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | List<String> list = new ArrayList<>();
|
| | | String html = org.yeshi.utils.HttpUtil.get(url);
|
| | | String json = html.substring(9, html.length() - 1);
|
| | |
|
| | | try {
|
| | | JSONObject obj = JSONObject.fromObject(json);
|
| | | JSONArray array = obj.getJSONObject("data").optJSONArray("images");
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | list.add(array.optString(i));
|
| | | }
|
| | | LogHelper.test("获取商品图文详情耗时:" + (System.currentTimeMillis() - startTime));
|
| | | } catch (Exception e) {
|
| | |
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | public static String getSaleCount(int count) {
|
| | | if (count >= 10000) {
|
| | | double sales = count;
|
| | | String salesCountMidea = String.format("%.1f", sales / 10000);
|
| | | return salesCountMidea + "万";
|
| | | } else
|
| | | return count + "";
|
| | | }
|
| | |
|
| | | public static List<TaoBaoProvince> getTaoBaoProvinceList() {
|
| | | if (taoBaoProvinceList == null) {
|
| | | taoBaoProvinceList = new ArrayList<>();
|
| | | // 解析
|
| | | try {
|
| | | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
| | | DocumentBuilder builder = factory.newDocumentBuilder();
|
| | | org.w3c.dom.Document doc = builder
|
| | | .parse(TaoBaoUtil.class.getClassLoader().getResourceAsStream("taobao_address.xml"));
|
| | | NodeList nodeList = doc.getElementsByTagName("province");
|
| | | nodeList = nodeList.item(0).getChildNodes();
|
| | | for (int i = 0; i < nodeList.getLength(); i++) {
|
| | | TaoBaoProvince province = new TaoBaoProvince();
|
| | | org.w3c.dom.Node node = nodeList.item(i);
|
| | | if (node.getNodeName().equalsIgnoreCase("topName")) {
|
| | | NamedNodeMap map = node.getAttributes();
|
| | | for (int n = 0; n < map.getLength(); n++) {
|
| | | if (map.item(n).getNodeName().equalsIgnoreCase("id")) {
|
| | | province.setId(map.item(n).getNodeValue());
|
| | | } else if (map.item(n).getNodeName().equalsIgnoreCase("name")) {
|
| | | province.setName(map.item(n).getNodeValue());
|
| | | }
|
| | | }
|
| | | taoBaoProvinceList.add(province);
|
| | | }
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | |
|
| | | }
|
| | | }
|
| | | return taoBaoProvinceList;
|
| | | }
|
| | |
|
| | | public static List<ImageInfo> getTBDetailImageWithSize(Long auctionId) {
|
| | |
|
| | | List<ImageInfo> imgList = new ArrayList<>();
|
| | |
|
| | | long startTime = System.currentTimeMillis();
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("id", auctionId + "");
|
| | | String url = "";
|
| | | try {
|
| | | url = String.format(
|
| | | "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 pcDescContent = data.optJSONObject("data").optString("pcDescContent");
|
| | | System.out.println(pcDescContent);
|
| | | if (!StringUtil.isNullOrEmpty(pcDescContent)) {
|
| | | try {
|
| | | 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) {
|
| | | }
|
| | | }
|
| | | System.out.println("请求详情耗时:" + (System.currentTimeMillis() - startTime));
|
| | | return imgList;
|
| | | }
|
| | |
|
| | | /**
|
| | | * |
| | | * @param auctionId
|
| | | * @return
|
| | | */
|
| | |
|
| | | 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, 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]));
|
| | | }
|
| | | 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);
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | return imgList;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 阿里百川转链接口(暂时无法使用)
|
| | | * |
| | | * @param auctionId
|
| | | * @param appKey
|
| | | * @param adzoneId
|
| | | * @return
|
| | | */
|
| | | public static String getBaiChuanConvertLink(Long auctionId, String appKey, String adzoneId) {
|
| | | String url = "http://acs4baichuan.m.taobao.com/gw-open/mtop.taobao.tbk.sdk.item.convert/1.0/";
|
| | | JSONObject params = new JSONObject();
|
| | | params.put("mcid", "tunion4android@862977040115210");
|
| | | params.put("appVersion", "1.3.4");
|
| | | params.put("os", "android8.0.0");
|
| | | params.put("taokeAppkey", appKey);
|
| | | params.put("jtype", "tb");
|
| | | params.put("aliapp", "tb");
|
| | | params.put("adzoneid", adzoneId);
|
| | | params.put("url", "https://h5.m.taobao.com/awp/core/detail.htm?id=" + auctionId);
|
| | | params.put("deviceModel", "LND-AL30");
|
| | | params.put("sdkVersion", "0.3.2");
|
| | | params.put("packageName", "com.yeshi.ec.rebate");
|
| | | params.put("cid", "tunion4android@862977040115210_1536222395791");
|
| | |
|
| | | try {
|
| | | url += "?data=" + URLEncoder.encode(params.toString(), "UTF-8");
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | String result = HttpUtil.get(url);
|
| | | System.out.println(result);
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 常规商品转为淘宝商品对象
|
| | | * |
| | | * @param commonGoods
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoGoodsBrief convert(CommonGoods commonGoods) {
|
| | | TaoBaoGoodsBrief taoBaoGoods = new TaoBaoGoodsBrief();
|
| | | taoBaoGoods.setAuctionId(commonGoods.getGoodsId());
|
| | | taoBaoGoods.setBiz30day(commonGoods.getSales());
|
| | | taoBaoGoods.setCouponAmount(commonGoods.getCouponAmount());
|
| | | taoBaoGoods.setCouponInfo(commonGoods.getCouponInfo());
|
| | | taoBaoGoods.setCouponLeftCount(commonGoods.getCouponLeftCount());
|
| | | taoBaoGoods.setCouponStartFee(commonGoods.getCouponStartPrice());
|
| | | taoBaoGoods.setCouponTotalCount(commonGoods.getCouponTotalCount());
|
| | | taoBaoGoods.setPictUrl(commonGoods.getPicture());
|
| | | taoBaoGoods.setPictUrlWhite(commonGoods.getPictureWhite());
|
| | | taoBaoGoods.setSellerId(commonGoods.getSellerId());
|
| | | taoBaoGoods.setShopTitle(commonGoods.getSellerName());
|
| | | taoBaoGoods.setTitle(commonGoods.getTitle());
|
| | | taoBaoGoods.setUserType(commonGoods.getShopType() - 1);
|
| | | taoBaoGoods.setZkPrice(commonGoods.getPrice());
|
| | | taoBaoGoods.setTkRate(commonGoods.getRate());
|
| | | taoBaoGoods.setTkCommFee(new BigDecimal("0"));
|
| | | taoBaoGoods.setState(commonGoods.getState());
|
| | | 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());
|
| | | taoBaoGoods.setBiz30day(detail.getMonthSales());
|
| | | taoBaoGoods.setCouponAmount(detail.getCouponPrice());
|
| | | taoBaoGoods.setCouponInfo(String.format("满%s元减%s元", detail.getCouponConditions(),
|
| | | MoneyBigDecimalUtil.getWithNoZera(detail.getCouponPrice())));
|
| | | if (detail.getCouponTotalNum() != null && detail.getCouponReceiveNum() != null)
|
| | | taoBaoGoods.setCouponLeftCount(detail.getCouponTotalNum() - detail.getCouponReceiveNum());
|
| | | else
|
| | | taoBaoGoods.setCouponLeftCount(0);
|
| | | taoBaoGoods.setCouponStartFee(detail.getOriginalPrice());
|
| | | taoBaoGoods.setCouponTotalCount(detail.getCouponTotalNum());
|
| | | taoBaoGoods.setPictUrl(detail.getMainPic());
|
| | | taoBaoGoods.setPictUrlWhite(detail.getMainPic());
|
| | | if (taoBaoGoods.getPictUrl() != null && !taoBaoGoods.getPictUrl().startsWith("http"))
|
| | | taoBaoGoods.setPictUrl("https:" + taoBaoGoods.getPictUrl());
|
| | |
|
| | | if (taoBaoGoods.getPictUrlWhite() != null && !taoBaoGoods.getPictUrlWhite().startsWith("http"))
|
| | | taoBaoGoods.setPictUrlWhite("https:" + taoBaoGoods.getPictUrlWhite());
|
| | |
|
| | | taoBaoGoods.setSellerId(detail.getSellerId());
|
| | | taoBaoGoods.setShopTitle(detail.getShopName());
|
| | | taoBaoGoods.setTitle(detail.getDtitle());
|
| | | taoBaoGoods.setUserType(detail.getShopType());
|
| | | taoBaoGoods.setZkPrice(detail.getOriginalPrice());
|
| | | taoBaoGoods.setTkRate(detail.getCommissionRate());
|
| | | taoBaoGoods.setTkCommFee(new BigDecimal("0"));
|
| | | taoBaoGoods.setState(0);
|
| | | return taoBaoGoods;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取淘宝联盟的授权链接
|
| | | * |
| | | * @param appKey
|
| | | * -应用Key
|
| | | * @param callBackUrl
|
| | | * -回调链接
|
| | | * @param uid-用户ID
|
| | | * @return
|
| | | */
|
| | | public static String getTaoBaoUnionAuthUrl(String appKey, String callBackUrl, Long uid, String source) {
|
| | | if (uid == null)
|
| | | return null;
|
| | | long timestamp = System.currentTimeMillis();
|
| | | JSONObject json = new JSONObject();
|
| | | json.put("u", uid);
|
| | | json.put("t", timestamp);
|
| | | json.put("s", source);
|
| | | String url = null;
|
| | | try {
|
| | | url = String.format(
|
| | | "https://oauth.taobao.com/authorize?response_type=code&client_id=%s&redirect_uri=%s&state=%s&view=wap",
|
| | | appKey, callBackUrl,
|
| | | URLEncoder.encode(AESUtil.encrypt(json.toString(), Constant.UIDAESKEY), "UTF-8"));
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return url;
|
| | | }
|
| | |
|
| | | 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",
|
| | | URLEncoder.encode(data.toString(), "UTF-8"));
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | HttpClient client = new HttpClient();
|
| | | GetMethod gm = new GetMethod(url);
|
| | | String result = null;
|
| | | try {
|
| | | gm.setRequestHeader("user-agent",
|
| | | "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Mobile Safari/537.36");
|
| | | gm.setRequestHeader("cache-control", "max-age=0");
|
| | | gm.setRequestHeader("sec-fetch-mode", "navigate");
|
| | | gm.setRequestHeader("sec-fetch-site", "none");
|
| | | gm.setRequestHeader("sec-fetch-user", "?1");
|
| | | gm.setRequestHeader("upgrade-insecure-requests", "1");
|
| | | gm.setRequestHeader("cookie",
|
| | | "t=2ef08e4a12314c12dcd98d2ec480dd69; thw=cn; hng=CN%7Czh-CN%7CCNY%7C156; x=e%3D1%26p%3D*%26s%3D0%26c%3D0%26f%3D0%26g%3D0%26t%3D0%26__ll%3D-1%26_ato%3D0; ali_ab=113.251.19.3.1554796147005.0; UM_distinctid=16b9d8257dd388-0a96f36f947888-e343166-1fa400-16b9d8257df114; WAPFDFDTGFG=%2B4cMKKP%2B8PI%2BuhLvELc2mB6zAz5Z54E%3D; _w_app_lg=0; enc=00wU0%2BKYu9Yf1tHSawG%2Bc4aMZojqg8eB6baoMr9Z8Ir4qJ6hRhMhdWQxbM71vvxv6OCsxN50T0xA1gJGIdFm7w%3D%3D; cna=Q9eYFEM1rm8CAXH7EKUDSamu; miid=769739881160810491; lgc=%5Cu6930%5Cu89C6%5Cu79D1%5Cu6280; tracknick=%5Cu6930%5Cu89C6%5Cu79D1%5Cu6280; tg=0; mt=ci=7_1; cookie2=13ad477d84d5e6659aa7855de3617163; _tb_token_=ee895586817b0; dnk=%5Cu6930%5Cu89C6%5Cu79D1%5Cu6280; v=0; _m_h5_tk=286f649add5207dfe82e770832daf1cc_1573547306314; _m_h5_tk_enc=137c39dafc279e40edc796770d3eda8f; tk_trace=oTRxOWSBNwn9dPyorMJE%2FoPdY8zZPEr%2FCrvCMS%2BG3sTRRWrQ%2BVVTl09ME1KrXdbd3QNiuPM1YZeXJrHpvLuG%2FSvA2umbWq5jqrcw%2FDpk1Lj6yQFVptx6jw71DzuBbw%2BuZLEozdKGb%2BZr85uzSnUSWfVAqZprzoB%2Bfde2IHnHJp651xghkKpmsSBgY5muhOI7FvNfc8zH1BIvygVQSEIa1bCCgy2VJl%2FkyuTXaGHb%2FAKxL566%2FLult1lRlo8RZx9s76BhXe7PTot5MPGrayPkRiqWfVdg3C7gFWRjrjjKriN47mbQazOoIM7knBX%2B3mnnmwWbCQjKiuA6I8W9ng%3D%3D; _cc_=VFC%2FuZ9ajQ%3D%3D; unb=3327215652; uc1=lng=zh_CN&tag=8&cookie16=W5iHLLyFPlMGbLDwA%2BdvAGZqLg%3D%3D&cookie15=VT5L2FSpMGV7TQ%3D%3D&cookie14=UoTbnrCeRJd%2F2g%3D%3D&pas=0&existShop=false&cookie21=VFC%2FuZ9aj38X; uc3=vt3=F8dByuWjrX8oBIwXl2Q%3D&nk2=sbdfkkkB37A%3D&id2=UNN%2F6whEupDGWQ%3D%3D&lg2=WqG3DMC9VAQiUQ%3D%3D; csg=30373d82; cookie17=UNN%2F6whEupDGWQ%3D%3D; skt=6a0617b2d0843ef4; existShop=MTU3MzgxNDAxNw%3D%3D; uc4=id4=0%40UgQ3BPth2rlXv3PxjwesD5MgnRD3&nk4=0%40s9JQzQv3gdCkG6YVO6ulkEbNug%3D%3D; _l_g_=Ug%3D%3D; sg=%E6%8A%8021; _nk_=%5Cu6930%5Cu89C6%5Cu79D1%5Cu6280; cookie1=AnRaCZfOZrWoY8u%2BoXxB8y%2FnnwnZszWqI6Bbr5BrFtM%3D; isg=BOnpxPqJkNY3p6zvIy1AdcEC-JVDtt3of1m6aoveZVAPUglk0wbtuNdAFL5BUXUg; l=dBgUvWMcqlf1dR9EBOCanurza77OSIRYYuPzaNbMi_5IT6T6q1QOkBPUkF96VfWfTVLB47_ypV99-etkZ2ejm8IpXUJsAMc.");
|
| | | client.executeMethod(gm);
|
| | | result = gm.getResponseBodyAsString();
|
| | | } catch (HttpException e) {
|
| | | e.printStackTrace();
|
| | | } catch (IOException e) {
|
| | | e.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.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);
|
| | | }
|
| | | 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;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 根据商品ID获取店铺详情
|
| | | * |
| | | * @param auctionId
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoShop getTaoBaoShopDetailByAuctionId(Long auctionId) {
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("itemNumId", auctionId + "");
|
| | |
|
| | | String url = "";
|
| | | try {
|
| | | url = String.format("https://acs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?data=%s",
|
| | | URLEncoder.encode(data.toString(), "UTF-8"));
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | String result = HttpUtil.get(url);
|
| | |
|
| | | TaoBaoShop shop = new TaoBaoShop();
|
| | |
|
| | | try {
|
| | | JSONObject resultJson = JSONObject.fromObject(result);
|
| | | JSONObject dataJson = resultJson.optJSONObject("data");
|
| | | JSONObject sellerJson = dataJson.optJSONObject("seller");
|
| | |
|
| | | shop.setGoodRatePercentage(new BigDecimal(sellerJson.optString("goodRatePercentage").replace("%", "")));
|
| | |
|
| | | LogHelper.test("卖家信息:" + result);
|
| | | shop.setId(sellerJson.optLong("userId"));
|
| | | JSONArray array = sellerJson.optJSONArray("evaluates");
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | JSONObject item = array.optJSONObject(i);
|
| | | if ("宝贝描述".equalsIgnoreCase(item.optString("title").trim())) {
|
| | | shop.setScoreGoods(new BigDecimal(item.optString("score").trim()));
|
| | | shop.setScoreGoodsD(new BigDecimal(item.optString("level").trim()));
|
| | | } else if ("卖家服务".equalsIgnoreCase(item.optString("title").trim())) {
|
| | | shop.setScoreSeller(new BigDecimal(item.optString("score").trim()));
|
| | | shop.setScoreSellerD(new BigDecimal(item.optString("level").trim()));
|
| | | } else if ("物流服务".equalsIgnoreCase(item.optString("title").trim())) {
|
| | | shop.setScoreLogistics(new BigDecimal(item.optString("score").trim()));
|
| | | shop.setScoreLogisticsD(new BigDecimal(item.optString("level").trim()));
|
| | | }
|
| | | }
|
| | |
|
| | | shop.setSellerNick(sellerJson.optString("sellerNick"));
|
| | | shop.setShopIcon("https:" + sellerJson.optString("shopIcon"));
|
| | | shop.setShopId(sellerJson.optLong("shopId"));
|
| | | shop.setShopName(sellerJson.optString("shopName"));
|
| | | if ("B".equalsIgnoreCase(sellerJson.optString("sellerType")))
|
| | | shop.setUserType(1);
|
| | | else
|
| | | shop.setUserType(0);
|
| | |
|
| | | shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId()));
|
| | | } catch (Exception e) {
|
| | | // if (1 > 0)
|
| | | // return null;
|
| | | try {
|
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.getSimpleGoodsInfo(auctionId);
|
| | | shop.setId(goods.getSellerId());
|
| | | shop.setShopName(goods.getShopTitle());
|
| | | shop.setUserType(goods.getUserType());
|
| | | } catch (Exception e1) {
|
| | | shop.setId(1L);
|
| | | shop.setShopName("");
|
| | | shop.setUserType(0);
|
| | | }
|
| | |
|
| | | shop.setGoodRatePercentage(new BigDecimal(100));
|
| | | shop.setScoreGoods(new BigDecimal("4.9"));
|
| | | shop.setScoreGoodsD(new BigDecimal("0"));
|
| | | shop.setScoreSeller(new BigDecimal("4.9"));
|
| | | shop.setScoreSellerD(new BigDecimal("0"));
|
| | | shop.setScoreLogistics(new BigDecimal("4.9"));
|
| | | shop.setScoreLogisticsD(new BigDecimal("0"));
|
| | | shop.setSellerNick("");
|
| | | shop.setShopIcon("https:");
|
| | | shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId()));
|
| | | }
|
| | |
|
| | | return shop;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 根据卖家id获取店铺链接
|
| | | * |
| | | * @param sellerId
|
| | | * @return
|
| | | */
|
| | | public static String getShopLink(Long sellerId) {
|
| | | return "http://store.taobao.com/shop/view_shop.htm?user_number_id=" + sellerId;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 是否可以加入淘礼金的预选商品库
|
| | | * |
| | | * @param v2
|
| | | * @return
|
| | | */
|
| | | public static boolean canAddToTLJBuyGoods(TaoBaoGoodsBrief goods) {
|
| | | BigDecimal tljMoney = getShareGoodsHongBaoInfo(goods, TaoBaoConstant.OWN_BUY_WITHOUT_FANLI_RATE);
|
| | | // 不能小于1块
|
| | | if (tljMoney.compareTo(new BigDecimal(1)) < 0 || tljMoney.compareTo(new BigDecimal(10)) > 0)
|
| | | return false;
|
| | |
|
| | | // 券后价不能大于150
|
| | | if (getAfterUseCouplePrice(goods).compareTo(new BigDecimal(150)) > 0)
|
| | | return false;
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 查询天猫商品图片、标题
|
| | | * |
| | | * @param auctionId
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoGoodsBrief getTmallGoodsInfo(String auctionId) {
|
| | | TaoBaoGoodsBrief taoBaoGoodsBrief = null;
|
| | | try {
|
| | | Connection connect = Jsoup.connect(String.format(TM_PHONE_URL, auctionId));
|
| | | Document document = connect.get();
|
| | | Elements elements = document.getElementsByTag("script");
|
| | | if (elements.size() >= 0) {
|
| | | for (int i = 0; i < elements.size(); i++) {
|
| | | String content = elements.get(i).toString();
|
| | | if (content.contains("var _DATA_Mdskip")) {
|
| | | content = content.replace("<script>", "");
|
| | | content = content.replace("</script>", "");
|
| | |
|
| | | if (content.contains("videoDetail")) {
|
| | | content += ";function getData(){ var json={title:_DATA_Mdskip.item.title,pictUrl:_DATA_Mdskip.item.videoDetail.videoThumbnailURL}; return JSON.stringify(json);}";
|
| | | } else {
|
| | | content += ";function getData(){ var json={title:_DATA_Mdskip.item.title,pictUrl:_DATA_Mdskip.item.videos[0].videoThumbnailURL}; return JSON.stringify(json);}";
|
| | | }
|
| | |
|
| | | ScriptEngineManager manager = new ScriptEngineManager();
|
| | | ScriptEngine engine = manager.getEngineByName("javascript");
|
| | | engine.eval(content);
|
| | |
|
| | | if (engine instanceof Invocable) {
|
| | | Invocable in = (Invocable) engine;
|
| | | JSONObject json = JSONObject.fromObject(in.invokeFunction("getData"));
|
| | | Object title = json.get("title");
|
| | | Object pictUrl = json.get("pictUrl");
|
| | | taoBaoGoodsBrief = new TaoBaoGoodsBrief();
|
| | | taoBaoGoodsBrief.setTitle(title.toString());
|
| | | taoBaoGoodsBrief.setPictUrl(pictUrl.toString());
|
| | | }
|
| | |
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return taoBaoGoodsBrief;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 抖音返利local 获取真实淘宝链接
|
| | | * |
| | | * @param url
|
| | | * https://s.click.taobao.com/t?e=m%3D2%26s%
|
| | | * 3DT9DFpHQCT7Rw4vFB6t2Z2ueEDrYVVa64XoO8tOebS+dRAdhuF14FMR8
|
| | | * @return
|
| | | */
|
| | | public static String getRealUrl(String url) {
|
| | | if (StringUtil.isNullOrEmpty(url))
|
| | | return null;
|
| | |
|
| | | try {
|
| | | HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager());
|
| | | client.getHttpConnectionManager().getParams().setConnectionTimeout(10000);
|
| | | client.getParams().setParameter(HttpMethodParams.USER_AGENT,
|
| | | "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)"); // 让服务器认为是IE
|
| | | GetMethod get = new GetMethod(url);
|
| | | get.setFollowRedirects(false); // 禁止自动重定向
|
| | | int iGetResultCode = client.executeMethod(get);
|
| | | String location = get.getResponseHeader("location").getValue(); // 打印地址
|
| | | GetMethod get2 = new GetMethod(URLDecoder.decode(location.split("tu=")[1]));
|
| | | get2.addRequestHeader("Referer", location);
|
| | | get2.setFollowRedirects(false); // 禁止自动重定向
|
| | | int iGetResultCode2 = client.executeMethod(get2);
|
| | | return get2.getResponseHeader("location").getValue(); // 真实地址
|
| | | } catch (Exception ex) {
|
| | | ex.printStackTrace();
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 淘口令过滤
|
| | | * |
| | | * @param token
|
| | | * @return
|
| | | */
|
| | | public static String filterTaoToken(String token) {
|
| | | if (StringUtil.isNullOrEmpty(token))
|
| | | return token;
|
| | | if (token.contains("¥") || token.contains("€")) {
|
| | | String newToken = "";
|
| | | for (int i = 0; i < token.length(); i++) {
|
| | | if (token.charAt(i) == '¥' || token.charAt(i) == '€') {
|
| | | if (!newToken.contains("("))
|
| | | newToken += "(";
|
| | | else
|
| | | newToken += ")";
|
| | | } else
|
| | | newToken += token.charAt(i) + "";
|
| | | }
|
| | | return newToken;
|
| | | }
|
| | | 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))
|
| | | return group;
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | public static boolean isSpecialGoods(Integer materialLibType) {
|
| | | if (materialLibType != null && materialLibType == 1)
|
| | | return true;
|
| | | else
|
| | | return false;
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.util.taobao; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLDecoder; |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | import javax.script.Invocable; |
| | | import javax.script.ScriptEngine; |
| | | import javax.script.ScriptEngineManager; |
| | | import javax.xml.parsers.DocumentBuilder; |
| | | import javax.xml.parsers.DocumentBuilderFactory; |
| | | |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.util.*; |
| | | import org.apache.commons.httpclient.HttpClient; |
| | | import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; |
| | | import org.apache.commons.httpclient.methods.GetMethod; |
| | | import org.apache.commons.httpclient.params.HttpMethodParams; |
| | | import org.jsoup.Connection; |
| | | import org.jsoup.Jsoup; |
| | | import org.jsoup.nodes.Document; |
| | | import org.jsoup.nodes.Element; |
| | | import org.jsoup.select.Elements; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.stereotype.Component; |
| | | import org.w3c.dom.NamedNodeMap; |
| | | import org.w3c.dom.NodeList; |
| | | import org.yeshi.utils.BigDecimalUtil; |
| | | 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.vip.UserLevelEnum; |
| | | import com.yeshi.fanli.entity.common.ImageInfo; |
| | | import com.yeshi.fanli.entity.goods.CommonGoods; |
| | | import com.yeshi.fanli.entity.taobao.SearchFilter; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoCoupon; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBriefExtra; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoHead; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoHongBaoInfo; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoLink; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoProvince; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoQuanInfo; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchNav; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult; |
| | | import com.yeshi.common.entity.taobao.TaoBaoShop; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig; |
| | | import com.yeshi.goods.facade.entity.taobao.dataoke.DaTaoKeDetailV2; |
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException; |
| | | import com.yeshi.fanli.log.LogHelper; |
| | | import com.yeshi.fanli.service.inter.goods.TaoBaoLinkService; |
| | | import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; |
| | | import com.yeshi.common.entity.PageEntity; |
| | | import org.yeshi.utils.MoneyBigDecimalUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import com.yeshi.common.vo.ClientTextStyleVO; |
| | | |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | |
| | | @Component |
| | | public class TaoBaoUtil { |
| | | |
| | | @Autowired |
| | | private HongBaoManageService manageService; |
| | | |
| | | @Resource |
| | | private TaoBaoLinkService taoBaoLinkService; |
| | | |
| | | private static TaoBaoUtil taoBaoUtil; |
| | | |
| | | @PostConstruct |
| | | public void init() { |
| | | taoBaoUtil = this; |
| | | taoBaoUtil.manageService = this.manageService; |
| | | taoBaoUtil.taoBaoLinkService = this.taoBaoLinkService; |
| | | } |
| | | |
| | | public final static int SORT_PRICE_HIGH_TO_LOW = 3;// 价格从高到低 |
| | | public final static int SORT_PRICE_LOW_TO_HIGH = 4;// 价格从低到高 |
| | | |
| | | public static final int SORT_TKRATE_LOW_TO_HIGH = 1;// 淘客佣金比率低到高 |
| | | public static final int SORT_TKRATE_HIGH_TO_LOW = 2;// 淘客佣金比率高到低 |
| | | |
| | | public static final int SORT_TOTAL_COMMI_LOW_TO_HIGH = 5;// 总支出佣金低到高 |
| | | public static final int SORT_TOTAL_COMMI_HIGH_TO_LOW = 6;// 总支出佣金高到低 |
| | | |
| | | public static final int SORT_TOTAL_SALES_LOW_TO_HIGH = 10;// 累计推广量低到高 |
| | | public static final int SORT_TOTAL_SALES_HIGH_TO_LOW = 11;// 累计推广量高到低 |
| | | |
| | | public static final int SORT_SALE_COMMISSION = 7;// 月支出佣金从高到低 |
| | | |
| | | public final static int SORT_SALE_LOW_TO_HIGH = 8;// 销量从低到高 |
| | | |
| | | public final static int SORT_SALE_HIGH_TO_LOW = 9;// 销量从高到低 |
| | | public final static int SORT_DEFAULT = 0;// 销量从高到低 |
| | | |
| | | public final static int SORT_FILTER_FROM_ALL = 0;// 淘宝天猫 |
| | | public final static int SORT_FILTER_FROM_TMALL = 1;// 天猫 |
| | | |
| | | private final static int PAGESIZE = 20; |
| | | |
| | | public final static String SEARCH_URL = "http://pub.alimama.com/items/search.json"; |
| | | private static final String NZJH_URL = "http://pub.alimama.com/items/channel/nzjh.json"; |
| | | private static final String MUYING_URL = "http://pub.alimama.com/items/channel/muying.json"; |
| | | private static final String QQHD_URL = "http://pub.alimama.com/items/channel/qqhd.json"; |
| | | private static final String IFS_URL = "http://pub.alimama.com/items/channel/ifs.json"; |
| | | private static final String QBB_URL = "http://pub.alimama.com/items/channel/qbb.json"; |
| | | private static final String HCH_URL = "http://pub.alimama.com/items/channel/hch.json"; |
| | | private static final String CDJ_URL = "http://pub.alimama.com/items/channel/cdj.json"; |
| | | private static final String JYJ_URL = "http://pub.alimama.com/items/channel/jyj.json"; |
| | | private static final String KDC_URL = "http://pub.alimama.com/items/channel/kdc.json"; |
| | | private static final String DIY_URL = "http://pub.alimama.com/items/channel/diy.json"; |
| | | private static final String K9_URL = "http://pub.alimama.com/items/channel/9k9.json"; |
| | | private static final String K20_URL = "http://pub.alimama.com/items/channel/20k.json"; |
| | | private static final String TEHUI_URL = "http://pub.alimama.com/items/channel/tehui.json"; |
| | | |
| | | private static final String TB_ITEM_URL = "http://gw.api.taobao.com/router/rest"; |
| | | |
| | | public static final String TB_URL = "http://item.taobao.com/item.htm?id=%s"; |
| | | public static final String TM_PHONE_URL = "https://detail.m.tmall.com/item.htm?id=%s"; |
| | | public static final String TB_H5_URL = "http://h5.m.taobao.com/awp/core/detail.htm?id=%s"; |
| | | |
| | | private static final Map<Integer, String> channelMap = new HashMap<Integer, String>(); |
| | | private static final Map<Integer, String> urlMap = new HashMap<Integer, String>(); |
| | | |
| | | private static List<TaoBaoProvince> taoBaoProvinceList = null; |
| | | |
| | | static { |
| | | channelMap.put(0, "");// 普通 |
| | | channelMap.put(1, "nzjh");// 女装尖货 |
| | | channelMap.put(2, "muying");// 母婴热推 |
| | | channelMap.put(3, "qqhd");// 高佣活动 |
| | | channelMap.put(4, "ifs");// ifashion |
| | | channelMap.put(5, "qbb");// 亲宝贝 |
| | | channelMap.put(6, "hch");// 淘宝汇吃 |
| | | channelMap.put(7, "cdj");// 潮电街 |
| | | channelMap.put(8, "jyj");// 极有家 |
| | | channelMap.put(9, "kdc");// 酷动城 |
| | | channelMap.put(10, "diy");// 淘宝DIY |
| | | channelMap.put(11, "9k9");// 超值9块9 |
| | | channelMap.put(12, "20k");// 20元封顶 |
| | | channelMap.put(13, "tehui");// 特价好货 |
| | | |
| | | urlMap.put(0, SEARCH_URL); |
| | | urlMap.put(1, NZJH_URL); |
| | | urlMap.put(2, MUYING_URL); |
| | | urlMap.put(3, QQHD_URL); |
| | | urlMap.put(4, IFS_URL); |
| | | urlMap.put(5, QBB_URL); |
| | | urlMap.put(6, HCH_URL); |
| | | urlMap.put(7, CDJ_URL); |
| | | urlMap.put(8, JYJ_URL); |
| | | urlMap.put(9, KDC_URL); |
| | | urlMap.put(10, DIY_URL); |
| | | urlMap.put(11, K9_URL); |
| | | urlMap.put(12, K20_URL); |
| | | urlMap.put(13, TEHUI_URL); |
| | | } |
| | | |
| | | public static TaoBaoSearchResult search(SearchFilter filter, boolean proxy, String specialId, String relationId) { |
| | | if (filter.getKey().startsWith("http://") || filter.getKey().startsWith("https://")) { |
| | | String[] sts = filter.getKey().split("\\?")[1].split("&"); |
| | | for (String st : sts) { |
| | | if (st.contains("id=")) { |
| | | String id = st.replace("id=", "").trim(); |
| | | TaoBaoGoodsBrief tb = null; |
| | | try { |
| | | tb = TaoKeApiUtil.searchGoodsDetail(id); |
| | | } catch (TaobaoGoodsDownException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | List<TaoBaoGoodsBrief> goodsList = new ArrayList<>(); |
| | | goodsList.add(tb); |
| | | TaoBaoSearchResult result = new TaoBaoSearchResult(); |
| | | result.setTaoBaoGoodsBriefs(goodsList); |
| | | result.setNavList(new ArrayList<>()); |
| | | TaoBaoHead taoBaoHead = new TaoBaoHead(); |
| | | taoBaoHead.setDocsfound(1); |
| | | result.setTaoBaoHead(taoBaoHead); |
| | | return result; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | List<Long> cateList = null; |
| | | if (!StringUtil.isNullOrEmpty(filter.getCateIds())) { |
| | | cateList = new ArrayList<>(); |
| | | for (String c : filter.getCateIds().split(",")) |
| | | cateList.add(Long.parseLong(c)); |
| | | } |
| | | return TaoKeApiUtil.searchWuLiaoNew(filter, specialId, relationId); |
| | | } |
| | | |
| | | /** |
| | | * 淘宝联盟网页搜索商品 |
| | | * |
| | | * @param filter |
| | | * @param config -联盟配置 |
| | | * @return |
| | | */ |
| | | public static TaoBaoSearchResult searchFromAlimamaWeb(SearchFilter filter, TaoBaoUnionConfig config) { |
| | | Map<String, String> params = new HashMap<String, String>(); |
| | | params.put("q", filter.getKey()); |
| | | params.put("_t", System.currentTimeMillis() + ""); |
| | | params.put("toPage", filter.getPage() + ""); |
| | | params.put("auctionTag", ""); |
| | | params.put("perPageSize", filter.getPageSize() == 0 ? PAGESIZE + "" : filter.getPageSize() + ""); |
| | | params.put("shopTag", filter.getShopTag() + ""); |
| | | params.put("t", System.currentTimeMillis() + ""); |
| | | params.put("_tb_token_", "test"); |
| | | params.put("yxjh", "-1"); |
| | | params.put("queryType", "2"); |
| | | String shopTag = filter.getShopTag(); |
| | | if (shopTag != null) { |
| | | String[] split = shopTag.split(","); |
| | | for (String tag : split) { |
| | | params.put(tag, "1"); |
| | | } |
| | | } |
| | | |
| | | if (filter.isTmall()) { |
| | | params.put("userType", "1"); |
| | | } |
| | | |
| | | if (filter.isBaoYou()) { |
| | | params.put("freeShipment", "1"); |
| | | } |
| | | |
| | | if (filter.getStartPrice() != null) { |
| | | params.put("startPrice", filter.getStartPrice() + ""); |
| | | } |
| | | if (filter.getEndPrice() != null) { |
| | | params.put("endPrice", filter.getEndPrice() + ""); |
| | | } |
| | | if (!StringUtil.isNullOrEmpty(filter.getCateIds())) |
| | | params.put("catIds", filter.getCateIds()); |
| | | |
| | | if (filter.getParams() != null && filter.getParams().size() > 0) { |
| | | Set<String> set = filter.getParams(); |
| | | StringBuffer sb = new StringBuffer(); |
| | | int i = 0; |
| | | for (String ids : set) { |
| | | if (i == 0) { |
| | | sb.append(ids); |
| | | } else { |
| | | sb.append(";" + ids); |
| | | } |
| | | i++; |
| | | } |
| | | params.put("pidvid", sb.toString()); |
| | | } |
| | | if (filter.getSort() > 0) { |
| | | params.put("sortType", filter.getSort() + ""); |
| | | // params.put("queryType", "0"); |
| | | } |
| | | |
| | | Map<String, String> headers = new HashMap<>(); |
| | | // headers.put("cookie", |
| | | // TaoBaoOrderUtil.getTaoBaoCookie(config.getAccount())); |
| | | |
| | | headers.put("referer", "https://pub.alimama.com/promo/search/index.htm"); |
| | | |
| | | headers.put("User-Agent", |
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"); |
| | | |
| | | String result = TaoBaoHttpUtil.get(SEARCH_URL, params, headers, true); |
| | | if (result == null || "".equals(result)) { |
| | | return null; |
| | | } |
| | | result = result.replace("</span>", "").replace("<span class=H>", ""); |
| | | if (result.contains("<!DOCTYPE html>")) { |
| | | TaoBaoSearchResult presult = new TaoBaoSearchResult(); |
| | | presult.setNavList(new ArrayList<TaoBaoSearchNav>()); |
| | | presult.setTaoBaoGoodsBriefs(new ArrayList<TaoBaoGoodsBrief>()); |
| | | TaoBaoHead taoBaoHead = new TaoBaoHead(); |
| | | taoBaoHead.setDocsfound(0); |
| | | presult.setTaoBaoHead(taoBaoHead); |
| | | return presult; |
| | | } |
| | | TaoBaoSearchResult presult = parseTaoBao(result); |
| | | presult.setKey(filter.getKey()); |
| | | return presult; |
| | | } |
| | | |
| | | /** |
| | | * 淘宝联盟网页搜索商品 |
| | | * |
| | | * @param filter |
| | | * @param config -联盟配置 |
| | | * @return |
| | | */ |
| | | public static TaoBaoSearchResult searchAlimamaWeb(SearchFilter filter, TaoBaoUnionConfig config, Integer typeNum) { |
| | | |
| | | Map<String, String> params = new HashMap<String, String>(); |
| | | |
| | | if (typeNum != null && !typeNum.equals(0)) { |
| | | if (channelMap.get(typeNum) != null) { |
| | | params.put("channel", channelMap.get(typeNum)); |
| | | } |
| | | } |
| | | |
| | | params.put("toPage", filter.getPage() + ""); |
| | | params.put("perPageSize", filter.getPageSize() == 0 ? PAGESIZE + "" : filter.getPageSize() + ""); |
| | | |
| | | if (typeNum != null && typeNum == 3) { |
| | | // 查询类目 |
| | | String catIds = filter.getCateIds(); |
| | | |
| | | if (!StringUtil.isNullOrEmpty(catIds)) { |
| | | // 高佣时根据类目id查询 |
| | | params.put("catIds", catIds); // 类目 |
| | | params.put("level", "1");// 默认一级 |
| | | } else { |
| | | // 查询条件 |
| | | String key = filter.getKey(); |
| | | if (!StringUtil.isNullOrEmpty(key)) { |
| | | params.put("q", filter.getKey()); |
| | | } |
| | | } |
| | | |
| | | } else { |
| | | // 查询条件 |
| | | String key = filter.getKey(); |
| | | if (!StringUtil.isNullOrEmpty(key)) { |
| | | params.put("q", filter.getKey()); |
| | | } |
| | | } |
| | | |
| | | // 排序字段 3 价格高到低 4 价格低到高 |
| | | // 9 销量高到低 1 收入比率高到低 5 月推广量高到低 7月支出佣金高到低 |
| | | // 13 活动开始时间由近到远 11 活动剩余时间长到短 12 活动剩余时间短到长 |
| | | |
| | | int sort = filter.getSort(); |
| | | if (sort > 0) { |
| | | params.put("sortType", sort + ""); |
| | | } |
| | | |
| | | // 是否天猫 |
| | | if (filter.isTmall()) { |
| | | params.put("userType", "1"); |
| | | } |
| | | |
| | | // 使用含优惠券 |
| | | int quan = filter.getQuan(); |
| | | if (quan == 1) { |
| | | params.put("shopTag", "dpyhq"); |
| | | params.put("dpyhq", "1"); |
| | | } /* |
| | | * else { params.put("shopTag", ""); } |
| | | */ |
| | | |
| | | // 销量 |
| | | String startBiz30day = filter.getStartBiz30day(); |
| | | if (!StringUtil.isNullOrEmpty(startBiz30day)) { |
| | | params.put("startBiz30day", startBiz30day); |
| | | } |
| | | |
| | | // 佣金比例小值 |
| | | int startTkRate = filter.getStartTkRate(); |
| | | if (startTkRate > 0) { |
| | | params.put("startTkRate", startTkRate / 100 + ""); |
| | | } |
| | | |
| | | // 佣金比例大值 |
| | | int endTkRate = filter.getEndTkRate(); |
| | | if (endTkRate > 0) { |
| | | params.put("endTkRate", endTkRate + ""); |
| | | } |
| | | |
| | | // 起始价格 |
| | | if (filter.getStartPrice() != null) { |
| | | |
| | | params.put("startPrice", filter.getStartPrice() + ""); |
| | | } |
| | | |
| | | // 截止价格 |
| | | if (filter.getEndPrice() != null) { |
| | | params.put("endPrice", filter.getEndPrice() + ""); |
| | | } |
| | | |
| | | if (filter.getParams() != null && filter.getParams().size() > 0) { |
| | | Set<String> set = filter.getParams(); |
| | | StringBuffer sb = new StringBuffer(); |
| | | int i = 0; |
| | | for (String ids : set) { |
| | | if (i == 0) { |
| | | sb.append(ids); |
| | | } else { |
| | | sb.append(";" + ids); |
| | | } |
| | | i++; |
| | | } |
| | | params.put("pidvid", sb.toString()); |
| | | } |
| | | |
| | | params.put("t", System.currentTimeMillis() + ""); |
| | | params.put("_tb_token_", "e430bae750a11"); |
| | | |
| | | Map<String, String> headers = new HashMap<>(); |
| | | |
| | | headers.put("referer", "https://pub.alimama.com/promo/search/index.htm"); |
| | | |
| | | headers.put("User-Agent", |
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"); |
| | | |
| | | String cookie = TaoBaoOrderUtil.getTaoBaoCookie(config.getAccount()); |
| | | headers.put("Cookie", cookie); |
| | | |
| | | String url = SEARCH_URL; |
| | | |
| | | if (typeNum != null && !typeNum.equals(0)) { |
| | | url = urlMap.get(typeNum); |
| | | } |
| | | |
| | | String result = TaoBaoHttpUtil.get(url, params, headers, true); |
| | | if (result == null || "".equals(result)) { |
| | | return null; |
| | | } |
| | | |
| | | result = result.replace("</span>", "").replace("<span class=H>", ""); |
| | | if (result.contains("<!DOCTYPE html>")) { |
| | | TaoBaoSearchResult presult = new TaoBaoSearchResult(); |
| | | |
| | | presult.setNavList(new ArrayList<TaoBaoSearchNav>()); |
| | | presult.setTaoBaoGoodsBriefs(new ArrayList<TaoBaoGoodsBrief>()); |
| | | |
| | | TaoBaoHead taoBaoHead = new TaoBaoHead(); |
| | | taoBaoHead.setDocsfound(0); |
| | | presult.setTaoBaoHead(taoBaoHead); |
| | | |
| | | return presult; |
| | | } |
| | | TaoBaoSearchResult presult = parseTaoBao(result); |
| | | presult.setKey(filter.getKey()); |
| | | |
| | | return presult; |
| | | } |
| | | |
| | | public static TaoBaoSearchResult search(SearchFilter filter, String specialId, String relationId) { |
| | | return search(filter, false, specialId, relationId); |
| | | } |
| | | |
| | | public static TaoBaoSearchResult search2(SearchFilter filter, TaoBaoUnionConfig config) { |
| | | |
| | | if (filter.getKey().startsWith("http://") || filter.getKey().startsWith("https://")) { |
| | | String[] sts = filter.getKey().split("\\?")[1].split("&"); |
| | | for (String st : sts) { |
| | | if (st.contains("id=")) { |
| | | String id = st.replace("id=", "").trim(); |
| | | TaoBaoGoodsBrief tb = null; |
| | | try { |
| | | tb = TaoKeApiUtil.searchGoodsDetail(id); |
| | | } catch (TaobaoGoodsDownException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | List<TaoBaoGoodsBrief> goodsList = new ArrayList<>(); |
| | | goodsList.add(tb); |
| | | TaoBaoSearchResult result = new TaoBaoSearchResult(); |
| | | result.setTaoBaoGoodsBriefs(goodsList); |
| | | result.setNavList(new ArrayList<>()); |
| | | TaoBaoHead taoBaoHead = new TaoBaoHead(); |
| | | taoBaoHead.setDocsfound(1); |
| | | result.setTaoBaoHead(taoBaoHead); |
| | | result.setPageEntity(new PageEntity()); |
| | | return result; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | List<Long> cateList = null; |
| | | if (!StringUtil.isNullOrEmpty(filter.getCateIds())) { |
| | | cateList = new ArrayList<>(); |
| | | for (String c : filter.getCateIds().split(",")) |
| | | cateList.add(Long.parseLong(c)); |
| | | } |
| | | |
| | | if (1 > 0) |
| | | return TaoKeApiUtil.searchWuLiaoNew(filter, null, null); |
| | | |
| | | Map<String, String> params = new HashMap<String, String>(); |
| | | String key = filter.getKey(); |
| | | if (key != null) { |
| | | params.put("q", filter.getKey()); |
| | | } |
| | | params.put("_t", System.currentTimeMillis() + ""); |
| | | params.put("toPage", filter.getPage() + ""); |
| | | params.put("perPageSize", PAGESIZE + ""); |
| | | params.put("auctionTag", ""); |
| | | params.put("shopTag", ""); |
| | | params.put("queryType", "2"); |
| | | params.put("t", System.currentTimeMillis() + ""); |
| | | params.put("_tb_token_", "owxj2i1mfTXq"); |
| | | int type = filter.getType(); |
| | | params.put("channel", channelMap.get(type)); |
| | | if (filter.getSort() > 0) { |
| | | params.put("sortType", filter.getSort() + ""); |
| | | // params.put("queryType", "0"); |
| | | } |
| | | String result = TaoBaoHttpUtil.tbGet(urlMap.get(type), params, config.getAccount()); |
| | | result = result.replace("</span>", "").replace("<span class=H>", ""); |
| | | TaoBaoSearchResult presult = parseTaoBao(result); |
| | | presult.setKey(filter.getKey()); |
| | | return presult; |
| | | } |
| | | |
| | | /** |
| | | * 9块9 19块9的列表 |
| | | * |
| | | * @param filter |
| | | * @return |
| | | */ |
| | | public static TaoBaoSearchResult search3(SearchFilter filter, TaoBaoUnionConfig config) { |
| | | Map<String, String> params = new HashMap<String, String>(); |
| | | String key = filter.getKey(); |
| | | if (key != null) { |
| | | params.put("q", filter.getKey()); |
| | | } |
| | | params.put("_t", System.currentTimeMillis() + ""); |
| | | params.put("toPage", filter.getPage() + ""); |
| | | params.put("perPageSize", PAGESIZE + ""); |
| | | params.put("auctionTag", ""); |
| | | params.put("shopTag", ""); |
| | | params.put("queryType", "2"); |
| | | params.put("t", System.currentTimeMillis() + ""); |
| | | params.put("_tb_token_", "owxj2i1mfTXq"); |
| | | int type = filter.getType(); |
| | | params.put("channel", channelMap.get(type)); |
| | | if (filter.getSort() > 0) { |
| | | params.put("sortType", filter.getSort() + ""); |
| | | // params.put("queryType", "0"); |
| | | } |
| | | String result = TaoBaoHttpUtil.tbGet(urlMap.get(type), params, config.getAccount()); |
| | | result = result.replace("</span>", "").replace("<span class=H>", ""); |
| | | TaoBaoSearchResult presult = parseTaoBao(result); |
| | | presult.setKey(filter.getKey()); |
| | | return presult; |
| | | } |
| | | |
| | | public static TaoBaoSearchResult parseTaoBao(String result) { |
| | | TaoBaoSearchResult resu = new TaoBaoSearchResult(); |
| | | List<TaoBaoGoodsBrief> list = new ArrayList<TaoBaoGoodsBrief>(); |
| | | JSONObject root = null; |
| | | try { |
| | | root = JSONObject.fromObject(result); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | resu.setTaoBaoGoodsBriefs(list); |
| | | return resu; |
| | | } |
| | | Gson gson = new GsonBuilder().create(); |
| | | if (root.optBoolean("ok")) { |
| | | JSONArray array = root.optJSONObject("data").optJSONArray("pageList"); |
| | | if (array != null) { |
| | | for (int i = 0; i < array.size(); i++) { |
| | | list.add(gson.fromJson(array.optJSONObject(i).toString(), TaoBaoGoodsBrief.class)); |
| | | } |
| | | } |
| | | JSONObject head = root.optJSONObject("data").optJSONObject("head"); |
| | | Type headType = new TypeToken<TaoBaoHead>() { |
| | | }.getType(); |
| | | TaoBaoHead taoBaoHead = gson.fromJson(head.toString(), headType); |
| | | resu.setTaoBaoHead(taoBaoHead); |
| | | |
| | | JSONArray navArray = root.optJSONObject("data").optJSONArray("navigator"); |
| | | Type type = new TypeToken<ArrayList<TaoBaoSearchNav>>() { |
| | | }.getType(); |
| | | if (navArray != null) { |
| | | List<TaoBaoSearchNav> navList = gson.fromJson(navArray.toString(), type); |
| | | for (TaoBaoSearchNav taoBaoSearchNav : navList) { |
| | | String tbtype = taoBaoSearchNav.getType(); |
| | | if (!"category".equalsIgnoreCase(tbtype)) { |
| | | taoBaoSearchNav.setSelector(1); |
| | | } |
| | | } |
| | | resu.setNavList(navList); |
| | | } |
| | | JSONObject paginatorObject = root.optJSONObject("data").optJSONObject("paginator"); |
| | | if (paginatorObject != null) { |
| | | int count = (Integer) paginatorObject.get("items"); |
| | | int totalPage = (Integer) paginatorObject.get("pages"); |
| | | PageEntity pe = new PageEntity(); |
| | | pe.setTotalCount(count); |
| | | pe.setPageSize(PAGESIZE); |
| | | pe.setTotalPage(totalPage); |
| | | resu.setPageEntity(pe); |
| | | } |
| | | } |
| | | for (TaoBaoGoodsBrief taoBaoGoodsBrief : list) { |
| | | String pictUrl = taoBaoGoodsBrief.getPictUrl(); |
| | | if (!pictUrl.contains("http:") && !pictUrl.contains("https:")) { |
| | | taoBaoGoodsBrief.setPictUrl("http:" + pictUrl); |
| | | } |
| | | } |
| | | resu.setTaoBaoGoodsBriefs(list); |
| | | |
| | | PageEntity pageEntity = resu.getPageEntity(); |
| | | if (pageEntity == null) { |
| | | PageEntity entity = new PageEntity(); |
| | | resu.setPageEntity(entity); |
| | | } |
| | | |
| | | return resu; |
| | | } |
| | | |
| | | public static List<TaoBaoSearchNav> getBaseNav() { |
| | | List<TaoBaoSearchNav> list = new ArrayList<TaoBaoSearchNav>(); |
| | | |
| | | // 设置宝贝类型(淘宝天猫/天猫) |
| | | // TaoBaoSearchNav shopType = new TaoBaoSearchNav(); |
| | | // shopType.setLevel(1); |
| | | // shopType.setId(2); |
| | | // shopType.setName("宝贝类型"); |
| | | // shopType.setType("shoptype"); |
| | | // shopType.setFlag("shoptype"); |
| | | // shopType.setSelector(0); |
| | | // List<TaoBaoSearchNav> shopTypeChildList = new |
| | | // ArrayList<TaoBaoSearchNav>(); |
| | | // shopTypeChildList.add(new TaoBaoSearchNav(0, "all", 21, 2, "淘宝天猫", |
| | | // "")); |
| | | // shopTypeChildList.add(new TaoBaoSearchNav(0, "tmall", 22, 2, "天猫", |
| | | // "")); |
| | | // shopType.setSubIds(shopTypeChildList); |
| | | // list.add(shopType); |
| | | |
| | | // 是否有券 |
| | | // TaoBaoSearchNav quanType = new TaoBaoSearchNav(); |
| | | // quanType.setLevel(1); |
| | | // quanType.setId(3); |
| | | // quanType.setName("是否有券"); |
| | | // quanType.setType("quantype"); |
| | | // quanType.setFlag("quantype"); |
| | | // quanType.setSelector(0); |
| | | // List<TaoBaoSearchNav> quanTypeChildList = new |
| | | // ArrayList<TaoBaoSearchNav>(); |
| | | // quanTypeChildList.add(new TaoBaoSearchNav(0, "quan", 31, 2, "有券", |
| | | // "")); |
| | | // quanTypeChildList |
| | | // .add(new TaoBaoSearchNav(0, "noquan", 32, 2, "无券", "")); |
| | | // quanType.setSubIds(quanTypeChildList); |
| | | // list.add(quanType); |
| | | |
| | | // 是否有红包 |
| | | // TaoBaoSearchNav hongbaoType = new TaoBaoSearchNav(); |
| | | // hongbaoType.setLevel(1); |
| | | // hongbaoType.setId(4); |
| | | // hongbaoType.setName("是否有红包"); |
| | | // hongbaoType.setType("hongbaotype"); |
| | | // hongbaoType.setFlag("hongbaotype"); |
| | | // hongbaoType.setSelector(0); |
| | | // List<TaoBaoSearchNav> hongbaoChildList = new |
| | | // ArrayList<TaoBaoSearchNav>(); |
| | | // hongbaoChildList |
| | | // .add(new TaoBaoSearchNav(0, "hongbao", 41, 2, "有红包", "")); |
| | | // hongbaoChildList.add(new TaoBaoSearchNav(0, "nohongbao", 42, 2, |
| | | // "无红包", |
| | | // "")); |
| | | // hongbaoType.setSubIds(hongbaoChildList); |
| | | // list.add(hongbaoType); |
| | | |
| | | // 设置发货地 |
| | | // TaoBaoSearchNav address = new TaoBaoSearchNav(); |
| | | // address.setLevel(1); |
| | | // address.setId(1); |
| | | // address.setName("店铺所在地"); |
| | | // address.setType("loc"); |
| | | // address.setFlag("loc"); |
| | | // List<TaoBaoSearchNav> addressChildList = new |
| | | // ArrayList<TaoBaoSearchNav>(); |
| | | // |
| | | // list.add(address); |
| | | |
| | | return list; |
| | | } |
| | | |
| | | public static TaoBaoGoodsBriefExtra getTaoBaoGoodsBriefExtra(TaoBaoGoodsBrief tb, String proportion, String pid) { |
| | | TaoBaoGoodsBriefExtra tg = new TaoBaoGoodsBriefExtra(); |
| | | tg.setId(tb.getId()); |
| | | tg.setAuctionId(tb.getAuctionId()); |
| | | tg.setBiz30day(tb.getBiz30day()); |
| | | tg.setSalesCount(TaoBaoUtil.getSaleCount(tb.getBiz30day())); |
| | | tg.setTitle(tb.getTitle()); |
| | | if (!StringUtil.isNullOrEmpty(tb.getPictUrlWhite())) |
| | | tg.setPictUrl(TbImgUtil.getTBSize320Img(tb.getPictUrlWhite())); |
| | | else |
| | | tg.setPictUrl(TbImgUtil.getTBSize320Img(tb.getPictUrl())); |
| | | tg.setZkPrice(tb.getZkPrice()); |
| | | tg.setAuctionUrl(tb.getAuctionUrl()); |
| | | tg.setReservePrice(tb.getReservePrice()); |
| | | tg.setUserType(tb.getUserType()); |
| | | tg.setShopTitle(tb.getShopTitle()); |
| | | tg.setTkRate(tb.getTkRate()); |
| | | tg.setSellerId(tb.getSellerId()); |
| | | tg.setState(tb.getState()); // 状态:2018-12-03 |
| | | if (tb.getCouponAmount().compareTo(BigDecimal.valueOf(0)) > 0) { |
| | | |
| | | tg.setCoupon(true);// 有券 |
| | | |
| | | TaoBaoQuanInfo quanInfo = new TaoBaoQuanInfo(); |
| | | quanInfo.setCouponAmount(tb.getCouponAmount()); |
| | | String couponEffectiveEndTime = tb.getCouponEffectiveEndTime(); |
| | | long endtime = TimeUtil.convertDateToTemp(couponEffectiveEndTime); |
| | | quanInfo.setCouponEffectiveEndTime(endtime + 1000 * 60 * 60 * 24L + ""); |
| | | quanInfo.setCouponEffectiveStartTime(TimeUtil.convertDateToTemp(tb.getCouponEffectiveStartTime()) + ""); |
| | | quanInfo.setCouponInfo(tb.getCouponInfo()); |
| | | quanInfo.setCouponLeftCount(tb.getCouponLeftCount()); |
| | | quanInfo.setCouponLink( |
| | | TaoBaoCouponUtil.getCoupleUrl(tb.getCouponActivityId(), pid, tb.getAuctionId() + "")); |
| | | quanInfo.setCouponPrice(MoneyBigDecimalUtil.sub(tg.getZkPrice(), tb.getCouponAmount())); |
| | | quanInfo.setCouponStartFee(tb.getCouponStartFee()); |
| | | quanInfo.setCouponTotalCount(tb.getCouponTotalCount()); |
| | | tg.setTaoBaoQuanInfo(quanInfo); |
| | | } |
| | | TaoBaoHongBaoInfo hongBaoInfo = new TaoBaoHongBaoInfo(); |
| | | |
| | | hongBaoInfo.setRate("最高40%"); |
| | | |
| | | String hongbao = getGoodsHongBaoInfo(tb, new BigDecimal(proportion), false); |
| | | if (hongbao.contains("最高")) { |
| | | hongBaoInfo.setType(1); |
| | | hongBaoInfo.setHongbao(new BigDecimal(0)); |
| | | } else { |
| | | hongBaoInfo.setRate(hongbao); |
| | | hongBaoInfo.setHongbao(new BigDecimal(hongbao.replace("¥", ""))); |
| | | } |
| | | |
| | | tg.setBaoyou(true); |
| | | |
| | | if (tb.getUserType() == 1) |
| | | tg.setShopType(2); |
| | | else |
| | | tg.setShopType(1); |
| | | |
| | | if (tb.getCouponAmount().compareTo(BigDecimal.valueOf(0)) == 1) |
| | | tg.setShowType(3); |
| | | else |
| | | tg.setShowType(2); |
| | | |
| | | int showType = tg.getShowType(); |
| | | if (showType == 3 || showType == 1) { |
| | | BigDecimal sub = tg.getZkPrice().subtract(tb.getCouponStartFee()); |
| | | if (sub.compareTo(BigDecimal.valueOf(0)) >= 0) { |
| | | BigDecimal quanPrice = MoneyBigDecimalUtil.sub(tg.getZkPrice(), tb.getCouponAmount()); |
| | | tg.setQuanPrice(quanPrice); |
| | | } else { |
| | | tg.setQuanPrice(tg.getZkPrice()); |
| | | } |
| | | } |
| | | |
| | | tg.setTaoBaoHongBaoInfo(hongBaoInfo); |
| | | |
| | | tg.setMoneyType(1); |
| | | tg.setSalesType(1); |
| | | // 测试使用 |
| | | // tg.setSalesType(Math.random() > 0.5 ? tg.getSalesType() : 3); |
| | | // if(Constant.IS_TEST) |
| | | // { |
| | | // List<ClientTextStyleVO> labels = new ArrayList<>(); |
| | | // labels.add(new ClientTextStyleVO("标签内容", "#F14242")); |
| | | // labels.add(new ClientTextStyleVO("标签内容", "#00FF00")); |
| | | // tg.setLabels(labels); |
| | | // } |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 获取淘宝推广链接 |
| | | * |
| | | * @param auctionId |
| | | * @param pid |
| | | * @return |
| | | */ |
| | | public static TaoBaoLink getTbLink(String auctionId, String pid, TaoBaoUnionConfig config) { |
| | | TaoBaoLink tbk = null; |
| | | String cookie = TaoBaoOrderUtil.getTaoBaoCookie(config.getAccount()); |
| | | String adzoneid = pid.split("_")[3]; |
| | | String siteId = pid.split("_")[2]; |
| | | Map<String, String> headers = new HashMap<>(); |
| | | |
| | | headers.put("Cookie", cookie); |
| | | headers.put("Referer", "http://pub.alimama.com/promo/search/index.htm"); |
| | | headers.put("User-Agent", |
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"); |
| | | headers.put("Cookie", cookie); |
| | | headers.put("X-Requested-With", "XMLHttpRequest"); |
| | | |
| | | String json = TaoBaoHttpUtil.proxyGet("http://pub.alimama.com/common/code/getAuctionCode.json?auctionid=" |
| | | + auctionId + "&adzoneid=" + adzoneid + "&siteid=" + siteId + "&scenes=1", cookie); |
| | | System.out.println(json); |
| | | if (json == null || "".equals(json.trim())) { |
| | | LogHelper.taoBaoLinkError("获取推广链接失败:" + auctionId); |
| | | return null; |
| | | } |
| | | |
| | | JSONObject data; |
| | | try { |
| | | data = JSONObject.fromObject(json); |
| | | } catch (Exception e) { |
| | | LogHelper.taoBaoLinkError("获取推广链接失败:" + auctionId); |
| | | return null; |
| | | } |
| | | |
| | | if (data.optBoolean("ok")) { |
| | | tbk = new TaoBaoLink(); |
| | | JSONObject dat = data.optJSONObject("data"); |
| | | String couponLink = dat.optString("couponLink"); |
| | | String clickUrl = dat.optString("clickUrl"); |
| | | String taoToken = dat.optString("taoToken"); |
| | | tbk.setCouponLink(couponLink); |
| | | tbk.setClickUrl(clickUrl); |
| | | tbk.setTaoToken(taoToken); |
| | | tbk.setAuctionId(auctionId); |
| | | return tbk; |
| | | } else { |
| | | LogHelper.taoBaoLinkError("获取推广链接失败:" + auctionId); |
| | | } |
| | | // 如果json返回的是false,说明cookie失效 |
| | | TaoBaoOrderUtil.reportCookieInvalid(config.getAccount()); |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 获取推广用的淘口令 |
| | | * |
| | | * @param auctionId |
| | | * @param pid |
| | | * @return |
| | | */ |
| | | public static TaoBaoLink getTbLinkForShare(String auctionId, String pid, TaoBaoUnionConfig config) { |
| | | TaoBaoLink tbk = null; |
| | | String cookie = TaoBaoOrderUtil.getTaoBaoCookie(config.getAccount()); |
| | | selfAdzoneCreate(pid, cookie); |
| | | String adzoneid = pid.split("_")[3]; |
| | | String siteId = pid.split("_")[2]; |
| | | Map<String, String> headers = new HashMap<>(); |
| | | |
| | | headers.put("Cookie", cookie); |
| | | headers.put("Referer", "http://pub.alimama.com/promo/search/index.htm"); |
| | | headers.put("User-Agent", |
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"); |
| | | headers.put("Cookie", cookie); |
| | | headers.put("X-Requested-With", "XMLHttpRequest"); |
| | | |
| | | String json = TaoBaoHttpUtil.proxyGet("http://pub.alimama.com/common/code/getAuctionCode.json?auctionid=" |
| | | + auctionId + "&adzoneid=" + adzoneid + "&siteid=" + siteId + "&scenes=1", cookie); |
| | | System.out.println(json); |
| | | LogHelper.test(json); |
| | | if (json == null || "".equals(json.trim())) { |
| | | return null; |
| | | } |
| | | |
| | | JSONObject data; |
| | | try { |
| | | data = JSONObject.fromObject(json); |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | |
| | | if (data.optBoolean("ok")) { |
| | | tbk = new TaoBaoLink(); |
| | | JSONObject dat = data.optJSONObject("data"); |
| | | String couponLink = dat.optString("couponLink"); |
| | | String clickUrl = dat.optString("clickUrl"); |
| | | String taoToken = dat.optString("taoToken"); |
| | | tbk.setCouponLink(couponLink); |
| | | tbk.setClickUrl(clickUrl); |
| | | tbk.setTaoToken(taoToken); |
| | | tbk.setAuctionId(auctionId); |
| | | |
| | | return tbk; |
| | | } |
| | | // 如果json返回的是false,说明cookie失效 |
| | | TaoBaoOrderUtil.reportCookieInvalid(config.getAccount()); |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 通过优惠券链接获取淘口令 |
| | | * |
| | | * @param picture |
| | | * @param title |
| | | * @param activityId |
| | | * @param auctionId |
| | | * @param pid |
| | | * @return |
| | | */ |
| | | public static TaoBaoLink getTbLinkWithCoupon(String picture, String title, String activityId, String auctionId, |
| | | String pid) { |
| | | activityId = StringUtil.isNullOrEmpty(activityId) ? "da75a5880d4c41ab88a82256b069a38c" : activityId; |
| | | String url = String.format("https://uland.taobao.com/coupon/edetail?activityId=%s&pid=%s&itemId=%s", activityId, |
| | | pid, auctionId + ""); |
| | | String tbk = TaoKeApiUtil.getTKToken(picture, title, url); |
| | | if (StringUtil.isNullOrEmpty(tbk)) |
| | | LogHelper.error("生成淘口令失败(优惠券链接):" + auctionId); |
| | | TaoBaoLink taoBaoLink = new TaoBaoLink(); |
| | | taoBaoLink.setAuctionId(auctionId); |
| | | taoBaoLink.setClickUrl(url); |
| | | taoBaoLink.setCouponLink(url); |
| | | taoBaoLink.setTaoToken(tbk); |
| | | return taoBaoLink; |
| | | } |
| | | |
| | | private static void selfAdzoneCreate(String pid, String cookie) { |
| | | String[] sts = cookie.split(";"); |
| | | String tbToken = ""; |
| | | for (String st : sts) { |
| | | if (st.contains("_tb_token_")) { |
| | | tbToken = st.replace("_tb_token_=", ""); |
| | | break; |
| | | } |
| | | } |
| | | String adzoneid = pid.split("_")[3]; |
| | | String siteId = pid.split("_")[2]; |
| | | String url = "http://pub.alimama.com/common/adzone/selfAdzoneCreate.json"; |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("tag", "29"); |
| | | params.put("gcid", "8"); |
| | | params.put("siteid", siteId); |
| | | params.put("selectact", "sel"); |
| | | params.put("adzoneid", adzoneid); |
| | | params.put("t", System.currentTimeMillis() + ""); |
| | | params.put("_tb_token_", tbToken); |
| | | |
| | | Map<String, String> headers = new HashMap<>(); |
| | | headers.put("Cookie", cookie); |
| | | headers.put("Referer", "http://pub.alimama.com/promo/search/index.htm"); |
| | | headers.put("User-Agent", |
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"); |
| | | headers.put("Cookie", cookie); |
| | | headers.put("X-Requested-With", "XMLHttpRequest"); |
| | | String result = TaoBaoHttpUtil.post(url, params, headers); |
| | | System.out.println(result); |
| | | } |
| | | |
| | | public static TaoBaoGoodsBriefExtra getTaoBaoGoodsBriefExtra(TaoBaoGoodsBrief tb, TaoBaoUnionConfig config, SystemEnum system) { |
| | | TaoBaoGoodsBriefExtra tg = new TaoBaoGoodsBriefExtra(); |
| | | 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()); |
| | | 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(); |
| | | quanInfo.setCouponAmount(tb.getCouponAmount()); |
| | | String couponEffectiveEndTime = tb.getCouponEffectiveEndTime(); |
| | | long endtime = TimeUtil.convertDateToTemp(couponEffectiveEndTime); |
| | | quanInfo.setCouponEffectiveEndTime(endtime + 1000 * 60 * 60 * 24L + ""); |
| | | quanInfo.setCouponEffectiveStartTime(TimeUtil.convertDateToTemp(tb.getCouponEffectiveStartTime()) + ""); |
| | | quanInfo.setCouponInfo(tb.getCouponInfo()); |
| | | quanInfo.setCouponLeftCount(tb.getCouponLeftCount()); |
| | | String pid = config.getDefaultPid(); |
| | | quanInfo.setCouponLink( |
| | | TaoBaoCouponUtil.getCoupleUrl(tb.getCouponActivityId(), pid, tb.getAuctionId() + "")); |
| | | quanInfo.setCouponPrice(tb.getZkPrice().subtract(tb.getCouponAmount())); |
| | | quanInfo.setCouponStartFee(tb.getCouponStartFee()); |
| | | quanInfo.setCouponTotalCount(tb.getCouponTotalCount()); |
| | | tg.setTaoBaoQuanInfo(quanInfo); |
| | | } |
| | | |
| | | BigDecimal proportion = taoBaoUtil.manageService.getFanLiRate(UserLevelEnum.daRen, system); |
| | | TaoBaoHongBaoInfo hongBaoInfo = new TaoBaoHongBaoInfo(); |
| | | String tkMktStatus = tb.getTkMktStatus(); |
| | | if ("1".equals(tkMktStatus)) { |
| | | hongBaoInfo.setType(1); |
| | | } |
| | | |
| | | hongBaoInfo.setRate("最高40%"); |
| | | |
| | | String hongbao = getGoodsHongBaoInfo(tb, proportion, false); |
| | | if (!hongbao.contains("最高")) |
| | | hongBaoInfo.setHongbao(new BigDecimal(hongbao.replace("¥", ""))); |
| | | else |
| | | hongBaoInfo.setHongbao(new BigDecimal(0)); |
| | | |
| | | tg.setBaoyou(true); |
| | | |
| | | if (tb.getUserType() == 1) |
| | | tg.setShopType(2); |
| | | else |
| | | tg.setShopType(1); |
| | | |
| | | if (tb.getCouponAmount().compareTo(BigDecimal.valueOf(0)) == 1) |
| | | tg.setShowType(3); |
| | | else |
| | | tg.setShowType(2); |
| | | |
| | | int showType = tg.getShowType(); |
| | | if (showType == 3 || showType == 1) { |
| | | BigDecimal sub = tg.getZkPrice().subtract(tb.getCouponStartFee()); |
| | | if (sub.compareTo(BigDecimal.valueOf(0)) >= 0) { |
| | | BigDecimal quanPrice = tg.getZkPrice().subtract(tb.getCouponAmount()); |
| | | tg.setQuanPrice(quanPrice); |
| | | } else { |
| | | tg.setQuanPrice(tg.getZkPrice()); |
| | | } |
| | | } |
| | | tg.setTaoBaoHongBaoInfo(hongBaoInfo); |
| | | |
| | | tg.setMoneyType(1); |
| | | tg.setSalesType(1); |
| | | // 测试使用 |
| | | // tg.setMoneyType(Math.random() > 0.5 ? 1 : 2); |
| | | // tg.setSalesType(Math.random() > 0.5 ? 1 : 2); |
| | | // tg.setSalesType(Math.random() > 0.5 ? tg.getSalesType() : 3); |
| | | // List<ClientTextStyleVO> labels = new ArrayList<>(); |
| | | // labels.add(new ClientTextStyleVO("标签内容", "#F14242")); |
| | | // labels.add(new ClientTextStyleVO("标签内容", "#000000")); |
| | | // tg.setLabels(labels); |
| | | |
| | | return tg; |
| | | } |
| | | |
| | | /** |
| | | * 获取未参与推广的淘宝商品详情 @Title: getTaoBaoGoodsBrief @Description: @param |
| | | * id @return TaoBaoGoodsBrief 包含(标题与图片) @throws |
| | | */ |
| | | public static TaoBaoGoodsBrief getTaoBaoGoodsBriefNotInPub(String id) { |
| | | TaoBaoGoodsBrief tb = TaoBaoUtil.getTmallGoodsInfo(id + ""); |
| | | return tb; |
| | | } |
| | | |
| | | public static List<String> getSuguestSearch(String key) { |
| | | try { |
| | | String url = String.format("https://suggest.taobao.com/sug?code=utf-8&q=%s&_=1486720576511", |
| | | URLEncoder.encode(key, "UTF-8")); |
| | | HttpClient client = new HttpClient(); |
| | | GetMethod gm = new GetMethod(url); |
| | | client.executeMethod(gm); |
| | | String result = gm.getResponseBodyAsString(); |
| | | JSONObject obj = JSONObject.fromObject(result); |
| | | if (obj != null) { |
| | | JSONArray array = obj.optJSONArray("result"); |
| | | List<String> list = new ArrayList<String>(); |
| | | for (int i = 0; i < array.size(); i++) { |
| | | list.add(array.optJSONArray(i).optString(0)); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static List<String> getTbImg(String auctionId) { |
| | | if (!NumberUtil.isNumeric(auctionId)) |
| | | return new ArrayList<>(); |
| | | TaoBaoGoodsBrief taoBaoGoodsBrief = null; |
| | | try { |
| | | taoBaoGoodsBrief = TaoKeApiUtil.getSimpleGoodsInfo(auctionId); |
| | | } catch (TaobaoGoodsDownException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | List<String> list = new ArrayList<String>(); |
| | | if (taoBaoGoodsBrief == null) |
| | | return list; |
| | | |
| | | if (!StringUtil.isNullOrEmpty(taoBaoGoodsBrief.getPictUrl())) |
| | | list.add(taoBaoGoodsBrief.getPictUrl()); |
| | | if (taoBaoGoodsBrief.getImgList() != null && taoBaoGoodsBrief.getImgList().size() > 0) |
| | | list.addAll(taoBaoGoodsBrief.getImgList()); |
| | | return list; |
| | | } |
| | | |
| | | public static TaoBaoGoodsBrief isAlimama(String auctionId) { |
| | | if (StringUtil.isNullOrEmpty(auctionId) || !NumberUtil.isNumeric(auctionId)) |
| | | return null; |
| | | TaoBaoGoodsBrief tb = null; |
| | | try { |
| | | tb = TaoKeApiUtil.getSimpleGoodsInfo(auctionId); |
| | | } catch (TaobaoGoodsDownException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return tb; |
| | | } |
| | | |
| | | public static List<TaoBaoGoodsBriefExtra> getTaoBaoGoodsBriefExtraList(List<TaoBaoCoupon> list) { |
| | | List<TaoBaoGoodsBriefExtra> tbxs = new ArrayList<TaoBaoGoodsBriefExtra>(); |
| | | TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra = null; |
| | | TaoBaoQuanInfo taobaoQuanInfo = null; |
| | | TaoBaoHongBaoInfo taobaoHongbaoInfo = null; |
| | | for (TaoBaoCoupon taoBaoCoupon : list) { |
| | | taoBaoGoodsBriefExtra = new TaoBaoGoodsBriefExtra(); |
| | | taobaoQuanInfo = new TaoBaoQuanInfo(); |
| | | taobaoQuanInfo.setCouponAmount(taoBaoCoupon.getCouponAmount()); |
| | | taobaoQuanInfo.setCouponInfo(taoBaoCoupon.getCouponinfo()); |
| | | taobaoQuanInfo.setCouponPrice(taoBaoCoupon.getQuanPrice()); |
| | | taobaoQuanInfo.setCouponLink(taoBaoCoupon.getCouponLink()); |
| | | taobaoHongbaoInfo = new TaoBaoHongBaoInfo(); |
| | | taobaoHongbaoInfo.setHongbao(taoBaoCoupon.getHongbao()); |
| | | taobaoHongbaoInfo.setRate("¥" + taoBaoCoupon.getHongbao().toString()); |
| | | |
| | | taoBaoGoodsBriefExtra.setTaoBaoHongBaoInfo(taobaoHongbaoInfo); |
| | | taoBaoGoodsBriefExtra.setTaoBaoQuanInfo(taobaoQuanInfo); |
| | | |
| | | taoBaoGoodsBriefExtra.setAuctionId(taoBaoCoupon.getAuctionId()); |
| | | taoBaoGoodsBriefExtra.setAuctionUrl(taoBaoCoupon.getAuctionUrl()); |
| | | taoBaoGoodsBriefExtra.setBaoyou(true); |
| | | taoBaoGoodsBriefExtra.setBiz30day(taoBaoCoupon.getBiz30day()); |
| | | taoBaoGoodsBriefExtra.setPictUrl(taoBaoCoupon.getPictUrl()); |
| | | taoBaoGoodsBriefExtra.setQuanPrice(taoBaoCoupon.getQuanPrice()); |
| | | |
| | | int shopType = taoBaoCoupon.getShopType(); |
| | | taoBaoGoodsBriefExtra.setShopType(shopType); |
| | | taoBaoGoodsBriefExtra.setShowType(taoBaoCoupon.getShowType()); |
| | | |
| | | taoBaoGoodsBriefExtra.setTitle(taoBaoCoupon.getTitle()); |
| | | taoBaoGoodsBriefExtra.setReservePrice(taoBaoCoupon.getZkPrice()); |
| | | taoBaoGoodsBriefExtra.setZkPrice(taoBaoCoupon.getZkPrice()); |
| | | taoBaoGoodsBriefExtra.setSellerId(taoBaoCoupon.getSellerId()); |
| | | tbxs.add(taoBaoGoodsBriefExtra); |
| | | } |
| | | |
| | | return tbxs; |
| | | } |
| | | |
| | | public static TaoBaoGoodsBrief parsePhoneShareUrlByTM(String murl) { |
| | | if (!murl.contains("http://zmnxbc.com")) { // 手机天猫分享 |
| | | return null; |
| | | } |
| | | TaoBaoGoodsBrief taobao; |
| | | try { |
| | | Connection connect = Jsoup.connect(murl); |
| | | Document document = connect.get(); |
| | | org.jsoup.nodes.Element element = document.getElementsByTag("head").get(0).getElementsByTag("Script") |
| | | .get(2); |
| | | String html = element.html(); |
| | | String json = html.substring(html.indexOf("{"), html.lastIndexOf("}") + 1); |
| | | JSONObject data = JSONObject.fromObject(json); |
| | | String auctionId = data.optString("bizId"); |
| | | TaoBaoGoodsBrief alimama = isAlimama(auctionId); |
| | | if (alimama != null) { |
| | | return alimama; |
| | | } |
| | | String price = data.optString("itemPrice", "0"); |
| | | String title = data.optString("content"); |
| | | String url = data.optJSONArray("actionRule").optJSONObject(0).optString("url"); |
| | | Document document2 = Jsoup.connect("http:" + url).get(); |
| | | org.jsoup.nodes.Element element2 = document2.getElementById("s-showcase").getElementsByClass("scroller") |
| | | .get(0); |
| | | Elements elements = element2.getElementsByClass("item"); |
| | | List<String> imgStrs = new ArrayList<String>(); |
| | | for (org.jsoup.nodes.Element e : elements) { |
| | | org.jsoup.nodes.Element img = e.getElementsByTag("img").get(0); |
| | | String attr = img.attr("src"); |
| | | if (attr == "") { |
| | | attr = img.attr("data-src"); |
| | | } |
| | | if (!attr.contains("http:")) { |
| | | attr = "http:" + attr; |
| | | } |
| | | imgStrs.add(attr); |
| | | } |
| | | taobao = new TaoBaoGoodsBrief(); |
| | | taobao.setAuctionId(auctionId); |
| | | taobao.setTitle(title); |
| | | taobao.setZkPrice(new BigDecimal(price)); |
| | | taobao.setImgList(imgStrs); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | return taobao; |
| | | } |
| | | |
| | | public static TaoBaoGoodsBrief parsePhoneShareUrlByTB(String burl) { |
| | | try { |
| | | Connection connect = Jsoup.connect(burl); |
| | | Document document = connect.get(); |
| | | org.jsoup.nodes.Element element = document.getElementsByTag("head").get(0).getElementsByTag("Script") |
| | | .get(1); |
| | | String html = element.toString(); |
| | | int index = html.indexOf("var url = "); |
| | | int endIndex = html.lastIndexOf("'"); |
| | | html = html.substring(index, endIndex); |
| | | int index2 = html.indexOf("'"); |
| | | html = html.substring(index2 + 1); |
| | | int indexId = html.indexOf("id="); |
| | | String id = ""; |
| | | if (html.contains("a.m.taobao.com")) { |
| | | indexId = html.indexOf("com/i"); |
| | | html = html.substring(indexId); |
| | | html = html.substring(5, html.indexOf(".")); |
| | | id = html; |
| | | } else { |
| | | String reg = "[?|&]{1}[i]{1}[d]{1}[=]{1}\\d+[&]?"; |
| | | Pattern p = Pattern.compile(reg); |
| | | Matcher matcher = p.matcher(html); |
| | | if (matcher.find()) { |
| | | id = matcher.group(); |
| | | } |
| | | id = id.substring(id.indexOf("=") + 1, id.lastIndexOf("&")); |
| | | } |
| | | TaoBaoGoodsBrief alimama = isAlimama(id); |
| | | |
| | | if (alimama != null) { |
| | | return alimama; |
| | | } |
| | | return parsePhoneTmAndTb(id); |
| | | } catch (Exception e) { |
| | | LogHelper.error("无法解析到淘宝商品ID:" + burl); |
| | | return null; |
| | | } |
| | | |
| | | } |
| | | |
| | | public static TaoBaoGoodsBrief parsePhoneTmAndTb(String auctionId) { |
| | | |
| | | TaoBaoGoodsBrief taoBaoGoodsBrief = null; |
| | | try { |
| | | |
| | | Connection connect = Jsoup.connect(String.format(TM_PHONE_URL, auctionId)); |
| | | Document document = connect.get(); |
| | | Elements elements = document.getElementsByTag("script"); |
| | | if (elements.size() >= 9) { |
| | | String json = elements.get(8).toString(); |
| | | json = json.substring(json.indexOf("{"), json.lastIndexOf("}") + 1); |
| | | JSONObject data = JSONObject.fromObject(json); |
| | | JSONObject model = data.optJSONObject("defaultModel"); |
| | | JSONObject itemPriceResultDO = model.optJSONObject("itemPriceResultDO"); |
| | | JSONObject priceInfo = itemPriceResultDO.optJSONObject("priceInfo"); |
| | | Set keySet = priceInfo.keySet(); |
| | | String key = (String) keySet.toArray()[0]; |
| | | JSONObject goods = priceInfo.optJSONObject(key); |
| | | String price = ""; |
| | | if (goods.optJSONArray("promotionList") != null) { |
| | | price = goods.optJSONArray("promotionList").getJSONObject(0).optString("price"); |
| | | } else { |
| | | price = goods.optString("price"); |
| | | } |
| | | List<String> imgs = new ArrayList<String>(); |
| | | Element showcase = document.getElementById("s-showcase"); |
| | | Elements Eleimgs = showcase.getElementsByTag("img"); |
| | | for (Element Eleimg : Eleimgs) { |
| | | String img = Eleimg.attr("src"); |
| | | if ("".equals(img)) { |
| | | img = Eleimg.attr("data-src"); |
| | | } |
| | | if (!img.contains("http")) { |
| | | img = "http:" + img; |
| | | } |
| | | imgs.add(img); |
| | | } |
| | | Element stitle = document.getElementById("s-title"); |
| | | String title = stitle.getElementsByTag("h1").get(0).toString().replaceAll("<h1>", "") |
| | | .replaceAll("</h1>", ""); |
| | | taoBaoGoodsBrief = new TaoBaoGoodsBrief(); |
| | | taoBaoGoodsBrief.setZkPrice(new BigDecimal(price)); |
| | | taoBaoGoodsBrief.setTitle(title); |
| | | taoBaoGoodsBrief.setImgList(imgs); |
| | | taoBaoGoodsBrief.setPictUrl(imgs.get(0)); |
| | | taoBaoGoodsBrief.setAuctionId(auctionId); |
| | | taoBaoGoodsBrief.setUserType(1); |
| | | } else { |
| | | Connection connect2 = Jsoup.connect(String.format(TB_URL, auctionId)); |
| | | Document document2 = connect2.get(); |
| | | Elements elements2 = document2.getElementsByTag("script"); |
| | | String json = elements2.get(0).toString(); |
| | | json = json.substring(json.indexOf("item:"), json.indexOf("seller:")); |
| | | json = json.substring(json.indexOf("{"), json.lastIndexOf(",")); |
| | | json = json.substring(json.indexOf("auctionImages"), json.lastIndexOf("]") + 1); |
| | | json = json.substring(json.indexOf("[")); |
| | | JSONArray array = JSONArray.fromObject(json); |
| | | List<String> imgs = new ArrayList<String>(); |
| | | for (Object str : array) { |
| | | String imgStr = String.valueOf(str); |
| | | if (!imgStr.contains("http")) { |
| | | imgStr = "http:" + imgStr; |
| | | } |
| | | imgs.add(imgStr); |
| | | } |
| | | String turl = "https://detailskip.taobao.com/service/getData/1/p1/item/detail/sib.htm?itemId=" |
| | | + auctionId |
| | | + "&sellerId=0&modules=dynStock,qrcode,viewer,price,duty,xmpPromotion,delivery,upp,activity,fqg,zjys,couponActivity,soldQuantity,contract,tradeContract&callback=onSibRequestSuccess"; |
| | | Map<String, String> params = new HashMap<String, String>(); |
| | | params.put("Referer", "https://item.taobao.com/item.htm?id=" + auctionId); |
| | | String json2 = TaoBaoHttpUtil.get(turl, params); |
| | | json2 = json2.substring(json2.indexOf("{"), json2.lastIndexOf("}") + 1); |
| | | JSONObject data2 = JSONObject.fromObject(json2); |
| | | String price = data2.optJSONObject("data").optJSONObject("promotion").optJSONObject("promoData") |
| | | .optJSONArray("def").getJSONObject(0).optString("price"); |
| | | String title = document2.getElementsByTag("title").get(0).toString(); |
| | | title = title.replaceAll("-淘宝网", "").replaceAll("<title>", "").replaceAll("</title>", ""); |
| | | taoBaoGoodsBrief = new TaoBaoGoodsBrief(); |
| | | taoBaoGoodsBrief.setTitle(title); |
| | | taoBaoGoodsBrief.setPictUrl(imgs.get(0)); |
| | | taoBaoGoodsBrief.setImgList(imgs); |
| | | taoBaoGoodsBrief.setZkPrice(new BigDecimal(price)); |
| | | taoBaoGoodsBrief.setAuctionId(auctionId); |
| | | taoBaoGoodsBrief.setUserType(0); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | return taoBaoGoodsBrief; |
| | | } |
| | | |
| | | public static String getGoodsIdByPhoneShareUrl(String burl) { |
| | | try { |
| | | Connection connect = Jsoup.connect(burl); |
| | | Document document = connect.get(); |
| | | org.jsoup.nodes.Element element = document.getElementsByTag("head").get(0).getElementsByTag("Script") |
| | | .get(1); |
| | | String html = element.toString(); |
| | | int index = html.indexOf("var url = "); |
| | | int endIndex = html.lastIndexOf("'"); |
| | | html = html.substring(index, endIndex); |
| | | int index2 = html.indexOf("'"); |
| | | html = html.substring(index2 + 1); |
| | | int indexId = html.indexOf("id="); |
| | | String id = ""; |
| | | if (html.contains("a.m.taobao.com")) { |
| | | indexId = html.indexOf("com/i"); |
| | | html = html.substring(indexId); |
| | | html = html.substring(5, html.indexOf(".")); |
| | | id = html; |
| | | } else { |
| | | String reg = "[?|&]{1}[i]{1}[d]{1}[=]{1}\\d+[&]?"; |
| | | Pattern p = Pattern.compile(reg); |
| | | Matcher matcher = p.matcher(html); |
| | | if (matcher.find()) { |
| | | id = matcher.group(); |
| | | } |
| | | id = id.substring(id.indexOf("=") + 1, id.lastIndexOf("&")); |
| | | } |
| | | return id; |
| | | } catch (Exception e) { |
| | | LogHelper.error("无法解析到淘宝商品ID:" + burl); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取商品的用户分成比例 |
| | | * |
| | | * @param goodsBrief 商品详情 |
| | | * @param rate 用户再次分成比例(0-100) |
| | | * @return |
| | | */ |
| | | public static String getGoodsHongBaoInfo(TaoBaoGoodsBrief goodsBrief, BigDecimal rate, boolean share) { |
| | | // if (goodsBrief != null && goodsBrief.getMaterialLibType() != null && |
| | | // goodsBrief.getMaterialLibType() == 0) |
| | | // return "¥0.00"; |
| | | // else |
| | | return "¥" + getGoodsHongBaoMoney(goodsBrief, rate, share).toString(); |
| | | } |
| | | |
| | | /** |
| | | * 获取淘宝商品该获得多少佣金 |
| | | * |
| | | * @param goodsBrief |
| | | * @param rate |
| | | * @return |
| | | */ |
| | | public static BigDecimal getGoodsHongBaoMoney(TaoBaoGoodsBrief goodsBrief, BigDecimal rate, boolean share) { |
| | | BigDecimal commissionRate = null; |
| | | if (goodsBrief.getMinTkRate() != null && !share) |
| | | commissionRate = goodsBrief.getMinTkRate(); |
| | | else |
| | | commissionRate = goodsBrief.getTkRate(); |
| | | |
| | | BigDecimal money = null; |
| | | if (StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo()) |
| | | || goodsBrief.getCouponInfo().trim().equalsIgnoreCase("无")) { |
| | | money = MoneyBigDecimalUtil.mul( |
| | | MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(goodsBrief.getZkPrice(), commissionRate), |
| | | new BigDecimal("0.01")), |
| | | MoneyBigDecimalUtil.div(rate, new BigDecimal(100))); |
| | | } else// 有券 |
| | | { |
| | | List<BigDecimal> list = TaoBaoCouponUtil.getCouponInfo(goodsBrief.getCouponInfo()); |
| | | BigDecimal startFee = list.get(0); |
| | | BigDecimal couponAccount = list.get(1); |
| | | if (startFee.compareTo(goodsBrief.getZkPrice()) <= 0 |
| | | && goodsBrief.getZkPrice().compareTo(couponAccount) > 0) { |
| | | BigDecimal finalPrice = goodsBrief.getZkPrice().subtract(couponAccount); |
| | | money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil |
| | | .mul(MoneyBigDecimalUtil.mul(finalPrice, commissionRate), new BigDecimal("0.01")), |
| | | MoneyBigDecimalUtil.div(rate, new BigDecimal(100))); |
| | | |
| | | } else {// 不能用券 |
| | | money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul( |
| | | MoneyBigDecimalUtil.mul(goodsBrief.getZkPrice(), commissionRate), |
| | | new BigDecimal("0.01")), MoneyBigDecimalUtil.div(rate, new BigDecimal(100))); |
| | | } |
| | | } |
| | | |
| | | if (share) |
| | | money = TaoBaoUtil.getCanShareMoney(new Date(), money); |
| | | |
| | | |
| | | return BigDecimalUtil.getWithNoZera(money); |
| | | } |
| | | |
| | | // } |
| | | |
| | | // 获取券的红包显示 |
| | | public static BigDecimal getCouponHongBaoInfo(TaoBaoCoupon taoBaoCoupon, BigDecimal rate) { |
| | | // 营销计划 |
| | | |
| | | // 计算返利 |
| | | // 无券 |
| | | |
| | | BigDecimal startFee = taoBaoCoupon.getCouponStartFee(); |
| | | BigDecimal couponAccount = taoBaoCoupon.getCouponAmount(); |
| | | if (startFee.compareTo(taoBaoCoupon.getZkPrice()) <= 0 |
| | | && taoBaoCoupon.getZkPrice().compareTo(couponAccount) > 0) { |
| | | BigDecimal finalPrice = taoBaoCoupon.getZkPrice().subtract(couponAccount); |
| | | return finalPrice.multiply(new BigDecimal(taoBaoCoupon.getTkRate())).divide(new BigDecimal(10000)) |
| | | .multiply(rate).setScale(2, BigDecimal.ROUND_DOWN); |
| | | } else {// 不能用券 |
| | | return taoBaoCoupon.getZkPrice().multiply(new BigDecimal(taoBaoCoupon.getTkRate())) |
| | | .divide(new BigDecimal(10000)).multiply(rate).setScale(2, BigDecimal.ROUND_DOWN); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取分享赚的金额 |
| | | * |
| | | * @param goodsBrief |
| | | * @param rate |
| | | * @return |
| | | */ |
| | | |
| | | public static BigDecimal getShareGoodsHongBaoInfo(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) { |
| | | return getGoodsHongBaoMoney(goodsBrief, rate, true); |
| | | } |
| | | |
| | | /** |
| | | * 计算商品券后价,没有券则返回原价 |
| | | * |
| | | * @param goodsBrief |
| | | * @return |
| | | */ |
| | | public static BigDecimal getCouponPrice(TaoBaoGoodsBrief goodsBrief) { |
| | | |
| | | if (StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo()) || "无".equals(goodsBrief.getCouponInfo())) { |
| | | return goodsBrief.getZkPrice(); |
| | | } else { |
| | | List<BigDecimal> list = TaoBaoCouponUtil.getCouponInfo(goodsBrief.getCouponInfo()); |
| | | BigDecimal startFee = list.get(0); |
| | | BigDecimal couponAccount = list.get(1); |
| | | if (startFee.compareTo(goodsBrief.getZkPrice()) <= 0 |
| | | && goodsBrief.getZkPrice().compareTo(couponAccount) > 0) { |
| | | BigDecimal finalPrice = goodsBrief.getZkPrice().subtract(couponAccount); |
| | | return finalPrice; |
| | | } else {// 不能用券 |
| | | return goodsBrief.getZkPrice(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取图文详情 |
| | | * |
| | | * @param id |
| | | */ |
| | | public static List<String> getGoodsTextAndImageDetails(Long id) { |
| | | if (id == null) { |
| | | return null; |
| | | } |
| | | long startTime = System.currentTimeMillis(); |
| | | |
| | | String url = null; |
| | | try { |
| | | url = String.format("http://hws.m.taobao.com/cache/mtop.wdetail.getItemDescx/4.1/?&data=%s&type=jsonp", |
| | | URLEncoder.encode("{\"item_num_id\":\"" + id + "\"}", "UTF-8")); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | List<String> list = new ArrayList<>(); |
| | | String html = org.yeshi.utils.HttpUtil.get(url); |
| | | String json = html.substring(9, html.length() - 1); |
| | | |
| | | try { |
| | | JSONObject obj = JSONObject.fromObject(json); |
| | | JSONArray array = obj.getJSONObject("data").optJSONArray("images"); |
| | | for (int i = 0; i < array.size(); i++) { |
| | | list.add(array.optString(i)); |
| | | } |
| | | LogHelper.test("获取商品图文详情耗时:" + (System.currentTimeMillis() - startTime)); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | public static String getSaleCount(int count) { |
| | | if (count >= 10000) { |
| | | double sales = count; |
| | | String salesCountMidea = String.format("%.1f", sales / 10000); |
| | | return salesCountMidea + "万"; |
| | | } else |
| | | return count + ""; |
| | | } |
| | | |
| | | public static List<TaoBaoProvince> getTaoBaoProvinceList() { |
| | | if (taoBaoProvinceList == null) { |
| | | taoBaoProvinceList = new ArrayList<>(); |
| | | // 解析 |
| | | try { |
| | | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
| | | DocumentBuilder builder = factory.newDocumentBuilder(); |
| | | org.w3c.dom.Document doc = builder |
| | | .parse(TaoBaoUtil.class.getClassLoader().getResourceAsStream("taobao_address.xml")); |
| | | NodeList nodeList = doc.getElementsByTagName("province"); |
| | | nodeList = nodeList.item(0).getChildNodes(); |
| | | for (int i = 0; i < nodeList.getLength(); i++) { |
| | | TaoBaoProvince province = new TaoBaoProvince(); |
| | | org.w3c.dom.Node node = nodeList.item(i); |
| | | if (node.getNodeName().equalsIgnoreCase("topName")) { |
| | | NamedNodeMap map = node.getAttributes(); |
| | | for (int n = 0; n < map.getLength(); n++) { |
| | | if (map.item(n).getNodeName().equalsIgnoreCase("id")) { |
| | | province.setId(map.item(n).getNodeValue()); |
| | | } else if (map.item(n).getNodeName().equalsIgnoreCase("name")) { |
| | | province.setName(map.item(n).getNodeValue()); |
| | | } |
| | | } |
| | | taoBaoProvinceList.add(province); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | return taoBaoProvinceList; |
| | | } |
| | | |
| | | public static List<ImageInfo> getTBDetailImageWithSize(String auctionId) { |
| | | |
| | | List<ImageInfo> imgList = new ArrayList<>(); |
| | | |
| | | long startTime = System.currentTimeMillis(); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("id", auctionId + ""); |
| | | String url = ""; |
| | | try { |
| | | url = String.format( |
| | | "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 pcDescContent = data.optJSONObject("data").optString("pcDescContent"); |
| | | System.out.println(pcDescContent); |
| | | if (!StringUtil.isNullOrEmpty(pcDescContent)) { |
| | | try { |
| | | 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) { |
| | | } |
| | | } |
| | | System.out.println("请求详情耗时:" + (System.currentTimeMillis() - startTime)); |
| | | return imgList; |
| | | } |
| | | |
| | | /** |
| | | * @param auctionId |
| | | * @return |
| | | */ |
| | | |
| | | public static List<ImageInfo> getTBDetailImageWithSizev2(String 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, 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])); |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | try { |
| | | LogHelper.errorDetailInfo(e); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | return imgList; |
| | | } |
| | | |
| | | /** |
| | | * 阿里百川转链接口(暂时无法使用) |
| | | * |
| | | * @param auctionId |
| | | * @param appKey |
| | | * @param adzoneId |
| | | * @return |
| | | */ |
| | | public static String getBaiChuanConvertLink(String auctionId, String appKey, String adzoneId) { |
| | | String url = "http://acs4baichuan.m.taobao.com/gw-open/mtop.taobao.tbk.sdk.item.convert/1.0/"; |
| | | JSONObject params = new JSONObject(); |
| | | params.put("mcid", "tunion4android@862977040115210"); |
| | | params.put("appVersion", "1.3.4"); |
| | | params.put("os", "android8.0.0"); |
| | | params.put("taokeAppkey", appKey); |
| | | params.put("jtype", "tb"); |
| | | params.put("aliapp", "tb"); |
| | | params.put("adzoneid", adzoneId); |
| | | params.put("url", "https://h5.m.taobao.com/awp/core/detail.htm?id=" + auctionId); |
| | | params.put("deviceModel", "LND-AL30"); |
| | | params.put("sdkVersion", "0.3.2"); |
| | | params.put("packageName", "com.yeshi.ec.rebate"); |
| | | params.put("cid", "tunion4android@862977040115210_1536222395791"); |
| | | |
| | | try { |
| | | url += "?data=" + URLEncoder.encode(params.toString(), "UTF-8"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | String result = HttpUtil.get(url); |
| | | System.out.println(result); |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 常规商品转为淘宝商品对象 |
| | | * |
| | | * @param commonGoods |
| | | * @return |
| | | */ |
| | | public static TaoBaoGoodsBrief convert(CommonGoods commonGoods) { |
| | | TaoBaoGoodsBrief taoBaoGoods = new TaoBaoGoodsBrief(); |
| | | if(!StringUtil.isNullOrEmpty(commonGoods.getGoodsSign())) { |
| | | taoBaoGoods.setAuctionId(commonGoods.getGoodsSign()); |
| | | }else{ |
| | | taoBaoGoods.setAuctionId(commonGoods.getGoodsId()); |
| | | } |
| | | taoBaoGoods.setBiz30day(commonGoods.getSales()); |
| | | taoBaoGoods.setCouponAmount(commonGoods.getCouponAmount()); |
| | | taoBaoGoods.setCouponInfo(commonGoods.getCouponInfo()); |
| | | taoBaoGoods.setCouponLeftCount(commonGoods.getCouponLeftCount()); |
| | | taoBaoGoods.setCouponStartFee(commonGoods.getCouponStartPrice()); |
| | | taoBaoGoods.setCouponTotalCount(commonGoods.getCouponTotalCount()); |
| | | taoBaoGoods.setPictUrl(commonGoods.getPicture()); |
| | | taoBaoGoods.setPictUrlWhite(commonGoods.getPictureWhite()); |
| | | taoBaoGoods.setSellerId(commonGoods.getSellerId()); |
| | | taoBaoGoods.setShopTitle(commonGoods.getSellerName()); |
| | | taoBaoGoods.setTitle(commonGoods.getTitle()); |
| | | taoBaoGoods.setUserType(commonGoods.getShopType() - 1); |
| | | taoBaoGoods.setZkPrice(commonGoods.getPrice()); |
| | | taoBaoGoods.setTkRate(commonGoods.getRate()); |
| | | taoBaoGoods.setTkCommFee(new BigDecimal("0")); |
| | | taoBaoGoods.setState(commonGoods.getState()); |
| | | taoBaoGoods.setCreatetime(commonGoods.getCreateTime()); |
| | | return taoBaoGoods; |
| | | } |
| | | |
| | | public static TaoBaoGoodsBrief convert(DaTaoKeDetailV2 detail) { |
| | | TaoBaoGoodsBrief taoBaoGoods = new TaoBaoGoodsBrief(); |
| | | taoBaoGoods.setAuctionId(detail.getGoodsId()); |
| | | taoBaoGoods.setBiz30day(detail.getMonthSales()); |
| | | // 券相关转换 |
| | | taoBaoGoods.setCouponAmount(detail.getCouponPrice()); |
| | | taoBaoGoods.setCouponInfo(String.format("满%s元减%s元", detail.getOriginalPrice(), |
| | | MoneyBigDecimalUtil.getWithNoZera(detail.getCouponPrice()))); |
| | | if (detail.getCouponTotalNum() != null && detail.getCouponReceiveNum() != null) |
| | | taoBaoGoods.setCouponLeftCount(detail.getCouponTotalNum() - detail.getCouponReceiveNum()); |
| | | else |
| | | taoBaoGoods.setCouponLeftCount(0); |
| | | taoBaoGoods.setCouponStartFee(detail.getOriginalPrice()); |
| | | try { |
| | | taoBaoGoods.setCouponStartFee(detail.getOriginalPrice()); |
| | | } catch (Exception e) { |
| | | } |
| | | |
| | | taoBaoGoods.setCouponTotalCount(detail.getCouponTotalNum()); |
| | | taoBaoGoods.setCouponLink(detail.getCouponLink()); |
| | | taoBaoGoods.setCouponEffectiveStartTime(TimeUtil.getGernalTime( |
| | | TimeUtil.convertToTimeTemp(detail.getCouponStartTime(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd")); |
| | | taoBaoGoods.setCouponEffectiveEndTime(TimeUtil.getGernalTime( |
| | | TimeUtil.convertToTimeTemp(detail.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd")); |
| | | |
| | | taoBaoGoods.setPictUrl(detail.getMainPic()); |
| | | taoBaoGoods.setPictUrlWhite(detail.getMainPic()); |
| | | if (taoBaoGoods.getPictUrl() != null && !taoBaoGoods.getPictUrl().startsWith("http")) |
| | | taoBaoGoods.setPictUrl("https:" + taoBaoGoods.getPictUrl()); |
| | | |
| | | if (taoBaoGoods.getPictUrlWhite() != null && !taoBaoGoods.getPictUrlWhite().startsWith("http")) |
| | | taoBaoGoods.setPictUrlWhite("https:" + taoBaoGoods.getPictUrlWhite()); |
| | | |
| | | |
| | | String imgs = detail.getImgs(); |
| | | if (!StringUtil.isNullOrEmpty(imgs)) { |
| | | String[] array = imgs.split(","); |
| | | if (array != null && array.length > 0) { |
| | | List<String> imgList = new ArrayList<>(); |
| | | for (int i = 0; i < array.length; i++) { |
| | | imgList.add(array[i]); |
| | | } |
| | | taoBaoGoods.setImgList(imgList); |
| | | } |
| | | } |
| | | |
| | | |
| | | taoBaoGoods.setSellerId(detail.getSellerId()); |
| | | taoBaoGoods.setShopTitle(detail.getShopName()); |
| | | taoBaoGoods.setTitle(detail.getDtitle()); |
| | | taoBaoGoods.setUserType(detail.getShopType()); |
| | | taoBaoGoods.setZkPrice(detail.getOriginalPrice()); |
| | | taoBaoGoods.setTkRate(detail.getCommissionRate()); |
| | | taoBaoGoods.setTkCommFee(new BigDecimal("0")); |
| | | taoBaoGoods.setState(0); |
| | | return taoBaoGoods; |
| | | } |
| | | |
| | | /** |
| | | * 获取淘宝联盟的授权链接 |
| | | * |
| | | * @param appKey -应用Key |
| | | * @param callBackUrl -回调链接 |
| | | * @param uid-用户ID |
| | | * @return |
| | | */ |
| | | public static String getTaoBaoUnionAuthUrl(String appKey, String callBackUrl, Long uid, String source) { |
| | | if (uid == null) |
| | | return null; |
| | | long timestamp = System.currentTimeMillis(); |
| | | JSONObject json = new JSONObject(); |
| | | json.put("u", uid); |
| | | json.put("t", timestamp); |
| | | json.put("s", source); |
| | | String url = null; |
| | | try { |
| | | url = String.format( |
| | | "https://oauth.taobao.com/authorize?response_type=code&client_id=%s&redirect_uri=%s&state=%s&view=wap", |
| | | appKey, callBackUrl, |
| | | URLEncoder.encode(AESUtil.encrypt(json.toString(), Constant.UIDAESKEY), "UTF-8")); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return url; |
| | | } |
| | | |
| | | /** |
| | | * 获取淘宝的商品详情 |
| | | * |
| | | * @param actionId |
| | | * @return |
| | | */ |
| | | public static TaoBaoGoodsBrief getSimpleGoodsBrief(String actionId) { |
| | | JSONObject data = new JSONObject(); |
| | | data.put("itemNumId", actionId + ""); |
| | | |
| | | String url = ""; |
| | | try { |
| | | 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 = 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"); |
| | | 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.optString("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; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 根据商品ID获取店铺详情 |
| | | * |
| | | * @param auctionId |
| | | * @return |
| | | */ |
| | | public static TaoBaoShop getTaoBaoShopDetailByAuctionId(String auctionId) { |
| | | JSONObject data = new JSONObject(); |
| | | data.put("itemNumId", auctionId + ""); |
| | | |
| | | String url = ""; |
| | | try { |
| | | url = String.format("https://acs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?data=%s", |
| | | URLEncoder.encode(data.toString(), "UTF-8")); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | String result = HttpUtil.get(url); |
| | | |
| | | TaoBaoShop shop = new TaoBaoShop(); |
| | | |
| | | try { |
| | | JSONObject resultJson = JSONObject.fromObject(result); |
| | | JSONObject dataJson = resultJson.optJSONObject("data"); |
| | | JSONObject sellerJson = dataJson.optJSONObject("seller"); |
| | | |
| | | shop.setGoodRatePercentage(new BigDecimal(sellerJson.optString("goodRatePercentage").replace("%", ""))); |
| | | |
| | | LogHelper.test("卖家信息:" + result); |
| | | shop.setId(sellerJson.optLong("userId")); |
| | | JSONArray array = sellerJson.optJSONArray("evaluates"); |
| | | for (int i = 0; i < array.size(); i++) { |
| | | JSONObject item = array.optJSONObject(i); |
| | | if ("宝贝描述".equalsIgnoreCase(item.optString("title").trim())) { |
| | | shop.setScoreGoods(new BigDecimal(item.optString("score").trim())); |
| | | shop.setScoreGoodsD(new BigDecimal(item.optString("level").trim())); |
| | | } else if ("卖家服务".equalsIgnoreCase(item.optString("title").trim())) { |
| | | shop.setScoreSeller(new BigDecimal(item.optString("score").trim())); |
| | | shop.setScoreSellerD(new BigDecimal(item.optString("level").trim())); |
| | | } else if ("物流服务".equalsIgnoreCase(item.optString("title").trim())) { |
| | | shop.setScoreLogistics(new BigDecimal(item.optString("score").trim())); |
| | | shop.setScoreLogisticsD(new BigDecimal(item.optString("level").trim())); |
| | | } |
| | | } |
| | | |
| | | shop.setSellerNick(sellerJson.optString("sellerNick")); |
| | | shop.setShopIcon("https:" + sellerJson.optString("shopIcon")); |
| | | shop.setShopId(sellerJson.optLong("shopId")); |
| | | shop.setShopName(sellerJson.optString("shopName")); |
| | | if ("B".equalsIgnoreCase(sellerJson.optString("sellerType"))) |
| | | shop.setUserType(1); |
| | | else |
| | | shop.setUserType(0); |
| | | |
| | | shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId())); |
| | | } catch (Exception e) { |
| | | // if (1 > 0) |
| | | // return null; |
| | | try { |
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.getSimpleGoodsInfo(auctionId); |
| | | shop.setId(goods.getSellerId()); |
| | | shop.setShopName(goods.getShopTitle()); |
| | | shop.setUserType(goods.getUserType()); |
| | | } catch (Exception e1) { |
| | | shop.setId(1L); |
| | | shop.setShopName(""); |
| | | shop.setUserType(0); |
| | | } |
| | | |
| | | shop.setGoodRatePercentage(new BigDecimal(100)); |
| | | shop.setScoreGoods(new BigDecimal("4.9")); |
| | | shop.setScoreGoodsD(new BigDecimal("0")); |
| | | shop.setScoreSeller(new BigDecimal("4.9")); |
| | | shop.setScoreSellerD(new BigDecimal("0")); |
| | | shop.setScoreLogistics(new BigDecimal("4.9")); |
| | | shop.setScoreLogisticsD(new BigDecimal("0")); |
| | | shop.setSellerNick(""); |
| | | shop.setShopIcon("https:"); |
| | | shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId())); |
| | | } |
| | | |
| | | return shop; |
| | | } |
| | | |
| | | /** |
| | | * 根据卖家id获取店铺链接 |
| | | * |
| | | * @param sellerId |
| | | * @return |
| | | */ |
| | | public static String getShopLink(Long sellerId) { |
| | | return "http://store.taobao.com/shop/view_shop.htm?user_number_id=" + sellerId; |
| | | } |
| | | |
| | | /** |
| | | * 是否可以加入淘礼金的预选商品库 |
| | | * |
| | | * @param goods |
| | | * @return |
| | | */ |
| | | public static boolean canAddToTLJBuyGoods(TaoBaoGoodsBrief goods) { |
| | | BigDecimal tljMoney = getShareGoodsHongBaoInfo(goods, TaoBaoConstant.OWN_BUY_WITHOUT_FANLI_RATE); |
| | | // 不能小于1块 |
| | | if (tljMoney.compareTo(new BigDecimal(1)) < 0 || tljMoney.compareTo(new BigDecimal(10)) > 0) |
| | | return false; |
| | | |
| | | // 券后价不能大于150 |
| | | if (getCouponPrice(goods).compareTo(new BigDecimal(150)) > 0) |
| | | return false; |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 查询天猫商品图片、标题 |
| | | * |
| | | * @param auctionId |
| | | * @return |
| | | */ |
| | | public static TaoBaoGoodsBrief getTmallGoodsInfo(String auctionId) { |
| | | TaoBaoGoodsBrief taoBaoGoodsBrief = null; |
| | | try { |
| | | Connection connect = Jsoup.connect(String.format(TM_PHONE_URL, auctionId)); |
| | | Document document = connect.get(); |
| | | Elements elements = document.getElementsByTag("script"); |
| | | if (elements.size() >= 0) { |
| | | for (int i = 0; i < elements.size(); i++) { |
| | | String content = elements.get(i).toString(); |
| | | if (content.contains("var _DATA_Detail")) { |
| | | content = content.replace("<script>", ""); |
| | | content = content.replace("</script>", ""); |
| | | |
| | | if (content.contains("videoDetail")) { |
| | | content += ";function getData(){ var json={title:_DATA_Detail.item.title,pictUrl:_DATA_Detail.item.images[0]}; return JSON.stringify(json);}"; |
| | | } else { |
| | | content += ";function getData(){ var json={title:_DATA_Detail.item.title,pictUrl:_DATA_Detail.item.images[0]}; return JSON.stringify(json);}"; |
| | | } |
| | | |
| | | ScriptEngineManager manager = new ScriptEngineManager(); |
| | | ScriptEngine engine = manager.getEngineByName("javascript"); |
| | | engine.eval(content); |
| | | |
| | | if (engine instanceof Invocable) { |
| | | Invocable in = (Invocable) engine; |
| | | JSONObject json = JSONObject.fromObject(in.invokeFunction("getData")); |
| | | Object title = json.get("title"); |
| | | Object pictUrl = json.get("pictUrl"); |
| | | taoBaoGoodsBrief = new TaoBaoGoodsBrief(); |
| | | taoBaoGoodsBrief.setTitle(title.toString()); |
| | | taoBaoGoodsBrief.setPictUrl(pictUrl.toString()); |
| | | if (!pictUrl.toString().startsWith("http")) { |
| | | taoBaoGoodsBrief.setPictUrl(TbImgUtil.getTBSize220Img("http:" + pictUrl.toString())); |
| | | } |
| | | } |
| | | |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return taoBaoGoodsBrief; |
| | | } |
| | | |
| | | /** |
| | | * 抖音返利local 获取真实淘宝链接 |
| | | * |
| | | * @param url https://s.click.taobao.com/t?e=m%3D2%26s% |
| | | * 3DT9DFpHQCT7Rw4vFB6t2Z2ueEDrYVVa64XoO8tOebS+dRAdhuF14FMR8 |
| | | * @return |
| | | */ |
| | | public static String getRealUrl(String url) { |
| | | if (StringUtil.isNullOrEmpty(url)) |
| | | return null; |
| | | |
| | | try { |
| | | HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager()); |
| | | client.getHttpConnectionManager().getParams().setConnectionTimeout(10000); |
| | | client.getParams().setParameter(HttpMethodParams.USER_AGENT, |
| | | "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)"); // 让服务器认为是IE |
| | | GetMethod get = new GetMethod(url); |
| | | get.setFollowRedirects(false); // 禁止自动重定向 |
| | | int iGetResultCode = client.executeMethod(get); |
| | | String location = get.getResponseHeader("location").getValue(); // 打印地址 |
| | | GetMethod get2 = new GetMethod(URLDecoder.decode(location.split("tu=")[1])); |
| | | get2.addRequestHeader("Referer", location); |
| | | get2.setFollowRedirects(false); // 禁止自动重定向 |
| | | int iGetResultCode2 = client.executeMethod(get2); |
| | | return get2.getResponseHeader("location").getValue(); // 真实地址 |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 淘口令过滤 |
| | | * |
| | | * @param token |
| | | * @return |
| | | */ |
| | | public static String filterTaoToken(String token) { |
| | | if (StringUtil.isNullOrEmpty(token)) |
| | | return token; |
| | | if (token.contains("¥") || token.contains("€")) { |
| | | String newToken = ""; |
| | | for (int i = 0; i < token.length(); i++) { |
| | | if (token.charAt(i) == '¥' || token.charAt(i) == '€') { |
| | | if (!newToken.contains("(")) |
| | | newToken += "("; |
| | | else |
| | | newToken += ")"; |
| | | } else |
| | | newToken += token.charAt(i) + ""; |
| | | } |
| | | return newToken; |
| | | } |
| | | 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; |
| | | else |
| | | return false; |
| | | } |
| | | |
| | | private final static String[] taoTokenSymbols = new String[]{"₳-₳", "¥-¥", "¥-¥", "€-€", "\\$-\\$", "₴-₴", "¢-¢", |
| | | "₤-₤"}; |
| | | |
| | | /** |
| | | * 从文本中提取淘口令 @Title: getTokenListFromText @Description: @param str @return |
| | | * List<String> 返回类型 @throws |
| | | */ |
| | | public static List<String> getTokenListFromText(String str) { |
| | | String[] marks = taoTokenSymbols; |
| | | List<String> list = new ArrayList<>(); |
| | | for (String m : marks) { |
| | | for (String m1 : marks) { |
| | | list.add(m.split("-")[0] + "-" + m1.split("-")[1]); |
| | | } |
| | | } |
| | | |
| | | return getTokenListFromText(str, list); |
| | | } |
| | | |
| | | /** |
| | | * 从文本中提取淘口令(括号的口令也算) |
| | | * |
| | | * @param str |
| | | * @return |
| | | */ |
| | | public static List<String> getTokenListFromTextWithKuoHao(String str) { |
| | | String[] marks = taoTokenSymbols; |
| | | List<String> list = new ArrayList<>(); |
| | | for (String m : marks) { |
| | | for (String m1 : marks) { |
| | | list.add(m.split("-")[0] + "-" + m1.split("-")[1]); |
| | | } |
| | | } |
| | | |
| | | list.add("\\(-\\)"); |
| | | list.add("(-)"); |
| | | return getTokenListFromText(str, list); |
| | | } |
| | | |
| | | 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.split("-")[0], st.split("-")[1])); |
| | | } |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 获取能够分的钱 |
| | | * |
| | | * @param estimate |
| | | * @return BigDecimal 返回类型 |
| | | * @throws |
| | | * @Title: getCanShareMoney |
| | | * @Description: |
| | | */ |
| | | public static BigDecimal getCanShareMoney(Date createTime, BigDecimal estimate) { |
| | | if (estimate == null) |
| | | return null; |
| | | if (createTime.getTime() < TimeUtil.convertToTimeTemp("2020-06-01 12:30:00", "yyyy-MM-dd HH:mm:ss")) { |
| | | return estimate; |
| | | } |
| | | BigDecimal rate = new BigDecimal("0.9101"); |
| | | return MoneyBigDecimalUtil.mul(estimate, rate); |
| | | } |
| | | |
| | | /** |
| | | * 拼接渠道ID |
| | | * |
| | | * @param url |
| | | * @param relationId |
| | | * @return |
| | | */ |
| | | public static String concatRelationId(String url, String relationId) { |
| | | if (StringUtil.isNullOrEmpty(url)) { |
| | | return url; |
| | | } |
| | | if (StringUtil.isNullOrEmpty(relationId)) |
| | | return url; |
| | | if (!url.contains("&relationId=")) |
| | | if(url.contains("?")) { |
| | | return url + "&relationId=" + relationId; |
| | | }else{ |
| | | return url + "?relationId=" + relationId; |
| | | } |
| | | else |
| | | return url; |
| | | } |
| | | |
| | | |
| | | //从券链接获取券ID |
| | | |
| | | /** |
| | | * 从券链接中获取券ID |
| | | * |
| | | * @param couponLink |
| | | * @return |
| | | */ |
| | | public static String getActivityIdFromCouponLink(String couponLink) { |
| | | Map<String, String> params = HttpUtil.getPramsFromUrl(couponLink); |
| | | if (params != null && params.containsKey("activityId")) |
| | | return params.get("activityId"); |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取淘宝授权链接 |
| | | * |
| | | * @param uid |
| | | * @param source |
| | | * @return |
| | | */ |
| | | public static String getTaoBaoAuthLink(Long uid, String source) { |
| | | return TaoBaoUtil.getTaoBaoUnionAuthUrl(TaoBaoConstant.TAOBAO_AUTH_APPKEY, |
| | | "http://api.flqapp.com/fanli/client/v1/auth/callback/tb", uid, source); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 是否为淘宝系的链接 |
| | | * |
| | | * @param link |
| | | * @return |
| | | */ |
| | | public static boolean isTaoBaoLink(String link) { |
| | | TaoBaoGoodsBrief tb = null; |
| | | String auctionId = null; |
| | | if (link.startsWith("https://a.m.taobao.com/i"))// 淘宝账号未登录状态 |
| | | { |
| | | return true; |
| | | } else if (link.contains("ju.taobao.com") || link.contains(".juhuasuan.com")) {// 聚划算 |
| | | return true; |
| | | } else if (link.contains("http://zmnxbc.com")) { // 手机端天猫APP分享 |
| | | return true; |
| | | } else if (link.contains("m.tb.cn") || link.contains("h5.m.taobao") || link.contains("detail.m.tmall") || link.contains("item.taobao") |
| | | || link.contains("detail.tmall")) { // 手机页面和电脑页面 |
| | | return true; |
| | | } else if (link.contains("//s.click.taobao.com")) { |
| | | return true; |
| | | } |
| | | |
| | | return false; |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 是否有新版淘口令 |
| | | * |
| | | * @param text |
| | | * @return |
| | | */ |
| | | public static boolean isHaveNewVersionTaoBaoToken(String text) { |
| | | if (text == null) |
| | | return false; |
| | | |
| | | int count = 0; |
| | | for (int i = 0; i < text.length(); i++) { |
| | | //大小写字母+数字 |
| | | if ((text.charAt(i) >= 65 && text.charAt(i) <= 90) || (text.charAt(i) >= 97 && text.charAt(i) <= 122) || (text.charAt(i) >= 48 && text.charAt(i) <= 57)) { |
| | | count++; |
| | | if (count >= 10) |
| | | return true; |
| | | } else { |
| | | count = 0; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * @return boolean |
| | | * @author hxh |
| | | * @description 判断淘宝商品ID是否相等 |
| | | * @date 14:55 2022/8/24 |
| | | * @param: auctionId1 |
| | | * @param: auctionId2 |
| | | **/ |
| | | public static boolean isEqual(String auctionId1, String auctionId2) { |
| | | if (auctionId1 == null || auctionId2 == null) { |
| | | return false; |
| | | } |
| | | |
| | | if (auctionId1.indexOf("-") > 0 && auctionId2.indexOf("-") > 0) { |
| | | return auctionId1.split("-")[1].equals(auctionId2.split("-")[1]); |
| | | } |
| | | return auctionId1.equals(auctionId2); |
| | | } |
| | | |
| | | /** |
| | | * @return java.lang.String |
| | | * @author hxh |
| | | * @description 获取商品ID的后半段 |
| | | * @date 15:20 2022/8/24 |
| | | * @param: auctionId |
| | | **/ |
| | | public static String getAuctionId(String auctionId) { |
| | | if (auctionId == null) |
| | | return auctionId; |
| | | if (auctionId.indexOf("-") > 0) { |
| | | return auctionId.split("-")[1]; |
| | | } else { |
| | | return auctionId; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @return org.springframework.data.mongodb.core.query.Criteria |
| | | * @author hxh |
| | | * @description 获取mongodb商品ID相同的条件 |
| | | * @date 16:05 2022/8/24 |
| | | * @param: key |
| | | * @param: auctionId |
| | | **/ |
| | | public static Criteria getAuctionIdEqualCriteria(String key, String auctionId) { |
| | | if (!isNewAuctionId(auctionId)) { |
| | | return Criteria.where(key).is(auctionId); |
| | | } else { |
| | | return Criteria.where(key).regex("-" + getAuctionId(auctionId)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @return boolean |
| | | * @author hxh |
| | | * @description 是否为新的商品ID |
| | | * @date 15:39 2022/8/24 |
| | | * @param: auctionId |
| | | **/ |
| | | public static boolean isNewAuctionId(String auctionId) { |
| | | if (auctionId != null && auctionId.indexOf("-") > 0) |
| | | return true; |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * @return java.lang.String |
| | | * @author hxh |
| | | * @description 获取淘宝的商品标题 |
| | | * @date 11:36 2022/9/9 |
| | | **/ |
| | | public static String getGoodsTitleFromTokenText(String text) { |
| | | String reg = "「.*」"; |
| | | Pattern p = Pattern.compile(reg); |
| | | Matcher matcher = p.matcher(text); |
| | | if (matcher.find()) { |
| | | String title = matcher.group(); |
| | | if(title!=null&&title.length()>0) { |
| | | return title.replace("「","").replace("」",""); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | // String reg = "「.*」"; |
| | | // Pattern p = Pattern.compile(reg); |
| | | // Matcher matcher = p.matcher("【淘宝】https://m.tb.cn/h.Ub3d7Kb?tk=g2Az2EmdcIX CZ3457 「造梦【蔷薇少女】复古碎花牛奶绒羊羔绒毛毯秋冬保暖休闲毯沙发毯」\n" + |
| | | // "点击链接直接打开"); |
| | | // if (matcher.find()) { |
| | | // String title = matcher.group(); |
| | | // System.out.println(title); |
| | | // } |
| | | String relationId = "1222"; |
| | | String url="http://123id=123"; |
| | | if(url.contains("?")) { |
| | | System.out.println(url + "&relationId=" + relationId); |
| | | }else{ |
| | | System.out.println(url + "?relationId=" + relationId); |
| | | } |
| | | } |
| | | |
| | | } |