yujian
2019-10-09 481da0ca0ac931f6ff35dbb8d70d4450d4252c17
fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java
@@ -3,6 +3,7 @@
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;
@@ -21,7 +22,9 @@
import javax.xml.parsers.DocumentBuilderFactory;
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;
@@ -1963,5 +1966,36 @@
      }
      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;
   }
}