| | |
| | | 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 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 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.hongbao.HongBaoManageService;
|
| | | 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;
|
| | |
| | | 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) {
|
| | |
|
| | |
| | | // labels.add(new ClientTextStyleVO("标签内容", "#00FF00"));
|
| | | // tg.setLabels(labels);
|
| | | // }
|
| | | return tg;
|
| | | return loadYuShouInfo(tg, tb);
|
| | | }
|
| | |
|
| | | private static TaoBaoGoodsBriefExtra loadYuShouInfo(TaoBaoGoodsBriefExtra extra, TaoBaoGoodsBrief goods) {
|
| | | if (goods != null && extra != null) {
|
| | | if (isYUShou(goods)) {// 预售商品
|
| | | // extra.setZkPrice(new BigDecimal(goods.getPresaleDeposit()));
|
| | | // 预售
|
| | | if (extra.getLabels() == null)
|
| | | extra.setLabels(new ArrayList<>());
|
| | | extra.getLabels().add(new ClientTextStyleVO("预售", "#FF2B4E"));
|
| | | }
|
| | | }
|
| | | return extra;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 是否为预售商品
|
| | | * |
| | | * @param goods
|
| | | * @return
|
| | | */
|
| | | public static boolean isYUShou(TaoBaoGoodsBrief goods) {
|
| | | if (!StringUtil.isNullOrEmpty(goods.getPresaleDeposit())
|
| | | && !StringUtil.isNullOrEmpty(goods.getPresaleStartTime())
|
| | | && !StringUtil.isNullOrEmpty(goods.getPresaleEndTime())) {
|
| | | long startTime = Long.parseLong(goods.getPresaleStartTime());
|
| | | long endTime = Long.parseLong(goods.getPresaleEndTime());
|
| | | long now = System.currentTimeMillis();
|
| | | if (now >= startTime && now < endTime) {
|
| | | return true;
|
| | | }
|
| | | }
|
| | |
|
| | | return false;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | return 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;
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取商品的用户分成比例
|
| | | *
|
| | |
| | | */
|
| | | public static BigDecimal getGoodsHongBaoMoney(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) {
|
| | | BigDecimal money = null;
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo())
|
| | | || goodsBrief.getCouponInfo().trim().equalsIgnoreCase("无")) {
|
| | | money = MoneyBigDecimalUtil.mul(
|
| | |
| | | MoneyBigDecimalUtil.getWithNoZera(detail.getQuanPrice())));
|
| | | taoBaoGoods.setCouponLeftCount(detail.getQuanSurplus());
|
| | | taoBaoGoods.setCouponStartFee(new BigDecimal(detail.getQuanCondition()));
|
| | | taoBaoGoods.setCouponTotalCount(detail.getQuanSurplus());
|
| | | if (detail.getQuanReceive() != null)
|
| | | taoBaoGoods.setCouponTotalCount(detail.getQuanSurplus() + detail.getQuanReceive());
|
| | | taoBaoGoods.setPictUrl(detail.getPic());
|
| | | taoBaoGoods.setPictUrlWhite(detail.getPic());
|
| | | taoBaoGoods.setSellerId(detail.getSellerId());
|
| | |
| | | return url;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取淘宝的商品详情
|
| | | * |
| | | * @param actionId
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoGoodsBrief getSimpleGoodsBrief(Long actionId) {
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("itemNumId", actionId + "");
|
| | |
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | String result = HttpUtil.get(url);
|
| | | 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.setAuctionId(item.optLong("itemId"));
|
| | | goods.setTitle(item.optString("title"));
|
| | | if (item.optJSONArray("images") != null && item.optJSONArray("images").size() > 0) {
|
| | | String picture = item.optJSONArray("images").optString(0);
|
| | | goods.setPictUrl(picture.startsWith("http") ? picture : "https:" + picture);
|
| | | if (data != null) {
|
| | | JSONObject item = data.optJSONObject("item");
|
| | | if (item != null) {
|
| | | JSONObject seller = data.optJSONObject("seller");
|
| | | TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
|
| | | goods.setTitle(item.optString("title"));
|
| | | goods.setAuctionId(item.optLong("itemId"));
|
| | | goods.setTitle(item.optString("title"));
|
| | | if (item.optJSONArray("images") != null && item.optJSONArray("images").size() > 0) {
|
| | | String picture = item.optJSONArray("images").optString(0);
|
| | | goods.setPictUrl(picture.startsWith("http") ? picture : "https:" + picture);
|
| | | }
|
| | | if (seller != null) {
|
| | | goods.setSellerId(seller.optLong("shopId"));
|
| | | String shopType = seller.optString("shopType");
|
| | | if ("B".equalsIgnoreCase(shopType)) {
|
| | | goods.setUserType(1);
|
| | | } else
|
| | | goods.setUserType(0);
|
| | | goods.setShopTitle(seller.optString("shopName"));
|
| | | }
|
| | | return goods;
|
| | | }
|
| | | }
|
| | | goods.setSellerId(seller.optLong("shopId"));
|
| | | String shopType = seller.optString("shopType");
|
| | | if ("B".equalsIgnoreCase(shopType)) {
|
| | | goods.setUserType(1);
|
| | | } else
|
| | | goods.setUserType(0);
|
| | |
|
| | | goods.setShopTitle(seller.optString("shopName"));
|
| | | return goods;
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
| | | return "http://store.taobao.com/shop/view_shop.htm?user_number_id=" + sellerId;
|
| | | }
|
| | |
|
| | | public static void main(String[] args) {
|
| | | String s = channelMap.get("3");
|
| | | System.out.println(s);
|
| | | /**
|
| | | * 是否可以加入淘礼金的预选商品库
|
| | | * |
| | | * @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;
|
| | | }
|
| | |
|
| | | }
|