diff --git a/mywust-core/pom.xml b/mywust-core/pom.xml index 88eb960..ad249d9 100644 --- a/mywust-core/pom.xml +++ b/mywust-core/pom.xml @@ -55,6 +55,18 @@ 0.0.1-dev compile + + com.fasterxml.jackson.core + jackson-annotations + 2.14.0-rc1 + compile + + + com.fasterxml.jackson.core + jackson-databind + 2.14.0-rc1 + compile + diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/api/Graduate.java b/mywust-core/src/main/java/cn/linghang/mywust/core/api/Graduate.java index 1e30ecc..8b64c05 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/api/Graduate.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/api/Graduate.java @@ -4,6 +4,8 @@ public class Graduate { public static final String GRADUATE_CAPTCHA_API = "http://59.68.177.189/pyxx/PageTemplate/NsoftPage/yzm/createyzm.aspx"; public static final String GRADUATE_LOGIN_API = "http://59.68.177.189/pyxx/login.aspx"; + public static final String GRADUATE_INDEX_TEST_API = "http://59.68.177.189/pyxx/Default.aspx"; + public static final String GRADUATE_STUDENT_INFO_API = "http://59.68.177.189/pyxx/grgl/student_info1.aspx"; public static final String GRADUATE_COURSE_TABLE_API = "http://59.68.177.189/pyxx/pygl/kbcx_xs.aspx"; public static final String GRADUATE_SCORE_API = "http://59.68.177.189/pyxx/grgl/xskccjcx.aspx"; diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/api/Library.java b/mywust-core/src/main/java/cn/linghang/mywust/core/api/Library.java index fa31aca..c55bb29 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/api/Library.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/api/Library.java @@ -6,4 +6,10 @@ public class Library { public static final String LIBRARY_INDEX_URL = "https://libsys.wust.edu.cn/meta-local/opac/cas/rosetta"; public static final String LIBRARY_COOKIE_TEST_URL = "https://libsys.wust.edu.cn/meta-local/opac/users/info"; + + public static final String LIBRARY_CURRENT_LOAN_API = "https://libsys.wust.edu.cn/meta-local/opac/users/loans"; + public static final String LIBRARY_LOAN_HISTORY_API = "https://libsys.wust.edu.cn/meta-local/opac/users/loan_hists"; + public static final String LIBRARY_OVERDUE_SOON_API = "https://libsys.wust.edu.cn/meta-local/opac/users/overdue_soon"; + + public static final String LIBRARY_SEARCH_API = "https://libsys.wust.edu.cn/meta-local/opac/search/"; } diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/api/PhysicsSystem.java b/mywust-core/src/main/java/cn/linghang/mywust/core/api/PhysicsSystem.java index 874a82c..398084c 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/api/PhysicsSystem.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/api/PhysicsSystem.java @@ -6,4 +6,9 @@ public class PhysicsSystem { public static final String PHYSICS_LOGIN_COOKIES_API = "http://wlsy.wust.edu.cn/Page/BI/BI000.aspx"; public static final String PHYSICS_MAIN_INDEX_URL = "http://wlsy.wust.edu.cn/Page/BI/BI0000.aspx"; + + public static final String PHYSICS_SYSTEM_INDEX_URL = "http://wlsy.wust.edu.cn:7101/Page/PEE/PEECM/PEECM0001.aspx"; + + public static final String PHYSICS_COURSE_INDEX_URL = "http://wlsy.wust.edu.cn:7101/Page/PEE/PEECM/PEECM0001.aspx?flag=1&&action=PEE110101&&moduleId=PEE11"; + public static final String PHYSICS_COURSE_API = "http://wlsy.wust.edu.cn:7101/Page/PEE/PEECM/PEECM0001.aspx?action=PEE110301&&parentId=PEE11"; } diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/api/UnionAuth.java b/mywust-core/src/main/java/cn/linghang/mywust/core/api/UnionAuth.java index bd869a0..fdf42cf 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/api/UnionAuth.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/api/UnionAuth.java @@ -7,9 +7,10 @@ public class UnionAuth { public static final String UNION_AUTH_API = "https://auth.wust.edu.cn/lyuapServer/v1/tickets"; public static class Service { - public static final String LIBRARY_SSO_SERVICE = "https://libsys.wust.edu.cn:443/meta-local/opac/cas/rosetta"; public static final String BKJX_SSO_SERVICE = "http://bkjx.wust.edu.cn/jsxsd/sso.jsp"; + + public static final String PORTAL_SSO_SERVICE = "https://portal.wust.edu.cn/c/portal/login?redirect=%2F&p_l_id=121585"; } } diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/exception/ApiException.java b/mywust-core/src/main/java/cn/linghang/mywust/core/exception/ApiException.java index 5fdc692..d09aab3 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/exception/ApiException.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/exception/ApiException.java @@ -1,38 +1,105 @@ package cn.linghang.mywust.core.exception; public class ApiException extends BasicException { - private final int code; + private final Code code; - public ApiException(int code) { + public ApiException(Code code) { this.code = code; } - public ApiException(int code, String message) { + public ApiException(Code code, String message) { super(message); this.code = code; } - public int getCode() { + public Code getCode() { return code; } + public int getCodeValue() { + return code.value; + } + + public String getCodeDescribe() { + return code.describe; + } + @Override public String toString() { return "接口调用异常: " + code; } - public static class ApiExceptionCode { - // 统一认证的异常 - public static final int UNI_LOGIN_PASSWORD_WRONG = 100101; - public static final int UNI_LOGIN_USER_NOT_EXISTS = 100102; - public static final int UNI_LOGIN_USER_BANNED = 100103; + public enum Code { + /** + * 未知的API异常 + */ + UNKNOWN_EXCEPTION(-1, "未知错误(开发又有活干啦)"), + + // -------------------------------- + // 统一认证的异常(本科生、图书馆) + /** + * 密码错误 + */ + UNI_LOGIN_PASSWORD_WRONG(100100, "统一认证登录: 密码错误"), + + /** + * 用户不存在 + */ + UNI_LOGIN_USER_NOT_EXISTS(100101, "统一认证登录: 用户不存在"), + + /** + * 用户登录被封禁 + */ + UNI_LOGIN_USER_BANNED(100102, "统一认证登录: 用户被封禁"), + + // -------------------------------- // 共有异常码:cookie无效 - // 放一起了 - public static final int BKJX_COOKIE_INVALID = 110101; - public static final int LIBRARY_COOKIE_INVALID = 12101; - public static final int PHYSICS_COOKIE_INVALID = 130101; - public static final int GRADE_COOKIE_INVALID = 140101; - } + /** + * Cookie无效 + */ + COOKIE_INVALID(100101, "Cookie无效"), + + // -------------------------------- + // 本科生API异常代码 + + /** + * 需要评教 + */ + BKJX_COURSE_NEED_EVALUATE(110102, "需要评教"), + + // -------------------------------- + // 物理实验系统API异常代码 + + /** + * 物理实验系统密码错误 + */ + PHYSICS_PASSWORD_WRONG(130100, "物理实验系统登录: 密码错误"), + + // -------------------------------- + // 研究生API异常代码 + + /** + * 研究生密码错误 + */ + GRADUATE_PASSWORD_WRONG(140100, "研究生登录: 密码错误"), + ; + + // -------------------------------- + // 图书馆API异常代码 + + private final int value; + private final String describe; + + Code(int value, String describe) { + this.value = value; + this.describe = describe; + } + + @Override + public String toString() { + return String.format("%s(%d)", describe, value); + } + } } \ No newline at end of file diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/exception/CookieInvalidException.java b/mywust-core/src/main/java/cn/linghang/mywust/core/exception/CookieInvalidException.java deleted file mode 100644 index 0ef5ef3..0000000 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/exception/CookieInvalidException.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.linghang.mywust.core.exception; - -public class CookieInvalidException extends BasicException { - public CookieInvalidException() { - } - - public CookieInvalidException(String message) { - super(message); - } - - public CookieInvalidException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/exception/PasswordWornException.java b/mywust-core/src/main/java/cn/linghang/mywust/core/exception/PasswordWornException.java deleted file mode 100644 index 4afe61b..0000000 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/exception/PasswordWornException.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.linghang.mywust.core.exception; - -public class PasswordWornException extends BasicException { - public PasswordWornException() { - } - - public PasswordWornException(String message) { - super(message); - } - - public PasswordWornException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateCourseTableParser.java b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/graduate/GraduateCourseTableParser.java similarity index 98% rename from mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateCourseTableParser.java rename to mywust-core/src/main/java/cn/linghang/mywust/core/parser/graduate/GraduateCourseTableParser.java index f59002d..c2a7774 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateCourseTableParser.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/graduate/GraduateCourseTableParser.java @@ -1,4 +1,4 @@ -package cn.linghang.mywust.core.parser.postgraduate; +package cn.linghang.mywust.core.parser.graduate; import cn.linghang.mywust.core.exception.ParseException; import cn.linghang.mywust.core.parser.Parser; diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateExamInfoParser.java b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/graduate/GraduateExamInfoParser.java similarity index 96% rename from mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateExamInfoParser.java rename to mywust-core/src/main/java/cn/linghang/mywust/core/parser/graduate/GraduateExamInfoParser.java index d37b16d..586066f 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateExamInfoParser.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/graduate/GraduateExamInfoParser.java @@ -1,4 +1,4 @@ -package cn.linghang.mywust.core.parser.postgraduate; +package cn.linghang.mywust.core.parser.graduate; import cn.linghang.mywust.core.exception.ParseException; import cn.linghang.mywust.core.parser.Parser; diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateStudentInfoPageParser.java b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/graduate/GraduateStudentInfoPageParser.java similarity index 97% rename from mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateStudentInfoPageParser.java rename to mywust-core/src/main/java/cn/linghang/mywust/core/parser/graduate/GraduateStudentInfoPageParser.java index 9e17ba7..6bacaf5 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateStudentInfoPageParser.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/graduate/GraduateStudentInfoPageParser.java @@ -1,4 +1,4 @@ -package cn.linghang.mywust.core.parser.postgraduate; +package cn.linghang.mywust.core.parser.graduate; import cn.linghang.mywust.core.exception.ParseException; import cn.linghang.mywust.core.parser.Parser; diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateTrainingPlanPageParser.java b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/graduate/GraduateTrainingPlanPageParser.java similarity index 96% rename from mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateTrainingPlanPageParser.java rename to mywust-core/src/main/java/cn/linghang/mywust/core/parser/graduate/GraduateTrainingPlanPageParser.java index 2dc4988..201a93a 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateTrainingPlanPageParser.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/graduate/GraduateTrainingPlanPageParser.java @@ -1,4 +1,4 @@ -package cn.linghang.mywust.core.parser.postgraduate; +package cn.linghang.mywust.core.parser.graduate; import cn.linghang.mywust.core.exception.ParseException; import cn.linghang.mywust.core.parser.Parser; diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/physics/PhysicsCoursePageParser.java b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/physics/PhysicsCoursePageParser.java index c18b16a..444b1e1 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/physics/PhysicsCoursePageParser.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/physics/PhysicsCoursePageParser.java @@ -3,10 +3,8 @@ package cn.linghang.mywust.core.parser.physics; import cn.linghang.mywust.core.exception.ParseException; import cn.linghang.mywust.core.parser.HuangjiahuClassroomNameParser; import cn.linghang.mywust.core.parser.Parser; -import cn.linghang.mywust.core.parser.physics.xpath.PhysicsCourseXpath; -import cn.linghang.mywust.model.physics.PhysicsCourse; import cn.linghang.mywust.model.global.ClassRoom; -import cn.linghang.mywust.model.global.Course; +import cn.linghang.mywust.model.physics.PhysicsCourse; import org.jsoup.Jsoup; import org.jsoup.select.Elements; @@ -83,3 +81,15 @@ public class PhysicsCoursePageParser implements Parser> { return courses; } } + +final class PhysicsCourseXpath { + /** + * 用于获取表格中所有行的xpath + * */ + public static final String COURSE_ROWS_XPATH = "//*[@id=\"ID_PEE110301_gvpee120101\"]/tbody/tr"; + + public static final String COURSE_ROW_NAME_XPATH = ""; + public static final String COURSE_ROW_TEACHER_XPATH = ""; + public static final String COURSE_ROW_TIME_XPATH = ""; + public static final String COURSE_ROW_CLASSROOM_XPATH = ""; +} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/physics/PhysicsIndexPageParser.java b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/physics/PhysicsIndexPageParser.java index a6dc159..9fc6b46 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/physics/PhysicsIndexPageParser.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/physics/PhysicsIndexPageParser.java @@ -2,7 +2,6 @@ package cn.linghang.mywust.core.parser.physics; import cn.linghang.mywust.core.exception.ParseException; import cn.linghang.mywust.core.parser.Parser; -import cn.linghang.mywust.core.parser.physics.xpath.PhysicsIndexXpath; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; @@ -18,3 +17,8 @@ public class PhysicsIndexPageParser implements Parser { return linkElements.get(0).attr("href"); } } + +final class PhysicsIndexXpath { + public static final String PHYSICS_LINK_XPATH = "//*[@id=\"rolemenu\"]/tbody/tr[1]/td[1]/a[2]"; +} + diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/physics/xpath/PhysicsCourseXpath.java b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/physics/xpath/PhysicsCourseXpath.java deleted file mode 100644 index fcc9fdf..0000000 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/physics/xpath/PhysicsCourseXpath.java +++ /dev/null @@ -1,13 +0,0 @@ -package cn.linghang.mywust.core.parser.physics.xpath; - -public class PhysicsCourseXpath { - /** - * 用于获取表格中所有行的xpath - * */ - public static final String COURSE_ROWS_XPATH = "//*[@id=\"ID_PEE110301_gvpee120101\"]/tbody/tr"; - - public static final String COURSE_ROW_NAME_XPATH = ""; - public static final String COURSE_ROW_TEACHER_XPATH = ""; - public static final String COURSE_ROW_TIME_XPATH = ""; - public static final String COURSE_ROW_CLASSROOM_XPATH = ""; -} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/physics/xpath/PhysicsIndexXpath.java b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/physics/xpath/PhysicsIndexXpath.java deleted file mode 100644 index da3ec34..0000000 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/physics/xpath/PhysicsIndexXpath.java +++ /dev/null @@ -1,5 +0,0 @@ -package cn.linghang.mywust.core.parser.physics.xpath; - -public class PhysicsIndexXpath { - public static final String PHYSICS_LINK_XPATH = "//*[@id=\"rolemenu\"]/tbody/tr[1]/td[1]/a[2]"; -} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/ExamInfoParser.java b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/ExamInfoParser.java index a706492..681cadf 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/ExamInfoParser.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/ExamInfoParser.java @@ -2,7 +2,6 @@ package cn.linghang.mywust.core.parser.undergraduate; import cn.linghang.mywust.core.exception.ParseException; import cn.linghang.mywust.core.parser.Parser; -import cn.linghang.mywust.core.parser.undergraduate.xpath.ExamInfoXpath; import cn.linghang.mywust.core.util.JsoupUtil; import cn.linghang.mywust.model.global.ExamInfo; import org.jsoup.Jsoup; @@ -67,3 +66,7 @@ public class ExamInfoParser implements Parser> { return examInfos; } } + +final class ExamInfoXpath { + public static final String EXAM_INFO_ROWS_XPATH = "//*[@id=\"dataList\"]/tbody/tr"; +} \ No newline at end of file diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/StudentInfoPageParser.java b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/StudentInfoPageParser.java index a6196eb..cc014fd 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/StudentInfoPageParser.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/StudentInfoPageParser.java @@ -2,7 +2,6 @@ package cn.linghang.mywust.core.parser.undergraduate; import cn.linghang.mywust.core.exception.ParseException; import cn.linghang.mywust.core.parser.Parser; -import cn.linghang.mywust.core.parser.undergraduate.xpath.StudentInfoXpath; import cn.linghang.mywust.model.global.StudentInfo; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; @@ -61,4 +60,35 @@ public class StudentInfoPageParser implements Parser { .idNumber(idNumber) .build(); } + + } +/** + *

本科生学生信息接口用到的xpath

+ *

看着挺唬人的,其实直接浏览器选择元素复制xpath就行了

+ *

这里的xpath只要网站UI不整什么花活就不会出问题

+ * + * @author lensfrex + * @create 2022-10-22 22:16 + */ +final class StudentInfoXpath { + public static final String STUDENT_NUMBER = "//*[@id=\"xjkpTable\"]/tbody/tr[3]/td[5]"; + + public static final String COLLEGE = "//*[@id=\"xjkpTable\"]/tbody/tr[3]/td[1]"; + + public static final String MAJOR = "//*[@id=\"xjkpTable\"]/tbody/tr[3]/td[2]"; + + public static final String CLASS = "//*[@id=\"xjkpTable\"]/tbody/tr[3]/td[4]"; + + public static final String NAME = "//*[@id=\"xjkpTable\"]/tbody/tr[4]/td[2]"; + + public static final String SEX = "//*[@id=\"xjkpTable\"]/tbody/tr[4]/td[4]"; + + public static final String BIRTHDAY = "//*[@id=\"xjkpTable\"]/tbody/tr[5]/td[2]"; + + public static final String HOMETOWN = "//*[@id=\"xjkpTable\"]/tbody/tr[7]/td[2]"; + + public static final String NATIONALITY = "//*[@id=\"xjkpTable\"]/tbody/tr[8]/td[4]"; + + public static final String ID_NUMBER = "//*[@id=\"xjkpTable\"]/tbody/tr[50]/td[4]"; +} \ No newline at end of file diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/TrainingPlanPageParser.java b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/TrainingPlanPageParser.java index 25510cb..77e9f3d 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/TrainingPlanPageParser.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/TrainingPlanPageParser.java @@ -3,7 +3,6 @@ package cn.linghang.mywust.core.parser.undergraduate; import cn.linghang.mywust.core.exception.ParseException; import cn.linghang.mywust.core.parser.Parser; import org.jsoup.Jsoup; -import org.jsoup.nodes.Element; import org.jsoup.select.Elements; public class TrainingPlanPageParser implements Parser { diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/xpath/ExamInfoXpath.java b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/xpath/ExamInfoXpath.java deleted file mode 100644 index cecebeb..0000000 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/xpath/ExamInfoXpath.java +++ /dev/null @@ -1,5 +0,0 @@ -package cn.linghang.mywust.core.parser.undergraduate.xpath; - -public class ExamInfoXpath { - public static final String EXAM_INFO_ROWS_XPATH = "//*[@id=\"dataList\"]/tbody/tr"; -} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/xpath/StudentInfoXpath.java b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/xpath/StudentInfoXpath.java deleted file mode 100644 index 54d9704..0000000 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/xpath/StudentInfoXpath.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.linghang.mywust.core.parser.undergraduate.xpath; - -/** - *

本科生学生信息接口用到的xpath

- *

看着挺唬人的,其实直接浏览器选择元素复制xpath就行了

- *

这里的xpath只要网站UI不整什么花活就不会出问题

- * - * @author lensfrex - * @create 2022-10-22 22:16 - */ -public class StudentInfoXpath { - public static final String STUDENT_NUMBER = "//*[@id=\"xjkpTable\"]/tbody/tr[3]/td[5]"; - - public static final String COLLEGE = "//*[@id=\"xjkpTable\"]/tbody/tr[3]/td[1]"; - - public static final String MAJOR = "//*[@id=\"xjkpTable\"]/tbody/tr[3]/td[2]"; - - public static final String CLASS = "//*[@id=\"xjkpTable\"]/tbody/tr[3]/td[4]"; - - public static final String NAME = "//*[@id=\"xjkpTable\"]/tbody/tr[4]/td[2]"; - - public static final String SEX = "//*[@id=\"xjkpTable\"]/tbody/tr[4]/td[4]"; - - public static final String BIRTHDAY = "//*[@id=\"xjkpTable\"]/tbody/tr[5]/td[2]"; - - public static final String HOMETOWN = "//*[@id=\"xjkpTable\"]/tbody/tr[7]/td[2]"; - - public static final String NATIONALITY = "//*[@id=\"xjkpTable\"]/tbody/tr[8]/td[4]"; - - public static final String ID_NUMBER = "//*[@id=\"xjkpTable\"]/tbody/tr[50]/td[4]"; -} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/request/graduate/GraduateRequestFactory.java b/mywust-core/src/main/java/cn/linghang/mywust/core/request/graduate/GraduateRequestFactory.java index a24700c..00f9b00 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/request/graduate/GraduateRequestFactory.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/request/graduate/GraduateRequestFactory.java @@ -15,18 +15,18 @@ public class GraduateRequestFactory extends RequestFactory { return makeHttpRequest(Graduate.GRADUATE_CAPTCHA_API); } - private static final Map CONST_PARAMS = new HashMap<>(5); + private static final Map LOGIN_CONST_PARAMS = new HashMap<>(5); static { - CONST_PARAMS.put("__VIEWSTATE", "/wEPDwUENTM4MWQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgIFEl9jdGwwOkltYWdlQnV0dG9uMQUSX2N0bDA6SW1hZ2VCdXR0b24yXnZLY54iSWFQ6B2yKH0EisNqU3/eKWEJPibQUElowzU="); - CONST_PARAMS.put("__EVENTVALIDATION", "/wEdAAYVkBquZFuFxLpraDgB64v+UDagjadrq+xukJizXKfuf485DjYUnSc4B1y8D5WGXeCaN+cQ7B52HzGj0ueO5HRlbdfASR9MjKgO1uRUmJC5kWf476Bpzok4CsBoBh+4Dc7vLkoP0tXUghu7H8qg++pYHeGok+i2xPFtG5oj0qB2dw=="); - CONST_PARAMS.put("__VIEWSTATEGENERATOR", "496CE0B8"); - CONST_PARAMS.put("_ctl0:ImageButton1.x", "39"); - CONST_PARAMS.put("_ctl0:ImageButton1.y", "10"); + LOGIN_CONST_PARAMS.put("__VIEWSTATE", "/wEPDwUENTM4MWQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgIFEl9jdGwwOkltYWdlQnV0dG9uMQUSX2N0bDA6SW1hZ2VCdXR0b24yXnZLY54iSWFQ6B2yKH0EisNqU3/eKWEJPibQUElowzU="); + LOGIN_CONST_PARAMS.put("__EVENTVALIDATION", "/wEdAAYVkBquZFuFxLpraDgB64v+UDagjadrq+xukJizXKfuf485DjYUnSc4B1y8D5WGXeCaN+cQ7B52HzGj0ueO5HRlbdfASR9MjKgO1uRUmJC5kWf476Bpzok4CsBoBh+4Dc7vLkoP0tXUghu7H8qg++pYHeGok+i2xPFtG5oj0qB2dw=="); + LOGIN_CONST_PARAMS.put("__VIEWSTATEGENERATOR", "496CE0B8"); + LOGIN_CONST_PARAMS.put("_ctl0:ImageButton1.x", "39"); + LOGIN_CONST_PARAMS.put("_ctl0:ImageButton1.y", "10"); } public static HttpRequest loginRequest(String username, String password, SolvedImageCaptcha captcha) { Map params = new HashMap<>(7); - params.putAll(CONST_PARAMS); + params.putAll(LOGIN_CONST_PARAMS); params.put("_ctl0:txtusername", username); params.put("_ctl0:txtpassword", password); params.put("_ctl0:txtyzm", captcha.getResult()); diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/LibraryRequestFactory.java b/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/LibraryRequestFactory.java index 362a742..e0004ec 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/LibraryRequestFactory.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/LibraryRequestFactory.java @@ -12,4 +12,16 @@ public class LibraryRequestFactory extends RequestFactory { public static HttpRequest indexRequest() { return makeHttpRequest(Library.LIBRARY_INDEX_URL); } + + public static HttpRequest currentLoanRequest(String cookie) { + return makeHttpRequest(Library.LIBRARY_CURRENT_LOAN_API, null, cookie); + } + + public static HttpRequest loanHistoryRequest(String cookie) { + return makeHttpRequest(Library.LIBRARY_LOAN_HISTORY_API, null, cookie); + } + + public static HttpRequest overdueSoonRequest(String cookie) { + return makeHttpRequest(Library.LIBRARY_OVERDUE_SOON_API, null, cookie); + } } diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/BaseInfo.java b/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/BaseInfo.java new file mode 100644 index 0000000..9005f03 --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/BaseInfo.java @@ -0,0 +1,30 @@ +package cn.linghang.mywust.core.request.library.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +public class BaseInfo { + + @JsonProperty("map") + private Map map; + + @JsonProperty("empty") + private boolean empty; + + public void setMap(Map map) { + this.map = map; + } + + public Map getMap() { + return map; + } + + public void setEmpty(boolean empty) { + this.empty = empty; + } + + public boolean isEmpty() { + return empty; + } +} \ No newline at end of file diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/DetailInfo.java b/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/DetailInfo.java new file mode 100644 index 0000000..8b1c6c8 --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/DetailInfo.java @@ -0,0 +1,30 @@ +package cn.linghang.mywust.core.request.library.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +public class DetailInfo { + + @JsonProperty("map") + private Map map; + + @JsonProperty("empty") + private boolean empty; + + public void setMap(Map map) { + this.map = map; + } + + public Map getMap() { + return map; + } + + public void setEmpty(boolean empty) { + this.empty = empty; + } + + public boolean isEmpty() { + return empty; + } +} \ No newline at end of file diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/ExtraInfo.java b/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/ExtraInfo.java new file mode 100644 index 0000000..59f4779 --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/ExtraInfo.java @@ -0,0 +1,30 @@ +package cn.linghang.mywust.core.request.library.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +public class ExtraInfo { + + @JsonProperty("map") + private Map map; + + @JsonProperty("empty") + private boolean empty; + + public void setMap(Map map) { + this.map = map; + } + + public Map getMap() { + return map; + } + + public void setEmpty(boolean empty) { + this.empty = empty; + } + + public boolean isEmpty() { + return empty; + } +} \ No newline at end of file diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/LoanResultItem.java b/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/LoanResultItem.java new file mode 100644 index 0000000..c5aceec --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/LoanResultItem.java @@ -0,0 +1,49 @@ +package cn.linghang.mywust.core.request.library.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +public class LoanResultItem { + @JsonProperty("bibId") + private String bookId; + + @JsonProperty("bibAttrs") + private BookAttribute bookAttribute; + + @JsonProperty("returnDate") + private String returnDate; + + @JsonProperty("loanDate") + private String loanDate; + + @JsonProperty("location") + private String location; + + @JsonProperty("barCode") + private String barCode; + + @Data + public static class BookAttribute { + @JsonProperty("pub_year") + private String publishYear; + + @JsonProperty("author") + private String author; + + @JsonProperty("callno") + private String callNumber; + + @JsonProperty("isbn") + private String isbn; + + @JsonProperty("classno") + private String classNumber; + + @JsonProperty("publisher") + private String publisher; + + @JsonProperty("title") + private String title; + } +} \ No newline at end of file diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/Map.java b/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/Map.java new file mode 100644 index 0000000..aece8f3 --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/Map.java @@ -0,0 +1,64 @@ +package cn.linghang.mywust.core.request.library.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +public class Map { + @JsonProperty("baseInfo") + private BaseInfo baseInfo; + + @JsonProperty("detailInfo") + private DetailInfo detailInfo; + + @JsonProperty("extraInfo") + private ExtraInfo extraInfo; + + @JsonProperty("score") + private int score; + + @JsonProperty("_clickCount") + private int clickCount; + + @JsonProperty("collected") + private boolean collected; + + @JsonProperty("出版发行项") + private String publisher; + + @JsonProperty("个人责任者") + private String author; + + @JsonProperty("提要文摘附注") + private String describe; + + @JsonProperty("ISBN及定价") + private String isbn; + + @JsonProperty("载体形态项") + private String size; + + @JsonProperty("学科主题") + private String category; + + @JsonProperty("使用对象附注") + private String reader; + + @JsonProperty("责任者附注") + private String authorDescribe; + + @JsonProperty("中图法分类号") + private String clcNumber; + + @JsonProperty("著录信息附注") + private String publishNotes; + + @JsonProperty("丛编项") + private String series; + + @JsonProperty("题名/责任者") + private String fullTitle; + + @JsonProperty("title") + private String title; +} \ No newline at end of file diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/Response.java b/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/Response.java new file mode 100644 index 0000000..bcbd5a0 --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/Response.java @@ -0,0 +1,17 @@ +package cn.linghang.mywust.core.request.library.response; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Response{ + + @JsonProperty("map") + private Map map; + + public void setMap(Map map){ + this.map = map; + } + + public Map getMap(){ + return map; + } +} \ No newline at end of file diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/SearchResultItem.java b/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/SearchResultItem.java new file mode 100644 index 0000000..2e2c5b9 --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/request/library/response/SearchResultItem.java @@ -0,0 +1,150 @@ +package cn.linghang.mywust.core.request.library.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class SearchResultItem { + /** + * 图书id + */ + @JsonProperty("bibId") + private String bookId; + + /** + * 作者 + */ + @JsonProperty("author") + private String author; + + /** + * 索书号 + */ + @JsonProperty("callno") + private List callNumber; + + /** + * doc类型 + */ + @JsonProperty("docType") + private String docType; + + /** + * 分组id + */ + @JsonProperty("groupId") + private String groupId; + + /** + * ISBN号 + */ + @JsonProperty("isbn") + private String isbn; + + @JsonProperty("bibNo") + private String bibNo; + + /** + * 标题 + */ + @JsonProperty("title") + private String title; + + /** + * 图书总数 + */ + @JsonProperty("itemCount") + private int itemCount; + + /** + * 可借数 + */ + @JsonProperty("circCount") + private int circCount; + + /** + * 出版年 + */ + @JsonProperty("pub_year") + private String publishYear; + + /** + * 分类号 + */ + @JsonProperty("classno") + private String classNumber; + + /** + * 出版商 + */ + @JsonProperty("publisher") + private String publisher; + + /** + * 馆藏信息,原始数据为json字符串 + */ + @JsonProperty("holdings") + private String collectionInfo; + + /** + * 馆藏信息 + */ + @Data + public static class CollectionInfo { + /** + * 索书号 + */ + @JsonProperty("callNo") + private String callNumber; + + /** + * 馆藏总数 + */ + @JsonProperty("itemsCount") + private int itemsCount; + + /** + * 图书条码 + */ + @JsonProperty("barCode") + private String barCode; + + /** + * 可借状态 + */ + @JsonProperty("circStatus") + private int circStatus; + + /** + * 书籍分卷信息 + */ + @JsonProperty("vol") + private String vol; + + /** + * 图书可借状态 + */ + @JsonProperty("itemsAvailable") + private int itemsAvailable; + + /** + * 所属馆藏地 + */ + @JsonProperty("location") + private String location; + + /** + * 捐赠者id + */ + @JsonProperty("donatorId") + private Object donatorId; + + /** + * 状态信息 + */ + @JsonProperty("status") + private String status; + } +} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/request/physics/PhysicsSystemRequestFactory.java b/mywust-core/src/main/java/cn/linghang/mywust/core/request/physics/PhysicsSystemRequestFactory.java index 8472109..27c098e 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/request/physics/PhysicsSystemRequestFactory.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/request/physics/PhysicsSystemRequestFactory.java @@ -27,11 +27,30 @@ public class PhysicsSystemRequestFactory extends RequestFactory { return makeHttpRequest(redirect, null, cookies); } + public static HttpRequest physicsCourseIndexRequest(Map indexParam, String cookies) { + // 补上“动态”生成的参数 + indexParam.put("smLabManage", "upnMenu|lnk_2"); + indexParam.put("__EVENTTARGET", "lnk_2"); + indexParam.put("ID_PEE01$NoticeType", "-999"); + indexParam.put("ID_PEE01$txtCreater", ""); + indexParam.put("ID_PEE01$IsRead", "-999"); + indexParam.put("ID_PEE01$ObjPager_input", "1"); + indexParam.put("__ASYNCPOST", "true"); + + byte[] fromData = StringUtil.generateQueryString(indexParam).getBytes(StandardCharsets.UTF_8); + return makeHttpRequest(PhysicsSystem.PHYSICS_COURSE_INDEX_URL, fromData, cookies); + } + + public static HttpRequest physicsCourseRequest(String cookies) { + return makeHttpRequest(PhysicsSystem.PHYSICS_COURSE_API, null, cookies); + } + private static Map makeLoginQueryParam(String username, String password) { // 这几个算是是写死了的,也能用 // 但其实最好还是从首页动态获取某些关键字段("__VIEWSTATE") // 这种办法等后面有时间了再实现 Map queryParams = new HashMap<>(12); + queryParams.put("__EVENTTARGET", ""); queryParams.put("__EVENTARGUMENT", ""); queryParams.put("__VIEWSTATE", VIEW_STATE); diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/JwcLogin.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/JwcLogin.java index 9becbd3..99522dc 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/JwcLogin.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/JwcLogin.java @@ -4,10 +4,10 @@ import cn.linghang.mywust.core.api.Bkjx; import cn.linghang.mywust.core.api.UnionAuth; import cn.linghang.mywust.core.exception.BasicException; import cn.linghang.mywust.core.request.undergrade.BkjxRequestFactory; -import cn.linghang.mywust.network.entitys.HttpRequest; -import cn.linghang.mywust.network.entitys.HttpResponse; import cn.linghang.mywust.network.RequestClientOption; import cn.linghang.mywust.network.Requester; +import cn.linghang.mywust.network.entitys.HttpRequest; +import cn.linghang.mywust.network.entitys.HttpResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,11 +25,6 @@ public class JwcLogin { this.unionLogin = new UnionLogin(requester); } - public JwcLogin(Requester requester, UnionLogin unionLogin) { - this.requester = requester; - this.unionLogin = unionLogin; - } - public String getLoginCookie(String username, String password, RequestClientOption requestOption) throws IOException, BasicException { // 获取service ticket以进行进一步的登录 String serviceTicket = unionLogin.getServiceTicket(username, password, UnionAuth.Service.BKJX_SSO_SERVICE, requestOption); @@ -51,9 +46,8 @@ public class JwcLogin { } private static final int COOKIES_ERROR_RESPONSE_LENGTH = - ("").length(); + ("") + .length(); public boolean checkCookies(String cookies, RequestClientOption option) throws IOException { HttpRequest testRequest = BkjxRequestFactory.makeHttpRequest(Bkjx.BKJX_TEST_API, null, cookies); diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/LibraryLogin.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/LibraryLogin.java index 1f8ce96..bb78c41 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/LibraryLogin.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/LibraryLogin.java @@ -4,10 +4,10 @@ import cn.linghang.mywust.core.api.Library; import cn.linghang.mywust.core.api.UnionAuth; import cn.linghang.mywust.core.exception.BasicException; import cn.linghang.mywust.core.request.library.LibraryRequestFactory; -import cn.linghang.mywust.network.entitys.HttpRequest; -import cn.linghang.mywust.network.entitys.HttpResponse; import cn.linghang.mywust.network.RequestClientOption; import cn.linghang.mywust.network.Requester; +import cn.linghang.mywust.network.entitys.HttpRequest; +import cn.linghang.mywust.network.entitys.HttpResponse; import java.io.IOException; @@ -16,9 +16,9 @@ public class LibraryLogin { private final UnionLogin unionLogin; - public LibraryLogin(Requester requester, UnionLogin unionLogin) { + public LibraryLogin(Requester requester) { this.requester = requester; - this.unionLogin = unionLogin; + this.unionLogin = new UnionLogin(requester); } public String getLibraryLoginCookie(String username, String password, RequestClientOption requestOption) throws BasicException, IOException { diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/PhysicsLogin.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/PhysicsLogin.java index 3d45ff5..a06c75f 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/PhysicsLogin.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/PhysicsLogin.java @@ -1,13 +1,13 @@ package cn.linghang.mywust.core.service.auth; +import cn.linghang.mywust.core.exception.ApiException; import cn.linghang.mywust.core.exception.BasicException; -import cn.linghang.mywust.core.exception.PasswordWornException; import cn.linghang.mywust.core.parser.physics.PhysicsIndexPageParser; import cn.linghang.mywust.core.request.physics.PhysicsSystemRequestFactory; -import cn.linghang.mywust.network.entitys.HttpRequest; -import cn.linghang.mywust.network.entitys.HttpResponse; import cn.linghang.mywust.network.RequestClientOption; import cn.linghang.mywust.network.Requester; +import cn.linghang.mywust.network.entitys.HttpRequest; +import cn.linghang.mywust.network.entitys.HttpResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,19 +29,19 @@ public class PhysicsLogin { HttpRequest loginCookieRequest = PhysicsSystemRequestFactory.loginCookiesRequest(username, password, null); HttpResponse loginCookieResponse = requester.post(loginCookieRequest, requestClientOption); if (loginCookieResponse.getStatusCode() != HttpResponse.HTTP_REDIRECT_302) { - throw new PasswordWornException(); + throw new ApiException(ApiException.Code.PHYSICS_PASSWORD_WRONG); } String loginCookies = loginCookieResponse.getCookies(); if (loginCookies == null) { - throw new PasswordWornException(); + throw new ApiException(ApiException.Code.UNKNOWN_EXCEPTION); } // 请求主页,获取实验选课系统的链接,顺便测试获取到的cookie是否有效,主页能否正常访问 HttpRequest indexRequest = PhysicsSystemRequestFactory.mainIndexRequest(loginCookies); HttpResponse indexResponse = requester.get(indexRequest, requestClientOption); if (indexResponse.getStatusCode() != HttpResponse.HTTP_OK || indexResponse.getBody() == null) { - throw new BasicException(); + throw new ApiException(ApiException.Code.UNKNOWN_EXCEPTION); } // 登录实验选课系统,因为之前使用的登录接口和真正的物理实验选课系统是两个不一样的系统, @@ -51,7 +51,10 @@ public class PhysicsLogin { HttpRequest systemIndexRequest = PhysicsSystemRequestFactory.physicsSystemIndexRequest(redirect, loginCookies); requestClientOption.setFallowUrlRedirect(true); - requester.get(systemIndexRequest, requestClientOption); + HttpResponse response = requester.get(systemIndexRequest, requestClientOption); + if (response.getStatusCode() != HttpResponse.HTTP_OK) { + throw new ApiException(ApiException.Code.COOKIE_INVALID); + } return loginCookies; } diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/UnionLogin.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/UnionLogin.java index 58772bc..73bd6d1 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/UnionLogin.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/UnionLogin.java @@ -1,13 +1,15 @@ package cn.linghang.mywust.core.service.auth; +import cn.linghang.mywust.core.exception.ApiException; import cn.linghang.mywust.core.exception.BasicException; -import cn.linghang.mywust.core.exception.PasswordWornException; import cn.linghang.mywust.core.request.auth.UnionAuthRequestFactory; -import cn.linghang.mywust.network.entitys.HttpRequest; -import cn.linghang.mywust.network.entitys.HttpResponse; import cn.linghang.mywust.network.RequestClientOption; import cn.linghang.mywust.network.Requester; +import cn.linghang.mywust.network.entitys.HttpRequest; +import cn.linghang.mywust.network.entitys.HttpResponse; import cn.linghang.mywust.util.PasswordEncoder; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +36,7 @@ public class UnionLogin { String redirectAddress = unionAuthResponse.getHeaders().get("Location"); if (redirectAddress == null) { - throw new PasswordWornException(); + throw new ApiException(this.analyzeFailReason(unionAuthResponse.getBody())); } // 获取服务ticket(service ticket,ST) @@ -45,9 +47,27 @@ public class UnionLogin { if (serviceTicketResponseData == null) { log.warn("获取服务st出错,serviceTicketResponseData == null"); - throw new BasicException(); + throw new ApiException(ApiException.Code.UNKNOWN_EXCEPTION); } return new String(serviceTicketResponseData); } + + private ApiException.Code analyzeFailReason(byte[] response) { + try { + JsonNode dataNode = new ObjectMapper().readTree(response).get("data"); + switch (dataNode.get("code").asText()) { + case "PASSERROR": + return ApiException.Code.UNI_LOGIN_PASSWORD_WRONG; + case "NOUSER": + return ApiException.Code.UNI_LOGIN_USER_NOT_EXISTS; + case "USERLOCK": + return ApiException.Code.UNI_LOGIN_USER_BANNED; + default: + return ApiException.Code.UNKNOWN_EXCEPTION; + } + } catch (Exception e) { + return ApiException.Code.UNKNOWN_EXCEPTION; + } + } } diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateApiService.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateApiService.java new file mode 100644 index 0000000..76ee083 --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateApiService.java @@ -0,0 +1,36 @@ +package cn.linghang.mywust.core.service.graduate; + +import cn.linghang.mywust.core.api.Graduate; +import cn.linghang.mywust.core.exception.ApiException; +import cn.linghang.mywust.core.request.RequestFactory; +import cn.linghang.mywust.network.RequestClientOption; +import cn.linghang.mywust.network.Requester; +import cn.linghang.mywust.network.entitys.HttpRequest; +import cn.linghang.mywust.network.entitys.HttpResponse; + +import java.io.IOException; + +public class GraduateApiService { + protected final Requester requester; + + public GraduateApiService(Requester requester) { + this.requester = requester; + } + + public void checkResponse(HttpResponse response) throws ApiException { + // 检查响应是否正确 + if (response.getBody() == null || + response.getStatusCode() != HttpResponse.HTTP_OK || + new String(response.getBody()).contains("name=\"_ctl0:txtpassword\"")) { + + throw new ApiException(ApiException.Code.COOKIE_INVALID); + } + } + + public void checkCookies(String cookie, RequestClientOption option) throws ApiException, IOException { + HttpRequest request = RequestFactory.makeHttpRequest(Graduate.GRADUATE_INDEX_TEST_API, null, cookie); + HttpResponse response = requester.get(request, option); + + this.checkResponse(response); + } +} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateCourseTableApiService.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateCourseTableApiService.java new file mode 100644 index 0000000..91156da --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateCourseTableApiService.java @@ -0,0 +1,25 @@ +package cn.linghang.mywust.core.service.graduate; + +import cn.linghang.mywust.core.exception.ApiException; +import cn.linghang.mywust.core.request.graduate.GraduateRequestFactory; +import cn.linghang.mywust.network.RequestClientOption; +import cn.linghang.mywust.network.Requester; +import cn.linghang.mywust.network.entitys.HttpRequest; +import cn.linghang.mywust.network.entitys.HttpResponse; + +import java.io.IOException; + +public class GraduateCourseTableApiService extends GraduateApiService{ + + public GraduateCourseTableApiService(Requester requester) { + super(requester); + } + + public String getCourseTablePage(String cookie, RequestClientOption option) throws IOException, ApiException { + HttpRequest request = GraduateRequestFactory.courseTableRequest(cookie); + HttpResponse response = requester.get(request, option); + super.checkResponse(response); + + return new String(response.getBody()); + } +} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateScoreApiService.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateScoreApiService.java new file mode 100644 index 0000000..18e5766 --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateScoreApiService.java @@ -0,0 +1,25 @@ +package cn.linghang.mywust.core.service.graduate; + +import cn.linghang.mywust.core.exception.ApiException; +import cn.linghang.mywust.core.request.graduate.GraduateRequestFactory; +import cn.linghang.mywust.network.RequestClientOption; +import cn.linghang.mywust.network.Requester; +import cn.linghang.mywust.network.entitys.HttpRequest; +import cn.linghang.mywust.network.entitys.HttpResponse; + +import java.io.IOException; + +public class GraduateScoreApiService extends GraduateApiService{ + + public GraduateScoreApiService(Requester requester) { + super(requester); + } + + public String getCourseTablePage(String cookie, RequestClientOption option) throws IOException, ApiException { + HttpRequest request = GraduateRequestFactory.examScoreInfoRequest(cookie); + HttpResponse response = requester.get(request, option); + super.checkResponse(response); + + return new String(response.getBody()); + } +} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateStudentInfoApiService.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateStudentInfoApiService.java new file mode 100644 index 0000000..676347e --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateStudentInfoApiService.java @@ -0,0 +1,25 @@ +package cn.linghang.mywust.core.service.graduate; + +import cn.linghang.mywust.core.exception.ApiException; +import cn.linghang.mywust.core.request.graduate.GraduateRequestFactory; +import cn.linghang.mywust.network.RequestClientOption; +import cn.linghang.mywust.network.Requester; +import cn.linghang.mywust.network.entitys.HttpRequest; +import cn.linghang.mywust.network.entitys.HttpResponse; + +import java.io.IOException; + +public class GraduateStudentInfoApiService extends GraduateApiService { + + public GraduateStudentInfoApiService(Requester requester) { + super(requester); + } + + public String getStudentInfoPage(String cookie, RequestClientOption option) throws ApiException, IOException { + HttpRequest request = GraduateRequestFactory.studentInfoRequest(cookie); + HttpResponse response = requester.get(request, option); + super.checkResponse(response); + + return new String(response.getBody()); + } +} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateTrainingPlanApiService.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateTrainingPlanApiService.java new file mode 100644 index 0000000..6fe3b89 --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateTrainingPlanApiService.java @@ -0,0 +1,25 @@ +package cn.linghang.mywust.core.service.graduate; + +import cn.linghang.mywust.core.exception.ApiException; +import cn.linghang.mywust.core.request.graduate.GraduateRequestFactory; +import cn.linghang.mywust.network.RequestClientOption; +import cn.linghang.mywust.network.Requester; +import cn.linghang.mywust.network.entitys.HttpRequest; +import cn.linghang.mywust.network.entitys.HttpResponse; + +import java.io.IOException; + +public class GraduateTrainingPlanApiService extends GraduateApiService{ + + public GraduateTrainingPlanApiService(Requester requester) { + super(requester); + } + + public String getCourseTablePage(String cookie, RequestClientOption option) throws IOException, ApiException { + HttpRequest request = GraduateRequestFactory.trainingPlanPageRequest(cookie); + HttpResponse response = requester.get(request, option); + super.checkResponse(response); + + return new String(response.getBody()); + } +} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/library/LibraryService.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/library/LibraryApiService.java similarity index 61% rename from mywust-core/src/main/java/cn/linghang/mywust/core/service/library/LibraryService.java rename to mywust-core/src/main/java/cn/linghang/mywust/core/service/library/LibraryApiService.java index b589a13..c9156b7 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/service/library/LibraryService.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/service/library/LibraryApiService.java @@ -1,4 +1,4 @@ package cn.linghang.mywust.core.service.library; -public class LibraryService { +public class LibraryApiService { } diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/physics/PhysicsApiService.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/physics/PhysicsApiService.java new file mode 100644 index 0000000..d99ca4e --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/service/physics/PhysicsApiService.java @@ -0,0 +1,31 @@ +package cn.linghang.mywust.core.service.physics; + +import cn.linghang.mywust.core.exception.ApiException; +import cn.linghang.mywust.core.request.physics.PhysicsSystemRequestFactory; +import cn.linghang.mywust.network.RequestClientOption; +import cn.linghang.mywust.network.Requester; +import cn.linghang.mywust.network.entitys.HttpRequest; +import cn.linghang.mywust.network.entitys.HttpResponse; + +import java.io.IOException; + +public class PhysicsApiService { + private final Requester requester; + + public PhysicsApiService(Requester requester) { + this.requester = requester; + } + + public String getCoursePage(String cookie, RequestClientOption requestClientOption) throws IOException, ApiException { + requestClientOption.setFallowUrlRedirect(false); + + // 请求真正的课表页 + HttpRequest coursePageRequest = PhysicsSystemRequestFactory.physicsCourseRequest(cookie); + HttpResponse courseResponse = requester.get(coursePageRequest, requestClientOption); + if (courseResponse.getStatusCode() != HttpResponse.HTTP_OK) { + throw new ApiException(ApiException.Code.COOKIE_INVALID); + } + + return new String(courseResponse.getBody()); + } +} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/CourseTableApi.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/CourseTableApiService.java similarity index 51% rename from mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/CourseTableApi.java rename to mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/CourseTableApiService.java index d7544f5..5111069 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/CourseTableApi.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/CourseTableApiService.java @@ -1,10 +1,9 @@ package cn.linghang.mywust.core.service.undergraduate; -import cn.linghang.mywust.core.exception.CookieInvalidException; +import cn.linghang.mywust.core.exception.ApiException; import cn.linghang.mywust.core.exception.ParseException; import cn.linghang.mywust.core.parser.undergraduate.CourseTableParser; import cn.linghang.mywust.core.request.undergrade.BkjxRequestFactory; -import cn.linghang.mywust.core.util.BkjxUtil; import cn.linghang.mywust.model.global.Course; import cn.linghang.mywust.network.RequestClientOption; import cn.linghang.mywust.network.Requester; @@ -16,28 +15,19 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.List; -public class CourseTableApi extends UndergraduateApi { - private static final Logger log = LoggerFactory.getLogger(CourseTableApi.class); +public class CourseTableApiService extends UndergraduateApiService { - private static final CourseTableParser parser = new CourseTableParser(); - - private final Requester requester; - - public CourseTableApi(Requester requester) { - this.requester = requester; + public CourseTableApiService(Requester requester) { + super(requester); } - public String getCourseTablePage(String term, String cookies, RequestClientOption requestClientOption) throws IOException, CookieInvalidException { + public String getCourseTablePage(String term, String cookies, RequestClientOption requestClientOption) throws IOException, ApiException { HttpRequest request = BkjxRequestFactory.courseTablePageRequest(term, cookies); HttpResponse response = requester.post(request, requestClientOption); - checkResponse(response, cookies); + super.checkResponse(response); return new String(response.getBody()); } - public List getCourseTable(String term, String cookies, RequestClientOption requestClientOption) throws IOException, CookieInvalidException, ParseException { - String page = this.getCourseTablePage(term, cookies, requestClientOption); - return parser.parse(page); - } } diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/ExamInfoApi.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/ExamInfoApiService.java similarity index 53% rename from mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/ExamInfoApi.java rename to mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/ExamInfoApiService.java index 3c986a3..889eccd 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/ExamInfoApi.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/ExamInfoApiService.java @@ -1,6 +1,6 @@ package cn.linghang.mywust.core.service.undergraduate; -import cn.linghang.mywust.core.exception.CookieInvalidException; +import cn.linghang.mywust.core.exception.ApiException; import cn.linghang.mywust.core.exception.ParseException; import cn.linghang.mywust.core.parser.undergraduate.ExamInfoParser; import cn.linghang.mywust.core.request.undergrade.BkjxRequestFactory; @@ -15,29 +15,18 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.List; -public class ExamInfoApi extends UndergraduateApi { - private static final Logger log = LoggerFactory.getLogger(ExamInfoApi.class); +public class ExamInfoApiService extends UndergraduateApiService { - private final Requester requester; - - private static final ExamInfoParser parser = new ExamInfoParser(); - - public ExamInfoApi(Requester requester) { - this.requester = requester; + public ExamInfoApiService(Requester requester) { + super(requester); } - public String getExamInfoPage(String cookies, RequestClientOption requestClientOption) throws IOException, CookieInvalidException { + public String getExamInfoPage(String cookies, RequestClientOption requestClientOption) throws IOException, ApiException { HttpRequest request = BkjxRequestFactory.examScoreInfoRequest(cookies, "", "", ""); HttpResponse response = requester.post(request, requestClientOption); - checkResponse(response, cookies); + super.checkResponse(response); return new String(response.getBody()); } - - public List getExamInfo(String cookies, RequestClientOption requestClientOption) throws IOException, CookieInvalidException, ParseException { - String examInfoPage = this.getExamInfoPage(cookies, requestClientOption); - - return parser.parse(examInfoPage); - } } diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/StudentInfoApi.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/StudentInfoApi.java deleted file mode 100644 index 264f789..0000000 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/StudentInfoApi.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.linghang.mywust.core.service.undergraduate; - -import cn.linghang.mywust.core.exception.CookieInvalidException; -import cn.linghang.mywust.core.exception.ParseException; -import cn.linghang.mywust.core.parser.undergraduate.StudentInfoPageParser; -import cn.linghang.mywust.core.request.undergrade.BkjxRequestFactory; -import cn.linghang.mywust.model.global.StudentInfo; -import cn.linghang.mywust.network.RequestClientOption; -import cn.linghang.mywust.network.Requester; -import cn.linghang.mywust.network.entitys.HttpRequest; -import cn.linghang.mywust.network.entitys.HttpResponse; - -import java.io.IOException; - -public class StudentInfoApi extends UndergraduateApi { - private final Requester requester; - - private static final StudentInfoPageParser parser = new StudentInfoPageParser(); - - public StudentInfoApi(Requester requester) { - this.requester = requester; - } - - public String getStudentInfoPage(String cookies, RequestClientOption requestOption) throws IOException, CookieInvalidException { - HttpRequest request = BkjxRequestFactory.studentInfoRequest(cookies); - HttpResponse response = requester.get(request, requestOption); - - checkResponse(response, cookies); - - return new String(response.getBody()); - } - - public StudentInfo getStudentInfo(String cookies, RequestClientOption requestOption) throws IOException, CookieInvalidException, ParseException { - String studentInfoPage = this.getStudentInfoPage(cookies, requestOption); - - return parser.parse(studentInfoPage); - } -} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/StudentInfoApiService.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/StudentInfoApiService.java new file mode 100644 index 0000000..d5c68ab --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/StudentInfoApiService.java @@ -0,0 +1,26 @@ +package cn.linghang.mywust.core.service.undergraduate; + +import cn.linghang.mywust.core.exception.ApiException; +import cn.linghang.mywust.core.request.undergrade.BkjxRequestFactory; +import cn.linghang.mywust.network.RequestClientOption; +import cn.linghang.mywust.network.Requester; +import cn.linghang.mywust.network.entitys.HttpRequest; +import cn.linghang.mywust.network.entitys.HttpResponse; + +import java.io.IOException; + +public class StudentInfoApiService extends UndergraduateApiService { + + public StudentInfoApiService(Requester requester) { + super(requester); + } + + public String getStudentInfoPage(String cookies, RequestClientOption requestOption) throws IOException, ApiException { + HttpRequest request = BkjxRequestFactory.studentInfoRequest(cookies); + HttpResponse response = requester.get(request, requestOption); + + super.checkResponse(response); + + return new String(response.getBody()); + } +} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/TrainingPlanApi.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/TrainingPlanApi.java deleted file mode 100644 index 89fbe06..0000000 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/TrainingPlanApi.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.linghang.mywust.core.service.undergraduate; - -import cn.linghang.mywust.core.exception.CookieInvalidException; -import cn.linghang.mywust.core.exception.ParseException; -import cn.linghang.mywust.core.parser.undergraduate.TrainingPlanPageParser; -import cn.linghang.mywust.core.request.undergrade.BkjxRequestFactory; -import cn.linghang.mywust.network.RequestClientOption; -import cn.linghang.mywust.network.Requester; -import cn.linghang.mywust.network.entitys.HttpRequest; -import cn.linghang.mywust.network.entitys.HttpResponse; - -import java.io.IOException; - -public class TrainingPlanApi extends UndergraduateApi { - private final Requester requester; - - private static final TrainingPlanPageParser parser = new TrainingPlanPageParser(); - - public TrainingPlanApi(Requester requester) { - this.requester = requester; - } - - public String getTrainingPlanPage(String cookies, RequestClientOption requestClientOption) throws CookieInvalidException, IOException { - HttpRequest request = BkjxRequestFactory.trainingPlanPageRequest(cookies); - HttpResponse response = requester.get(request, requestClientOption); - - checkResponse(response, cookies); - - return new String(response.getBody()); - } - - public String getPrueSchemePage(String cookies, RequestClientOption requestClientOption) throws IOException, CookieInvalidException, ParseException { - String fullPage = this.getTrainingPlanPage(cookies, requestClientOption); - return parser.parse(fullPage); - } -} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/TrainingPlanApiService.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/TrainingPlanApiService.java new file mode 100644 index 0000000..ec30750 --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/TrainingPlanApiService.java @@ -0,0 +1,26 @@ +package cn.linghang.mywust.core.service.undergraduate; + +import cn.linghang.mywust.core.exception.ApiException; +import cn.linghang.mywust.core.request.undergrade.BkjxRequestFactory; +import cn.linghang.mywust.network.RequestClientOption; +import cn.linghang.mywust.network.Requester; +import cn.linghang.mywust.network.entitys.HttpRequest; +import cn.linghang.mywust.network.entitys.HttpResponse; + +import java.io.IOException; + +public class TrainingPlanApiService extends UndergraduateApiService { + + public TrainingPlanApiService(Requester requester) { + super(requester); + } + + public String getTrainingPlanPage(String cookies, RequestClientOption requestClientOption) throws IOException, ApiException { + HttpRequest request = BkjxRequestFactory.trainingPlanPageRequest(cookies); + HttpResponse response = requester.get(request, requestClientOption); + + super.checkResponse(response); + + return new String(response.getBody()); + } +} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/UndergraduateApi.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/UndergraduateApi.java deleted file mode 100644 index 6fe871d..0000000 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/UndergraduateApi.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.linghang.mywust.core.service.undergraduate; - -import cn.linghang.mywust.core.exception.CookieInvalidException; -import cn.linghang.mywust.core.util.BkjxUtil; -import cn.linghang.mywust.network.entitys.HttpResponse; - -public class UndergraduateApi { - public void checkResponse(HttpResponse response, String cookies) throws CookieInvalidException { - // 检查响应是否正确 - if (response.getBody() == null || - response.getStatusCode() != HttpResponse.HTTP_OK || - BkjxUtil.checkLoginFinger(response.getBody())) { - - throw new CookieInvalidException("响应无效,cookie可能过期:" + cookies); - } - } -} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/UndergraduateApiService.java b/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/UndergraduateApiService.java new file mode 100644 index 0000000..7c2546a --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/service/undergraduate/UndergraduateApiService.java @@ -0,0 +1,38 @@ +package cn.linghang.mywust.core.service.undergraduate; + +import cn.linghang.mywust.core.api.Bkjx; +import cn.linghang.mywust.core.exception.ApiException; +import cn.linghang.mywust.core.request.RequestFactory; +import cn.linghang.mywust.core.request.undergrade.BkjxRequestFactory; +import cn.linghang.mywust.core.util.BkjxUtil; +import cn.linghang.mywust.network.RequestClientOption; +import cn.linghang.mywust.network.Requester; +import cn.linghang.mywust.network.entitys.HttpRequest; +import cn.linghang.mywust.network.entitys.HttpResponse; + +import java.io.IOException; + +public class UndergraduateApiService { + protected final Requester requester; + + public UndergraduateApiService(Requester requester) { + this.requester = requester; + } + + public void checkResponse(HttpResponse response) throws ApiException { + // 检查响应是否正确 + if (response.getBody() == null || + response.getStatusCode() != HttpResponse.HTTP_OK || + BkjxUtil.checkLoginFinger(response.getBody())) { + + throw new ApiException(ApiException.Code.COOKIE_INVALID); + } + } + + public void checkCookies(String cookie, RequestClientOption option) throws ApiException, IOException { + HttpRequest request = RequestFactory.makeHttpRequest(Bkjx.BKJX_TEST_API, null, cookie); + HttpResponse response = requester.get(request, option); + + this.checkResponse(response); + } +} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/util/BkjxUtil.java b/mywust-core/src/main/java/cn/linghang/mywust/core/util/BkjxUtil.java index dac0f53..274e338 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/util/BkjxUtil.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/util/BkjxUtil.java @@ -1,5 +1,7 @@ package cn.linghang.mywust.core.util; +import cn.linghang.mywust.core.api.Bkjx; + import java.nio.charset.StandardCharsets; /** @@ -7,7 +9,7 @@ import java.nio.charset.StandardCharsets; */ public class BkjxUtil { // 在“Bkjx”系统里边如果收到的响应开头是这个的话多半是cookie无效了,需要重新登录获取cookie - private static final byte[] LOGIN_MESSAGE_RESPONSE_FINGER = "