From c0284d7ae6d59aa1146aa5d4123ec7c4b44892da Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期一, 02 十二月 2019 14:00:31 +0800 Subject: [PATCH] 新人红包 + 品牌随机 --- utils/src/main/java/org/yeshi/utils/HttpUtil.java | 59 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 48 insertions(+), 11 deletions(-) diff --git a/utils/src/main/java/org/yeshi/utils/HttpUtil.java b/utils/src/main/java/org/yeshi/utils/HttpUtil.java index cafc9f0..8d4179b 100644 --- a/utils/src/main/java/org/yeshi/utils/HttpUtil.java +++ b/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,13 +59,13 @@ } public static String getShortLink(String url) { - return url; - // String shortLink = getShortLink3(url); - // if (StringUtil.isNullOrEmpty(shortLink)) - // shortLink = getShortLink1(url); - // if (StringUtil.isNullOrEmpty(shortLink)) - // shortLink = getShortLink2(url); - // return shortLink; + // return url; + String shortLink = getShortLink3(url); + if (StringUtil.isNullOrEmpty(shortLink)) + shortLink = getShortLink1(url); + if (StringUtil.isNullOrEmpty(shortLink)) + shortLink = getShortLink2(url); + return shortLink; } private static String getShortLink1(String url) { @@ -102,12 +101,11 @@ private static String getShortLink3(String url) { try { - String totalUrl = String.format( - "http://api.ft12.com/api.php?format=json&url=%s&apikey=Lqh4eXURkvKhbboXwz@ddd", + String totalUrl = String.format("http://h5.flq001.com/short/createShort?url=%s", URLEncoder.encode(url, "UTF-8")); String result = get(totalUrl, null); JSONObject data = JSONObject.fromObject(result); - return data.optString("url"); + return data.optString("short_url"); } catch (Exception e) { e.printStackTrace(); } @@ -475,6 +473,24 @@ } return ""; } + + @SuppressWarnings("deprecation") + public static String post(String url, String entity,String charset) { + HttpClient client = new HttpClient(); + PostMethod method = new PostMethod(url); + method.addRequestHeader("Content-Type", "text/html;charset="+charset); + method.setRequestHeader("Content-Type", "text/html;charset="+charset); + method.setRequestBody(entity); + try { + client.executeMethod(method); + return convertInputStreamToString(method.getResponseBodyAsStream()); + } catch (HttpException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return ""; + } public static String postInputStream(String url, File file) throws FileNotFoundException { HttpClient client = new HttpClient(); @@ -585,4 +601,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; + } } -- Gitblit v1.8.0