主要修复:研究生部分页面获取时Referer缺少导致无法获取相关的信息;次要修改:修改部分异常类的抛出,jdk最低版本降至1.8

old-package
lensfrex 2 years ago
parent d6fc6f9878
commit 79c6659509
Signed by: lensfrex
GPG Key ID: 947ADABD8533C476
  1. 4
      mywust-core/pom.xml
  2. 5
      mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/GraduateLogin.java
  3. 5
      mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/JwcLogin.java
  4. 3
      mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/LibraryLogin.java
  5. 3
      mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/PhysicsLogin.java
  6. 2
      mywust-core/src/main/java/cn/linghang/mywust/core/service/auth/UnionLogin.java
  7. 3
      mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateCourseTableApiService.java
  8. 4
      mywust-core/src/main/java/cn/linghang/mywust/core/service/graduate/GraduateScoreApiService.java
  9. 4
      mywust-model/pom.xml
  10. 4
      mywust-network-httpclient/pom.xml
  11. 4
      mywust-network-okhttp/pom.xml
  12. 4
      mywust-network/pom.xml
  13. 4
      mywust-test/pom.xml
  14. 4
      mywust-util/pom.xml
  15. 8
      mywust-util/src/main/java/cn/linghang/mywust/util/StringUtil.java
  16. 23
      pom.xml

@ -70,8 +70,8 @@
</dependencies> </dependencies>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
</project> </project>

@ -3,7 +3,6 @@ package cn.linghang.mywust.core.service.auth;
import cn.linghang.mywust.captcha.SolvedImageCaptcha; import cn.linghang.mywust.captcha.SolvedImageCaptcha;
import cn.linghang.mywust.captcha.UnsolvedImageCaptcha; import cn.linghang.mywust.captcha.UnsolvedImageCaptcha;
import cn.linghang.mywust.core.exception.ApiException; import cn.linghang.mywust.core.exception.ApiException;
import cn.linghang.mywust.core.exception.BasicException;
import cn.linghang.mywust.core.request.graduate.GraduateRequestFactory; import cn.linghang.mywust.core.request.graduate.GraduateRequestFactory;
import cn.linghang.mywust.core.service.captcha.solver.CaptchaSolver; import cn.linghang.mywust.core.service.captcha.solver.CaptchaSolver;
import cn.linghang.mywust.network.RequestClientOption; import cn.linghang.mywust.network.RequestClientOption;
@ -28,7 +27,7 @@ public class GraduateLogin {
this.captchaSolver = captchaSolver; this.captchaSolver = captchaSolver;
} }
public String getLoginCookie(String username, String password, RequestClientOption option) throws IOException, BasicException { public String getLoginCookie(String username, String password, RequestClientOption option) throws IOException, ApiException {
// 请求获取验证码 // 请求获取验证码
HttpRequest captchaImageRequest = GraduateRequestFactory.captchaRequest(); HttpRequest captchaImageRequest = GraduateRequestFactory.captchaRequest();
HttpResponse captchaImageResponse = requester.get(captchaImageRequest, option); HttpResponse captchaImageResponse = requester.get(captchaImageRequest, option);
@ -87,7 +86,7 @@ class ImageUtil {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "png", outputStream); ImageIO.write(bufferedImage, "png", outputStream);
return byteArrayInputStream.readAllBytes(); return outputStream.toByteArray();
} catch (Exception e) { } catch (Exception e) {
throw new ApiException(ApiException.Code.INTERNAL_EXCEPTION); throw new ApiException(ApiException.Code.INTERNAL_EXCEPTION);
} }

@ -2,6 +2,7 @@ package cn.linghang.mywust.core.service.auth;
import cn.linghang.mywust.core.api.Bkjx; import cn.linghang.mywust.core.api.Bkjx;
import cn.linghang.mywust.core.api.UnionAuth; import cn.linghang.mywust.core.api.UnionAuth;
import cn.linghang.mywust.core.exception.ApiException;
import cn.linghang.mywust.core.exception.BasicException; import cn.linghang.mywust.core.exception.BasicException;
import cn.linghang.mywust.core.request.undergrade.BkjxRequestFactory; import cn.linghang.mywust.core.request.undergrade.BkjxRequestFactory;
import cn.linghang.mywust.network.RequestClientOption; import cn.linghang.mywust.network.RequestClientOption;
@ -25,7 +26,7 @@ public class JwcLogin {
this.unionLogin = new UnionLogin(requester); this.unionLogin = new UnionLogin(requester);
} }
public String getLoginCookie(String username, String password, RequestClientOption requestOption) throws IOException, BasicException { public String getLoginCookie(String username, String password, RequestClientOption requestOption) throws IOException, ApiException {
// 获取service ticket以进行进一步的登录 // 获取service ticket以进行进一步的登录
String serviceTicket = unionLogin.getServiceTicket(username, password, UnionAuth.Service.BKJX_SSO_SERVICE, requestOption); String serviceTicket = unionLogin.getServiceTicket(username, password, UnionAuth.Service.BKJX_SSO_SERVICE, requestOption);
@ -35,7 +36,7 @@ public class JwcLogin {
String cookies = sessionResponse.getCookies(); String cookies = sessionResponse.getCookies();
if (roughCheckCookie(cookies)) { if (roughCheckCookie(cookies)) {
throw new BasicException(); throw new ApiException(ApiException.Code.UNKNOWN_EXCEPTION);
} }
return cookies; return cookies;

@ -2,6 +2,7 @@ package cn.linghang.mywust.core.service.auth;
import cn.linghang.mywust.core.api.Library; import cn.linghang.mywust.core.api.Library;
import cn.linghang.mywust.core.api.UnionAuth; import cn.linghang.mywust.core.api.UnionAuth;
import cn.linghang.mywust.core.exception.ApiException;
import cn.linghang.mywust.core.exception.BasicException; import cn.linghang.mywust.core.exception.BasicException;
import cn.linghang.mywust.core.request.library.LibraryRequestFactory; import cn.linghang.mywust.core.request.library.LibraryRequestFactory;
import cn.linghang.mywust.network.RequestClientOption; import cn.linghang.mywust.network.RequestClientOption;
@ -21,7 +22,7 @@ public class LibraryLogin {
this.unionLogin = new UnionLogin(requester); this.unionLogin = new UnionLogin(requester);
} }
public String getLibraryLoginCookie(String username, String password, RequestClientOption requestOption) throws BasicException, IOException { public String getLibraryLoginCookie(String username, String password, RequestClientOption requestOption) throws ApiException, IOException {
// 获取service ticket以进行进一步的登录 // 获取service ticket以进行进一步的登录
String serviceTicket = unionLogin.getServiceTicket(username, password, UnionAuth.Service.LIBRARY_SSO_SERVICE, requestOption); String serviceTicket = unionLogin.getServiceTicket(username, password, UnionAuth.Service.LIBRARY_SSO_SERVICE, requestOption);

@ -2,6 +2,7 @@ package cn.linghang.mywust.core.service.auth;
import cn.linghang.mywust.core.exception.ApiException; import cn.linghang.mywust.core.exception.ApiException;
import cn.linghang.mywust.core.exception.BasicException; import cn.linghang.mywust.core.exception.BasicException;
import cn.linghang.mywust.core.exception.ParseException;
import cn.linghang.mywust.core.parser.physics.PhysicsIndexPageParser; import cn.linghang.mywust.core.parser.physics.PhysicsIndexPageParser;
import cn.linghang.mywust.core.request.physics.PhysicsSystemRequestFactory; import cn.linghang.mywust.core.request.physics.PhysicsSystemRequestFactory;
import cn.linghang.mywust.network.RequestClientOption; import cn.linghang.mywust.network.RequestClientOption;
@ -24,7 +25,7 @@ public class PhysicsLogin {
this.requester = requester; this.requester = requester;
} }
public String getLoginCookie(String username, String password, RequestClientOption requestClientOption) throws IOException, BasicException { public String getLoginCookie(String username, String password, RequestClientOption requestClientOption) throws IOException, ApiException, ParseException {
// 直接登录,ASP.NET_SessionId其实在这步就能获取到,不需要再请求一遍首页获取 // 直接登录,ASP.NET_SessionId其实在这步就能获取到,不需要再请求一遍首页获取
HttpRequest loginCookieRequest = PhysicsSystemRequestFactory.loginCookiesRequest(username, password, null); HttpRequest loginCookieRequest = PhysicsSystemRequestFactory.loginCookiesRequest(username, password, null);
HttpResponse loginCookieResponse = requester.post(loginCookieRequest, requestClientOption); HttpResponse loginCookieResponse = requester.post(loginCookieRequest, requestClientOption);

@ -27,7 +27,7 @@ public class UnionLogin {
this.requester = requester; this.requester = requester;
} }
public String getServiceTicket(String username, String password, String serviceUrl, RequestClientOption requestOption) throws IOException, BasicException { public String getServiceTicket(String username, String password, String serviceUrl, RequestClientOption requestOption) throws IOException, ApiException {
String encodedPassword = PasswordEncoder.encodePassword(password); String encodedPassword = PasswordEncoder.encodePassword(password);
// 获取ticket granting ticket(TGT),以获取ServiceTicket // 获取ticket granting ticket(TGT),以获取ServiceTicket

@ -17,6 +17,9 @@ public class GraduateCourseTableApiService extends GraduateApiService{
public String getCourseTablePage(String cookie, RequestClientOption option) throws IOException, ApiException { public String getCourseTablePage(String cookie, RequestClientOption option) throws IOException, ApiException {
HttpRequest request = GraduateRequestFactory.courseTableRequest(cookie); HttpRequest request = GraduateRequestFactory.courseTableRequest(cookie);
request.addHeaders("Referer", "http://59.68.177.189/pyxx/pygl/kbcx_xs.aspx");
request.addHeaders("Origin", "http://59.68.177.189");
HttpResponse response = requester.get(request, option); HttpResponse response = requester.get(request, option);
super.checkResponse(response); super.checkResponse(response);

@ -15,8 +15,10 @@ public class GraduateScoreApiService extends GraduateApiService{
super(requester); super(requester);
} }
public String getCourseTablePage(String cookie, RequestClientOption option) throws IOException, ApiException { public String getScorePage(String cookie, RequestClientOption option) throws IOException, ApiException {
HttpRequest request = GraduateRequestFactory.examScoreInfoRequest(cookie); HttpRequest request = GraduateRequestFactory.examScoreInfoRequest(cookie);
request.addHeaders("Referer", "http://59.68.177.189/pyxx/leftmenu.aspx");
HttpResponse response = requester.get(request, option); HttpResponse response = requester.get(request, option);
super.checkResponse(response); super.checkResponse(response);

@ -20,8 +20,8 @@
</dependencies> </dependencies>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>

@ -9,8 +9,8 @@
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>

@ -9,8 +9,8 @@
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>

@ -12,8 +12,8 @@
<artifactId>mywust-network</artifactId> <artifactId>mywust-network</artifactId>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>

@ -61,8 +61,8 @@
</dependencies> </dependencies>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>

@ -12,8 +12,8 @@
<artifactId>mywust-util</artifactId> <artifactId>mywust-util</artifactId>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>

@ -3,6 +3,7 @@ package cn.linghang.mywust.util;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
@ -19,7 +20,12 @@ public class StringUtil {
public static String generateQueryString(Map<String, String> queryParams) { public static String generateQueryString(Map<String, String> queryParams) {
// 自动对value值进行url编码 // 自动对value值进行url编码
Map<String, String> urlEncodedQueryParams = new TreeMap<>(REPEATABLE_COMPARATOR); Map<String, String> urlEncodedQueryParams = new TreeMap<>(REPEATABLE_COMPARATOR);
queryParams.forEach((k, v) -> urlEncodedQueryParams.put(k, URLEncoder.encode(v, StandardCharsets.UTF_8))); queryParams.forEach((k, v) -> {
try {
urlEncodedQueryParams.put(k, URLEncoder.encode(v, StandardCharsets.UTF_8.name()));
} catch (UnsupportedEncodingException ignored) {
}
});
return Joiner.on('&') return Joiner.on('&')
.useForNull("") .useForNull("")

@ -19,10 +19,9 @@
</modules> </modules>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<distributionManagement> <distributionManagement>
@ -32,4 +31,22 @@
<url>https://maven.pkg.github.com/LingHangStudio/mywust</url> <url>https://maven.pkg.github.com/LingHangStudio/mywust</url>
</repository> </repository>
</distributionManagement> </distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project> </project>
Loading…
Cancel
Save