admin
2019-11-07 235a867e15a86c3666c3e57727a7d6bb828e08de
utils/src/main/java/org/yeshi/utils/HttpUtil.java
@@ -44,7 +44,6 @@
import org.apache.http.util.EntityUtils;
import org.yeshi.utils.entity.ProxyIP;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class HttpUtil {
@@ -60,11 +59,12 @@
   }
   public static String getShortLink(String url) {
      String shortLink = getShortLink2(url);
      if (StringUtil.isNullOrEmpty(shortLink))
         shortLink = getShortLink3(url);
      // return url;
      String shortLink = getShortLink3(url);
      if (StringUtil.isNullOrEmpty(shortLink))
         shortLink = getShortLink1(url);
      if (StringUtil.isNullOrEmpty(shortLink))
         shortLink = getShortLink2(url);
      return shortLink;
   }
@@ -72,7 +72,7 @@
      try {
         String totalUrl = String.format(
               "http://suo.im/api.htm?format=json&url=%s&key=5d7728078e676d45275f816b@681bb0446f1e6af4f8fc6ce3cad2a684",
            URLEncoder.encode(url));
               URLEncoder.encode(url));
         String result = get(totalUrl, null);
         System.out.println(result);
         try {
@@ -85,15 +85,14 @@
      return null;
   }
   // 搜狐网址
   private static String getShortLink2(String url) {
      try {
         String totalUrl = String.format(
               "http://api.t.sina.com.cn/short_url/shorten.json?source=2849184197&url_long=%s", // 3403499693
               URLEncoder.encode(url));
         String totalUrl = String.format("https://sohu.gg/api/?key=2zumZxsL8MuX&url=%s",
               URLEncoder.encode(url, "UTF-8"));
         String result = get(totalUrl, null);
         System.out.println(result);
         JSONObject data = JSONArray.fromObject(result).optJSONObject(0);
         return data.optString("url_short");
         if (result != null && result.startsWith("http"))
            return result;
      } catch (Exception e) {
         e.printStackTrace();
      }
@@ -102,12 +101,11 @@
   private static String getShortLink3(String url) {
      try {
         String totalUrl = String.format(
               "http://api.t.sina.com.cn/short_url/shorten.json?source=2963429064&url_long=%s",
               URLEncoder.encode(url));
         String totalUrl = String.format("http://h5.flq001.com/short/createShort?url=%s",
               URLEncoder.encode(url, "UTF-8"));
         String result = get(totalUrl, null);
         JSONObject data = JSONArray.fromObject(result).optJSONObject(0);
         return data.optString("url_short");
         JSONObject data = JSONObject.fromObject(result);
         return data.optString("short_url");
      } catch (Exception e) {
         e.printStackTrace();
      }
@@ -585,4 +583,25 @@
      return result;
   }
   /**
    * 获取post返回location
    * @param url
    * @return
    */
   public static String getLocation(String url) {
      HttpClient client = new HttpClient();
      PostMethod method = new PostMethod(url);
      try {
         client.executeMethod(method);
            return method.getResponseHeader("location").getValue();
      } catch (HttpException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
      return null;
   }
}