fix: 图书馆:修复图书馆登录获取到的cookie不正确的问题

main
lensfrex 1 year ago
parent c13aa2f56f
commit 99e1ea7c8f
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 3
      mywust-core/src/main/java/cn/wustlinghang/mywust/core/api/LibraryUrls.java
  2. 11
      mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/auth/LibraryLogin.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";

@ -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;
}

Loading…
Cancel
Save