Commit d7887322 by admin

转链接增加重定向

parent 38c6dcd6
...@@ -8,7 +8,10 @@ import java.io.IOException; ...@@ -8,7 +8,10 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.Socket; import java.net.Socket;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
...@@ -528,7 +531,7 @@ public class ExcelReadAndWrite { ...@@ -528,7 +531,7 @@ public class ExcelReadAndWrite {
continue; continue;
} }
} }
System.out.println("list:"+list.size()); System.out.println("list:" + list.size());
System.out.println(urls.size()); System.out.println(urls.size());
m.insert(urls);// 存储 m.insert(urls);// 存储
Thread.sleep(1000 * 80); Thread.sleep(1000 * 80);
...@@ -553,7 +556,7 @@ public class ExcelReadAndWrite { ...@@ -553,7 +556,7 @@ public class ExcelReadAndWrite {
if (null != w.getUrl() && w.getUrl().startsWith("https://mp.weixin.qq.com/s") if (null != w.getUrl() && w.getUrl().startsWith("https://mp.weixin.qq.com/s")
|| w.getUrl().startsWith("http://mp.weixin.qq.com/s")) { || w.getUrl().startsWith("http://mp.weixin.qq.com/s")) {
if (map.get(w.getUrl()) != null) { if (map.get(w.getUrl()) != null) {
w.setGetUrl(map.get(w.getUrl())); w.setGetUrl(urlRedirect(map.get(w.getUrl())));
} }
} else { } else {
if (w.getUrl() == null) { if (w.getUrl() == null) {
...@@ -636,4 +639,18 @@ public class ExcelReadAndWrite { ...@@ -636,4 +639,18 @@ public class ExcelReadAndWrite {
return list; return list;
} }
public static String urlRedirect(String url) {
String result = null;
try {
URL ul = new URL(url);
URLConnection con = ul.openConnection();
con.setRequestProperty("Host", "mp.weixin.qq.com");
con.setRequestProperty("User-Agent",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 MicroMessenger/6.5.2.501 NetType/WIFI WindowsWechat QBCore/3.43.691.400 QQBrowser/9.0.2524.400");
result=con.getHeaderField("Location");
} catch (Exception e) {
System.out.println(e.getMessage());
}
return (result == null||result.equals("")) ? url : result;
}
} }
...@@ -20,7 +20,7 @@ import com.zw.entity.NewsResult; ...@@ -20,7 +20,7 @@ import com.zw.entity.NewsResult;
import sendmail.SendMailUtil; import sendmail.SendMailUtil;
@Component //@Component
public class PushFinanceByTime extends Thread { public class PushFinanceByTime extends Thread {
private static final Log log = LogFactory.getLog(PushFinanceByTime.class); private static final Log log = LogFactory.getLog(PushFinanceByTime.class);
......
...@@ -64,7 +64,6 @@ public class ExcelUtil { ...@@ -64,7 +64,6 @@ public class ExcelUtil {
if (!tempFile.exists()) { if (!tempFile.exists()) {
tempFile.createNewFile(); tempFile.createNewFile();
} }
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
WritableWorkbook workbook = Workbook.createWorkbook(tempFile); WritableWorkbook workbook = Workbook.createWorkbook(tempFile);
WritableSheet sheet = workbook.createSheet("table1", 0); WritableSheet sheet = workbook.createSheet("table1", 0);
// 一些临时变量,用于写到excel中 // 一些临时变量,用于写到excel中
......
basefile=/home/nbzhiwei/upload/ basefile=/home/nbzhiwei/upload/
#basefile=C:/Users/Administrator/Desktop/news222.xls #basefile=C:/Users/admin/Desktop/
timefileUrl=/home/nbzhiwei/upload timefileUrl=/home/nbzhiwei/upload
#timefileUrl=C:/Users/admin/Desktop #timefileUrl=C:/Users/admin/Desktop
#host=106.14.249.240 #host=106.14.249.240
......
basefile=/home/nbzhiwei/upload/ basefile=/home/nbzhiwei/upload/
#basefile=C:/Users/Administrator/Desktop/news222.xls #basefile=C:/Users/admin/Desktop/
timefileUrl=/home/nbzhiwei/upload timefileUrl=/home/nbzhiwei/upload
#timefileUrl=C:/Users/admin/Desktop #timefileUrl=C:/Users/admin/Desktop
#host=106.14.249.240 #host=106.14.249.240
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment