From 766cb9630f1d29a2194c147c3fda1c487154d3a6 Mon Sep 17 00:00:00 2001 From: jiyeme Date: Fri, 10 Sep 2021 13:42:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20office=E6=88=90=E7=BB=A9=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/wecuit/backen/config/WecuitConfig.java | 31 +++++++++++++++++++ .../backen/controller/JszxController.java | 27 +++++++--------- .../wecuit/backen/utils/HTTP/HttpUtil2.java | 2 +- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/main/java/cn/wecuit/backen/config/WecuitConfig.java b/src/main/java/cn/wecuit/backen/config/WecuitConfig.java index dfc11ce..aee44b5 100644 --- a/src/main/java/cn/wecuit/backen/config/WecuitConfig.java +++ b/src/main/java/cn/wecuit/backen/config/WecuitConfig.java @@ -15,12 +15,43 @@ @EnableConfigurationProperties @ConfigurationProperties(prefix = "wecuit") public class WecuitConfig { + private String dataPath; + private String localhost; private Robot robot; + private AES aes; + private RSA rsa; + private OCR ocr; + private WX wx; + private QQ qq; @Data public static class Robot{ private Long id; private String pass; } + @Data + public static class AES{ + private String key; + } + @Data + public static class RSA{ + private String pri; + private String pub; + } + @Data + public static class OCR{ + private String server; + private String salt; + } + @Data + public static class WX{ + private String appid; + private String secret; + } + @Data + public static class QQ{ + private String appid; + private String secret; + } } diff --git a/src/main/java/cn/wecuit/backen/controller/JszxController.java b/src/main/java/cn/wecuit/backen/controller/JszxController.java index 5204e56..b678ed6 100644 --- a/src/main/java/cn/wecuit/backen/controller/JszxController.java +++ b/src/main/java/cn/wecuit/backen/controller/JszxController.java @@ -1,16 +1,15 @@ package cn.wecuit.backen.controller; import cn.wecuit.backen.exception.BaseException; +import cn.wecuit.backen.response.BaseResponse; import cn.wecuit.backen.utils.CCUtil; import cn.wecuit.backen.utils.HTTP.HttpUtil2; import cn.wecuit.backen.utils.HTTP.HttpUtilEntity; import cn.wecuit.backen.utils.JsonUtil; import cn.wecuit.backen.utils.RSAUtils; import org.apache.hc.core5.http.ParseException; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.ServletContext; @@ -27,9 +26,12 @@ **/ @RestController @RequestMapping("/Jszx") +@BaseResponse public class JszxController { @Resource HttpServletRequest request; + @Value("${wecuit.ocr.server}") + private String OCR_SERVER; @RequestMapping("/getCheckInListV2") public Map getCheckInListV2() throws IOException, ParseException { @@ -48,7 +50,7 @@ public Map getCheckInListV2() throws IOException, ParseException String html = resp.getBody(); Map>> checkInList = CCUtil.parseCheckInList(html); return new HashMap(){{ - put("code", 200); + put("list", checkInList); }}; } @@ -66,7 +68,6 @@ public Map loginRSAv1(@RequestBody Map uInfo) th // 响应体 Map ret = new HashMap<>(); - ret.put("code", 200); ret.put("cookie", loginCookie); return ret; } @@ -90,7 +91,6 @@ public Map getCheckInEditV2() throws IOException, ParseException String html = httpUtilEntity.getBody(); Map form = CCUtil.parseCheckInContent(html); return new HashMap(){{ - put("code", 200); put("form", form); }}; } @@ -125,7 +125,7 @@ public Map doCheckInV3(@RequestBody Map postMap) if(html.contains("提交打卡成功!")) { Map newForm = CCUtil.parseCheckInContent(html); return new HashMap(){{ - put("code", 200); + put("error", time.toString()); put("form", newForm); }}; @@ -164,7 +164,6 @@ public Map office_prepare() throws IOException, ParseException { String finalCodeKey = codeKey; String finalSyncTime = syncTime; return new HashMap(){{ - put("code", 200); put("cookie", cookie.toString()); put("codeKey", finalCodeKey); put("syncTime", finalSyncTime); @@ -172,9 +171,7 @@ public Map office_prepare() throws IOException, ParseException { } @RequestMapping("/office_getCaptcha") - public Map office_getCaptcha() throws IOException { - String cookie = request.getParameter("cookie"); - String codeKey = request.getParameter("codeKey"); + public Map office_getCaptcha(@RequestParam String cookie, @RequestParam String codeKey) throws IOException { HashMap headers = new HashMap(){{ put("cookie", cookie); @@ -183,13 +180,11 @@ public Map office_getCaptcha() throws IOException { HttpUtil2 http = new HttpUtil2(); byte[] body = http.getContent("http://login.cuit.edu.cn:81/Login/xLogin/yzmDvCode.asp?k=" + codeKey, null, headers, "UTF-8"); - ServletContext servletContext = request.getServletContext(); - String OCR_SERVER = servletContext.getInitParameter("OCR_SERVER"); String s = http.doFilePost(OCR_SERVER, body); Map map = JsonUtil.string2Obj(s, Map.class); return new HashMap(){{ - put("code", 200); + put("base64img", "data:image/png;base64, " + new String(Base64.getEncoder().encode(body))); put("imgCode", map.get("result")); }}; @@ -232,7 +227,7 @@ public Map office_query() throws IOException, ParseException { String msg = result.substring(result.lastIndexOf(">") + 1); return new HashMap(){{ - put("code", 200); + put("result", msg); }}; } diff --git a/src/main/java/cn/wecuit/backen/utils/HTTP/HttpUtil2.java b/src/main/java/cn/wecuit/backen/utils/HTTP/HttpUtil2.java index fb3060b..82c55e3 100644 --- a/src/main/java/cn/wecuit/backen/utils/HTTP/HttpUtil2.java +++ b/src/main/java/cn/wecuit/backen/utils/HTTP/HttpUtil2.java @@ -84,7 +84,7 @@ public class HttpUtil2 { // 默认配置 unBuildConfig = RequestConfig.custom().setConnectTimeout(Timeout.ofSeconds(5)) .setResponseTimeout(Timeout.ofSeconds(5)) - // .setProxy(new HttpHost("127.0.0.1", 8888)) + .setProxy(new HttpHost("127.0.0.1", 8888)) .setCircularRedirectsAllowed(true); localContext.setCookieStore(httpCookieStore); }