| | |
| | | return "";
|
| | | }
|
| | |
|
| | | public static String getShortLink(String url) { |
| | | public static String getShortLink(String url) {
|
| | | String shortLink = getShortLink2(url);
|
| | | if (StringUtil.isNullOrEmpty(shortLink))
|
| | | shortLink = getShortLink3(url);
|
| | |
| | | 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();
|
| | | }
|
| | |
| | | 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();
|
| | | }
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | |
| | | public static String postSimple(String url) {
|
| | | HttpClient client = new HttpClient();
|
| | | PostMethod method = new PostMethod(url);
|
| | |
| | | }
|
| | | return "";
|
| | | }
|
| | | |
| | | |
| | |
|
| | | public static String post(String url) {
|
| | | HttpClient client = new HttpClient();
|
| | | PostMethod method = new PostMethod(url);
|
| | |
| | |
|
| | | public static String post(String url, Map<String, String> map, Map<String, String> headers) {
|
| | | HttpClient client = new HttpClient();
|
| | | // client.getHostConfiguration().setProxy("192.168.1.122", 8888);
|
| | | // client.getHostConfiguration().setProxy("192.168.1.122", 8888);
|
| | | PostMethod pm = new PostMethod(url);// 创建HttpPost对象
|
| | | NameValuePair[] ns = new NameValuePair[map.keySet().size()];
|
| | | Iterator<String> its = map.keySet().iterator();
|