diff --git a/tall/src/main/java/com/ccsens/tall/web/DebugController.java b/tall/src/main/java/com/ccsens/tall/web/DebugController.java index c0637bd9..8b5a6041 100644 --- a/tall/src/main/java/com/ccsens/tall/web/DebugController.java +++ b/tall/src/main/java/com/ccsens/tall/web/DebugController.java @@ -23,6 +23,7 @@ import org.apache.ibatis.session.SqlSessionFactory; import org.junit.Test; import org.springframework.amqp.core.AmqpTemplate; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; @@ -30,6 +31,7 @@ import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @@ -55,6 +57,10 @@ public class DebugController { @Resource SqlSessionFactory sqlSessionFactory; + @Resource + private RestTemplate restTemplate; + + private static RestTemplateUtil util; @ApiOperation(value = "/测试",notes = "") @ApiImplicitParams({ @@ -297,6 +303,43 @@ public class DebugController { } catch (DocumentException e) { System.out.println(e); } + } + + + + @ApiOperation(value = "图片验证码") + @ApiImplicitParams({ + }) + @RequestMapping(value = "/https", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"}) + public void httpsTest() throws Exception { + int year = 2021; + int month = 8; + + String a = "https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query="+year+"%E5%B9%B4"+month+"%E6%9C%88&co=&resource_id=39043&t=1617089428269&ie=utf8&oe=gbk&cb=op_aladdin_callback&format=json&tn=wisetpl&cb=jQuery110203576901702188473_1617089118772&_=1617089118776"; +// long a1 = System.currentTimeMillis(); + String s = RestTemplateUtil.getForEntity(a,new HashMap<>(),StringBuilder.class).toString(); + System.out.println(s.toString()); +// String s = HttpsUtil.httpsRequest(a,"GET",""); +// System.out.println(System.currentTimeMillis() - a1); + + s = s.substring(s.indexOf("(")); + s = s.substring(1, s.length() - 2); + Map map = (Map) JSONObject.parse(s); + + List list = (List) map.get("data"); + Map data = (Map) list.get(0); + List almanac = (List) data.get("almanac"); + if(almanac == null || almanac.size() == 0) { + return; + } + for(int i = 1; i < almanac.size(); i++) { + String key = ((String)almanac.get(i).get("oDate")).substring(0, 10); + String status = (String)almanac.get(i - 1).get("status"); + if("1".equals(status) || "2".equals(status)) { + System.out.println(key); + System.out.println(status); + } + } } } diff --git a/tcm/src/main/java/com/ccsens/tcm/TcmApplication.java b/tcm/src/main/java/com/ccsens/tcm/TcmApplication.java index f54f95ec..eee1d6ea 100644 --- a/tcm/src/main/java/com/ccsens/tcm/TcmApplication.java +++ b/tcm/src/main/java/com/ccsens/tcm/TcmApplication.java @@ -15,6 +15,7 @@ import org.springframework.scheduling.annotation.EnableAsync; @EnableCircuitBreaker @EnableFeignClients(basePackages = "com.ccsens.cloudutil.feign") @SpringBootApplication(scanBasePackages = "com.ccsens") + public class TcmApplication { public static void main(String[] args) { diff --git a/util/src/main/java/com/ccsens/util/RestTemplateUtil.java b/util/src/main/java/com/ccsens/util/RestTemplateUtil.java index 89ad9df5..dd840609 100644 --- a/util/src/main/java/com/ccsens/util/RestTemplateUtil.java +++ b/util/src/main/java/com/ccsens/util/RestTemplateUtil.java @@ -60,6 +60,7 @@ public class RestTemplateUtil { log.info("url:{}, params:{}", url, params); ResponseEntity entity = util.restTemplate.getForEntity(url, String.class); log.info("entity:{}",entity); +// return entity; return JSONObject.parseObject(entity.getBody(), returnClass); } diff --git a/util/src/test/java/com/ccsens/util/DateTest.java b/util/src/test/java/com/ccsens/util/DateTest.java new file mode 100644 index 00000000..6121da45 --- /dev/null +++ b/util/src/test/java/com/ccsens/util/DateTest.java @@ -0,0 +1,95 @@ +package com.ccsens.util; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.util.*; + +import com.alibaba.fastjson.JSONObject; + +public class DateTest { + + public static String sendGet(String url, String param) { + String result = ""; + BufferedReader in = null; + try { + String urlNameString = url + "/" + param; + URL realUrl = new URL(urlNameString); + URLConnection connection = realUrl.openConnection(); + connection.setRequestProperty("accept", "*/*"); + connection.setRequestProperty("connection", "Keep-Alive"); + connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); + connection.connect(); + in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String line; + int cot = 0; + while ((line = in.readLine()) != null) { + result += line; + } + } catch (Exception e) { + System.out.println("发送GET请求出现异常!" + e); + e.printStackTrace(); + } + finally { + try { + if (in != null) { + in.close(); + } + } catch (Exception e2) { + e2.printStackTrace(); + } + } + return result; + } + + static Map totalMap = new TreeMap(); + + public static void main(String[] args) throws Exception { + + int startYear = 2021;//开始的年份 + int year = 8; //统计的年份 + loop(startYear + 2021 + "", 8 + ""); +// for(int i = 0; i <= (year - 1); i++){ +//// for(int j = 1; j <= 12; j++) { +// loop(startYear + i + "", j + ""); +//// } +// } + + Iterator it = totalMap.keySet().iterator(); + while(it.hasNext()) { + String temp = (String) it.next(); + System.out.println(temp + " " + totalMap.get(temp)); + } + + } + + public static void loop(String year, String month) throws Exception { + String s = DateTest.sendGet("https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query="+year+"%E5%B9%B4"+month+"%E6%9C%88&co=&resource_id=39043&t=1617089428269&ie=utf8&oe=gbk&cb=op_aladdin_callback&format=json&tn=wisetpl&cb=jQuery110203576901702188473_1617089118772&_=1617089118776", ""); + +// String a = "https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query="+year+"%E5%B9%B4"+month+"%E6%9C%88&co=&resource_id=39043&t=1617089428269&ie=utf8&oe=gbk&cb=op_aladdin_callback&format=json&tn=wisetpl&cb=jQuery110203576901702188473_1617089118772&_=1617089118776"; +// long a1 = System.currentTimeMillis(); +// RestTemplateUtil.getForEntity(a,new HashMap<>(),StringBuilder.class); +//// String s = HttpsUtil.httpsRequest(a,"GET",""); +// System.out.println(System.currentTimeMillis() - a1); + + s = s.substring(s.indexOf("(")); + s = s.substring(1, s.length() - 2); + Map map = (Map) JSONObject.parse(s); + + List list = (List) map.get("data"); + Map data = (Map) list.get(0); + List almanac = (List) data.get("almanac"); + if(almanac == null || almanac.size() == 0) { + return; + } + + for(int i = 1; i < almanac.size(); i++) { + String key = ((String)almanac.get(i).get("oDate")).substring(0, 10); + String status = (String)almanac.get(i - 1).get("status"); + if("1".equals(status) || "2".equals(status)) { + totalMap.put(key, status); + } + } + + } +} \ No newline at end of file diff --git a/util/src/test/java/com/ccsens/util/OtherTest.java b/util/src/test/java/com/ccsens/util/OtherTest.java index a55aa1e0..2043e272 100644 --- a/util/src/test/java/com/ccsens/util/OtherTest.java +++ b/util/src/test/java/com/ccsens/util/OtherTest.java @@ -14,6 +14,8 @@ import javax.annotation.Resource; import javax.script.ScriptException; import java.io.*; import java.math.BigDecimal; +import java.net.HttpURLConnection; +import java.net.URL; import java.text.SimpleDateFormat; import java.util.*; import java.util.regex.Matcher; @@ -25,6 +27,42 @@ public class OtherTest { public static final String REGEX_PHONE = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,1-9]))\\d{8}$"; + @Test + public void test15() { + String httpArg = "20211001"; + + String httpUrl = "http://api.goseek.cn/Tools/holiday"; + BufferedReader reader = null; + String result = null; + StringBuffer sbf = new StringBuffer(); + httpUrl = httpUrl + "?date=" + httpArg; + + int d=0;//工作日对应结果为 0, 休息日对应结果为 1, 节假日对应的结果为 2 + + try { + URL url = new URL(httpUrl); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.connect(); + InputStream is = connection.getInputStream(); + reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); + String strRead = null; + while ((strRead = reader.readLine()) != null) { + sbf.append(strRead); + sbf.append("\r\n"); + } + reader.close(); + result = sbf.toString(); +// JSONObject ob= JSONObject.fromObject(result); +// if(ob!=null){ +// d=Integer.parseInt(ob.getString("data")); +// } + + } catch (Exception e) { + e.printStackTrace(); + } + } + @Test public void test2() throws ScriptException { String str = "18200000000";