From 565c0a03a299de5a619f4d5b5fe593e46dbf35dd Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期三, 28 八月 2019 15:07:58 +0800
Subject: [PATCH] Merge branch 'div' of ssh://193.112.35.168:29418/fanli-server into div

---
 utils/src/main/java/org/yeshi/utils/HttpUtil.java |   38 ++++++++++++++++++++------------------
 1 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/utils/src/main/java/org/yeshi/utils/HttpUtil.java b/utils/src/main/java/org/yeshi/utils/HttpUtil.java
index ad48ffa..f1cc3bd 100644
--- a/utils/src/main/java/org/yeshi/utils/HttpUtil.java
+++ b/utils/src/main/java/org/yeshi/utils/HttpUtil.java
@@ -9,9 +9,7 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLEncoder;
-import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.httpclient.Header;
@@ -31,7 +29,6 @@
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.CredentialsProvider;
 import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.impl.client.BasicCredentialsProvider;
@@ -42,7 +39,6 @@
 
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
-import sun.rmi.log.LogHandler;
 
 public class HttpUtil {
 
@@ -80,15 +76,11 @@
 	private static String getShortLink2(String url) {
 		try {
 			String totalUrl = String.format(
-					"https://api.weibo.com/2/short_url/shorten.json?source=3403499693&url_long=%s",
+					"http://api.t.sina.com.cn/short_url/shorten.json?source=3403499693&url_long=%s",
 					URLEncoder.encode(url));
 			String result = get(totalUrl, null);
-			JSONObject data = JSONObject.fromObject(result);
-			JSONArray array = data.optJSONArray("urls");
-			data = array.optJSONObject(0);
-			String shortUrl = data.optString("url_short");
-			if (!StringUtil.isNullOrEmpty(shortUrl))
-				return shortUrl;
+			JSONObject data = JSONArray.fromObject(result).optJSONObject(0);
+			return data.optString("url_short");
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
@@ -98,15 +90,11 @@
 	private static String getShortLink3(String url) {
 		try {
 			String totalUrl = String.format(
-					"https://api.weibo.com/2/short_url/shorten.json?source=2963429064&url_long=%s",
+					"http://api.t.sina.com.cn/short_url/shorten.json?source=2963429064&url_long=%s",
 					URLEncoder.encode(url));
 			String result = get(totalUrl, null);
-			JSONObject data = JSONObject.fromObject(result);
-			JSONArray array = data.optJSONArray("urls");
-			data = array.optJSONObject(0);
-			String shortUrl = data.optString("url_short");
-			if (!StringUtil.isNullOrEmpty(shortUrl))
-				return shortUrl;
+			JSONObject data = JSONArray.fromObject(result).optJSONObject(0);
+			return data.optString("url_short");
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
@@ -325,6 +313,20 @@
 		return null;
 	}
 
+	public static String postSimple(String url) {
+		HttpClient client = new HttpClient();
+		PostMethod method = new PostMethod(url);
+		try {
+			client.executeMethod(method);
+			return method.getResponseBodyAsString();
+		} catch (HttpException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return "";
+	}
+
 	public static String post(String url) {
 		HttpClient client = new HttpClient();
 		PostMethod method = new PostMethod(url);

--
Gitblit v1.8.0