From 99e1ea7c8fe539c2c6d942b0b32a7d4445298f4f Mon Sep 17 00:00:00 2001 From: lensferno Date: Tue, 11 Jul 2023 16:58:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9B=BE=E4=B9=A6=E9=A6=86=EF=BC=9A?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=BE=E4=B9=A6=E9=A6=86=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=88=B0=E7=9A=84cookie=E4=B8=8D=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/wustlinghang/mywust/core/api/LibraryUrls.java | 3 ++- .../core/request/service/auth/LibraryLogin.java | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/api/LibraryUrls.java b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/api/LibraryUrls.java index 7760ab2..3b37d73 100644 --- a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/api/LibraryUrls.java +++ b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/api/LibraryUrls.java @@ -5,7 +5,8 @@ public class LibraryUrls { 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"; + // 用违章记录信息api地址作为测试url(大部分人应该没有违章吧 :) + public static final String LIBRARY_COOKIE_TEST_URL = "https://libsys.wust.edu.cn/meta-local/opac/users/volts"; public static final String LIBRARY_ACCOUNT_STATUS_API = "https://libsys.wust.edu.cn/meta-local/opac/users/stats"; diff --git a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/auth/LibraryLogin.java b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/auth/LibraryLogin.java index af85574..b072c29 100644 --- a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/auth/LibraryLogin.java +++ b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/auth/LibraryLogin.java @@ -2,8 +2,8 @@ package cn.wustlinghang.mywust.core.request.service.auth; import cn.wustlinghang.mywust.core.api.LibraryUrls; import cn.wustlinghang.mywust.core.api.UnionAuthUrls; -import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.core.request.factory.library.LibraryRequestFactory; +import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.network.RequestClientOption; import cn.wustlinghang.mywust.network.Requester; import cn.wustlinghang.mywust.network.entitys.HttpRequest; @@ -30,10 +30,15 @@ public class LibraryLogin { HttpResponse sessionResponse = requester.get(sessionRequest, requestOption); String cookies = sessionResponse.getCookies(); - // 请求一次首页 + // 请求一次首页,这次获得的cookie才是真正的cookie HttpRequest indexRequest = LibraryRequestFactory.indexRequest(); indexRequest.setCookies(cookies); - requester.get(indexRequest, requestOption); + HttpResponse indexResponse = requester.get(indexRequest, requestOption); + cookies = indexResponse.getCookies() != null ? indexResponse.getCookies() : cookies; + + if (!checkCookie(cookies)) { + throw new ApiException(ApiException.Code.COOKIE_INVALID); + } return cookies; }