图书馆接口获取:搜索,图书信息,图书封面图片url,当前借阅列表,即将逾期列表,借阅历史,账号状态

old-package
lensfrex 2 years ago
parent 71264e9ac3
commit ac79a9142e
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 10
      mywust-core/src/main/java/cn/linghang/mywust/core/api/LibraryUrls.java
  2. 2
      mywust-core/src/main/java/cn/linghang/mywust/core/exception/ParseException.java
  3. 10
      mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/UndergradCourseTableParser.java
  4. 26
      mywust-core/src/main/java/cn/linghang/mywust/core/parser/undergraduate/UndergradScoreParser.java
  5. 48
      mywust-core/src/main/java/cn/linghang/mywust/core/request/factory/library/LibraryRequestFactory.java
  6. 40
      mywust-core/src/main/java/cn/linghang/mywust/core/request/factory/library/request/SearchRequest.java
  7. 30
      mywust-core/src/main/java/cn/linghang/mywust/core/request/factory/library/response/BaseInfo.java
  8. 30
      mywust-core/src/main/java/cn/linghang/mywust/core/request/factory/library/response/DetailInfo.java
  9. 30
      mywust-core/src/main/java/cn/linghang/mywust/core/request/factory/library/response/ExtraInfo.java
  10. 49
      mywust-core/src/main/java/cn/linghang/mywust/core/request/factory/library/response/LoanResultItem.java
  11. 64
      mywust-core/src/main/java/cn/linghang/mywust/core/request/factory/library/response/Map.java
  12. 17
      mywust-core/src/main/java/cn/linghang/mywust/core/request/factory/library/response/Response.java
  13. 150
      mywust-core/src/main/java/cn/linghang/mywust/core/request/factory/library/response/SearchResultItem.java
  14. 14
      mywust-core/src/main/java/cn/linghang/mywust/core/request/factory/undergrade/BkjxRequestFactory.java
  15. 56
      mywust-core/src/main/java/cn/linghang/mywust/core/request/factory/undergrade/CourseTableRequestParamFactory.java
  16. 7
      mywust-core/src/main/java/cn/linghang/mywust/core/request/service/auth/LibraryLogin.java
  17. 66
      mywust-core/src/main/java/cn/linghang/mywust/core/request/service/library/LibraryApiService.java
  18. 20
      mywust-core/src/main/java/cn/linghang/mywust/core/request/service/library/LibraryApiServiceBase.java
  19. 4
      mywust-core/src/main/java/cn/linghang/mywust/core/request/service/physics/PhysicsCourseApiService.java
  20. 4
      mywust-core/src/main/java/cn/linghang/mywust/core/request/service/physics/PhysicsScoreApiService.java

@ -7,9 +7,15 @@ public class LibraryUrls {
public static final String LIBRARY_COOKIE_TEST_URL = "https://libsys.wust.edu.cn/meta-local/opac/users/info"; 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_ACCOUNT_STATUS_API = "https://libsys.wust.edu.cn/meta-local/opac/users/stats";
public static final String LIBRARY_LOAN_HISTORY_API = "https://libsys.wust.edu.cn/meta-local/opac/users/loan_hists";
public static final String LIBRARY_CURRENT_LOAN_API = "https://libsys.wust.edu.cn/meta-local/opac/users/loans?page=1&pageSize=100";
public static final String LIBRARY_LOAN_HISTORY_API = "https://libsys.wust.edu.cn/meta-local/opac/users/loan_hists?page=1&pageSize=100";
public static final String LIBRARY_OVERDUE_SOON_API = "https://libsys.wust.edu.cn/meta-local/opac/users/overdue_soon"; public static final String LIBRARY_OVERDUE_SOON_API = "https://libsys.wust.edu.cn/meta-local/opac/users/overdue_soon";
public static final String LIBRARY_BOOK_INFO_API = "https://libsys.wust.edu.cn/meta-local/opac/bibs/%s/holdings";
public static final String LIBRARY_BOOK_COVER_IMAGE_API = "https://libsys.wust.edu.cn/meta-local/opac/search/extend/";
public static final String LIBRARY_SEARCH_API = "https://libsys.wust.edu.cn/meta-local/opac/search/"; public static final String LIBRARY_SEARCH_API = "https://libsys.wust.edu.cn/meta-local/opac/search/";
} }

@ -28,7 +28,7 @@ public class ParseException extends BasicException {
public String toString() { public String toString() {
return new StringJoiner(", ", ParseException.class.getSimpleName() + "[", "]") return new StringJoiner(", ", ParseException.class.getSimpleName() + "[", "]")
.add("message='" + getMessage() + "'") .add("message='" + getMessage() + "'")
.add("rawData='" + rawData + "'") .add("rawData='" + (rawData.length() > 32 ? rawData.substring(0, 32) : rawData) + "'")
.toString(); .toString();
} }
} }

@ -81,12 +81,13 @@ public class UndergradCourseTableParser implements Parser<List<Course>> {
// 靠行位置来确定节次和星期,而不是靠time字段的数据确定(因为太不好处理了) // 靠行位置来确定节次和星期,而不是靠time字段的数据确定(因为太不好处理了)
// 对于只有一个小节的课程,这类课程多数是在线课程,这里一律按照两小节大课处理 // 对于只有一个小节的课程,这类课程多数是在线课程,这里一律按照两小节大课处理
// 具体算法就是行索引x2 + 1就是开始的节次(索引从0开始) // 具体算法就是行索引x2 + 1就是开始的节次(索引从0开始)
int lineIndex = (int) (girdCount * 0.142); int lineIndex = (girdCount / 7);
courseBuilder.startSection(lineIndex * 2 + 1); courseBuilder.startSection(lineIndex * 2 + 1);
courseBuilder.endSection(lineIndex * 2 + 2); courseBuilder.endSection(lineIndex * 2 + 2);
// 切割连续周信息,如"1-2,4-6(周)"这样两段的连续周(1-3周和5-10周)
// 不直接使用String.split而是手动分割,是因为系统自带split方法每次调用都需要编译一次切割正则,效率不太行 // 不直接使用String.split而是手动分割,是因为系统自带split方法每次调用都需要编译一次切割正则,效率不太行
String timeText = timeElements.isEmpty() ? "" : StringUtil.split(JsoupUtil.getElementText(timeElements, 0), ',').get(0); String timeText = StringUtil.split(JsoupUtil.getElementText(timeElements, 0), ',').get(0);
List<String> times = StringUtil.split(timeText, ','); List<String> times = StringUtil.split(timeText, ',');
for (String time : times) { for (String time : times) {
Matcher weekMatcher = WEEK_REGEX.matcher(time); Matcher weekMatcher = WEEK_REGEX.matcher(time);
@ -106,11 +107,10 @@ public class UndergradCourseTableParser implements Parser<List<Course>> {
} }
return courses; return courses;
} catch (Exception e) { } catch (Exception e) {
log.warn("解析课表时出现问题:{}", e.getMessage(), e); log.warn("解析课表时出现问题:{}", e.getMessage(), e);
throw new ParseException(html); throw new ParseException("解析课表时出现问题:" + e, html);
} }
} }
} }

@ -38,23 +38,23 @@ public class UndergradScoreParser implements Parser<List<Score>> {
Score score = new Score(); Score score = new Score();
// 这段看着震撼,但其实很丑 // 这段看着震撼,但其实很丑
score.setId(JsoupUtil.getElementText(girds.get(0))); score.setId(JsoupUtil.getElementText(girds, 0));
score.setTerm(JsoupUtil.getElementText(girds.get(1))); score.setTerm(JsoupUtil.getElementText(girds, 1));
score.setCourseNumber(JsoupUtil.getElementText(girds.get(2))); score.setCourseNumber(JsoupUtil.getElementText(girds, 2));
score.setCourseName(JsoupUtil.getElementText(girds.get(3))); score.setCourseName(JsoupUtil.getElementText(girds,3));
score.setGroupName(JsoupUtil.getElementText(girds.get(4))); score.setGroupName(JsoupUtil.getElementText(girds, 4));
score.setScore(JsoupUtil.getElementText(girds.get(5))); score.setScore(JsoupUtil.getElementText(girds, 5));
score.setFlag(JsoupUtil.getElementText(girds.get(6))); score.setFlag(JsoupUtil.getElementText(girds, 6));
score.setCredit(JsoupUtil.getElementText(girds.get(7))); score.setCredit(JsoupUtil.getElementText(girds, 7));
score.setCourseHours(JsoupUtil.getElementText(girds.get(8))); score.setCourseHours(JsoupUtil.getElementText(girds, 8));
score.setGradePoint(JsoupUtil.getElementText(girds.get(9))); score.setGradePoint(JsoupUtil.getElementText(girds, 9));
score.setEvaluateMethod(JsoupUtil.getElementText(girds.get(11))); score.setEvaluateMethod(JsoupUtil.getElementText(girds, 11));
score.setKind(JsoupUtil.getElementText(girds.get(12))); score.setKind(JsoupUtil.getElementText(girds, 12));
score.setCourseKind(JsoupUtil.getElementText(girds.get(13))); score.setCourseKind(JsoupUtil.getElementText(girds, 13));
scores.add(score); scores.add(score);
} }

@ -1,10 +1,21 @@
package cn.linghang.mywust.core.request.factory.library; package cn.linghang.mywust.core.request.factory.library;
import cn.hutool.core.util.URLUtil;
import cn.linghang.mywust.core.api.LibraryUrls; import cn.linghang.mywust.core.api.LibraryUrls;
import cn.linghang.mywust.core.request.factory.RequestFactory; import cn.linghang.mywust.core.request.factory.RequestFactory;
import cn.linghang.mywust.core.request.factory.library.request.SearchRequest;
import cn.linghang.mywust.network.entitys.HttpRequest; import cn.linghang.mywust.network.entitys.HttpRequest;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import java.util.StringJoiner;
public class LibraryRequestFactory extends RequestFactory { public class LibraryRequestFactory extends RequestFactory {
private static final ObjectMapper objectMapper = new ObjectMapper();
private static final String searchTemplate = "{\"page\":%d,\"pageSize\":%d,\"indexName\":\"idx.opac\",\"sortField\":\"relevance\",\"sortType\":\"desc\",\"collapseField\":\"groupId\",\"queryFieldList\":[{\"logic\":0,\"field\":\"all\",\"values\":[\"%s\"],\"operator\":\"*\"}],\"filterFieldList\":[]}";
public static HttpRequest sessionCookieRequest(String serviceTicket) { public static HttpRequest sessionCookieRequest(String serviceTicket) {
return makeHttpRequest(String.format(LibraryUrls.LIBRARY_SESSION_COOKIE_API, serviceTicket)); return makeHttpRequest(String.format(LibraryUrls.LIBRARY_SESSION_COOKIE_API, serviceTicket));
} }
@ -13,6 +24,19 @@ public class LibraryRequestFactory extends RequestFactory {
return makeHttpRequest(LibraryUrls.LIBRARY_INDEX_URL); return makeHttpRequest(LibraryUrls.LIBRARY_INDEX_URL);
} }
public static HttpRequest bookSearchRequest(String keyword, int page, int pageSize) {
return bookSearchRequest(new SearchRequest(keyword, page, pageSize));
}
public static HttpRequest bookSearchRequest(SearchRequest request) {
return makeHttpRequest(LibraryUrls.LIBRARY_SEARCH_API, json(request))
.addHeaders("Content-Type", "application/json");
}
public static HttpRequest accountStateRequest(String cookie) {
return makeHttpRequest(LibraryUrls.LIBRARY_ACCOUNT_STATUS_API, null, cookie);
}
public static HttpRequest currentLoanRequest(String cookie) { public static HttpRequest currentLoanRequest(String cookie) {
return makeHttpRequest(LibraryUrls.LIBRARY_CURRENT_LOAN_API, null, cookie); return makeHttpRequest(LibraryUrls.LIBRARY_CURRENT_LOAN_API, null, cookie);
} }
@ -25,7 +49,27 @@ public class LibraryRequestFactory extends RequestFactory {
return makeHttpRequest(LibraryUrls.LIBRARY_OVERDUE_SOON_API, null, cookie); return makeHttpRequest(LibraryUrls.LIBRARY_OVERDUE_SOON_API, null, cookie);
} }
public static HttpRequest bookInfoRequest(String cookie) { public static HttpRequest bookInfoRequest(String bookId) {
return makeHttpRequest(LibraryUrls.LIBRARY_OVERDUE_SOON_API, null, cookie); String url = String.format(LibraryUrls.LIBRARY_BOOK_INFO_API, bookId);
return makeHttpRequest(url, (byte[]) null);
}
public static HttpRequest bookCoverImageUrlRequest(List<String> isbn) {
StringJoiner joiner = new StringJoiner("%2C", LibraryUrls.LIBRARY_BOOK_COVER_IMAGE_API, "");
isbn.forEach(joiner::add);
return makeHttpRequest(joiner.toString(), (byte[]) null);
}
public static HttpRequest bookCoverImageUrlRequest(String isbn) {
return makeHttpRequest(LibraryUrls.LIBRARY_BOOK_COVER_IMAGE_API + isbn, (byte[]) null);
}
private static String json(Object object) {
try {
return objectMapper.writeValueAsString(object);
} catch (JsonProcessingException ignored) {
return "";
}
} }
} }

@ -0,0 +1,40 @@
package cn.linghang.mywust.core.request.factory.library.request;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;
@Data
public class SearchRequest {
private final List<Object> filterFieldList = new ArrayList<>();
private final String collapseField = "groupId";
private final String sortType = "desc";
private final String indexName = "idx.opac";
private final String sortField = "relevance";
private final List<QueryFieldListItem> queryFieldList = new ArrayList<>(1);
private int pageSize;
private int page;
public SearchRequest(String keyWord, int pageSize, int page) {
this.pageSize = pageSize;
this.page = page;
this.queryFieldList.add(new QueryFieldListItem(keyWord));
}
@Data
public static class QueryFieldListItem {
private final String field = "all";
private final String operator = "*";
private final int logic = 0;
private final List<String> values = new ArrayList<>(1);
public QueryFieldListItem(String keyWord) {
values.add(keyWord);
}
}
}

@ -1,30 +0,0 @@
package cn.linghang.mywust.core.request.factory.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;
}
}

@ -1,30 +0,0 @@
package cn.linghang.mywust.core.request.factory.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;
}
}

@ -1,30 +0,0 @@
package cn.linghang.mywust.core.request.factory.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;
}
}

@ -1,49 +0,0 @@
package cn.linghang.mywust.core.request.factory.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;
}
}

@ -1,64 +0,0 @@
package cn.linghang.mywust.core.request.factory.library.response;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class Map<S, S1> {
@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;
}

@ -1,17 +0,0 @@
package cn.linghang.mywust.core.request.factory.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;
}
}

@ -1,150 +0,0 @@
package cn.linghang.mywust.core.request.factory.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<String> 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;
}
}

@ -8,7 +8,10 @@ import cn.linghang.mywust.network.entitys.HttpRequest;
import cn.linghang.mywust.util.StringUtil; import cn.linghang.mywust.util.StringUtil;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
public class BkjxRequestFactory extends RequestFactory { public class BkjxRequestFactory extends RequestFactory {
public static HttpRequest sessionCookieRequest(String serviceTicket) { public static HttpRequest sessionCookieRequest(String serviceTicket) {
@ -70,8 +73,13 @@ public class BkjxRequestFactory extends RequestFactory {
} }
public static HttpRequest courseTablePageRequest(String term, String cookies) { public static HttpRequest courseTablePageRequest(String term, String cookies) {
Map<String, String> params = new TreeMap<>(FormBodyBuilder.REPEATABLE_COMPARATOR); Map<String, String> params = new HashMap<>(7);
params.putAll(CourseTableRequestParamFactory.COURSE_TABLE_MAGIC_QUERY_PARAMS); params.put("jx0404id", "");
params.put("cj0701id", "");
params.put("zc", "");
params.put("demo", "");
params.put("sfFD", "1");
params.put("kbjcmsid", "9486203B90F3E3CBE0532914A8C03BE2");
params.put("xnxq01id", term); params.put("xnxq01id", term);
byte[] queryData = StringUtil.generateQueryString(params).getBytes(StandardCharsets.UTF_8); byte[] queryData = StringUtil.generateQueryString(params).getBytes(StandardCharsets.UTF_8);

@ -1,56 +0,0 @@
package cn.linghang.mywust.core.request.factory.undergrade;
import cn.linghang.mywust.network.entitys.FormBodyBuilder;
import java.util.Map;
/**
* <p>课表请求参数生成</p>
* <p>由于请求参数生成部分过于庞大和丑陋不适合放在总的Factory因此单独拎出来了</p>
*
* @author lensfrex
* @create 2022-10-27 10:17
*/
public class CourseTableRequestParamFactory {
// 课表请求的谜之参数,貌似是固定的
// 其实都可以靠解析html中id为Form1的表单获得(input和select两种所有元素的值),这样可以防止系统作妖改掉这些值
// 但为了快速起见,免去重复解析,直接使用也是没有什么大问题的,估计在很长的一段时间内这部分都是不会改的
protected static final Map<String, String> COURSE_TABLE_MAGIC_QUERY_PARAMS = generateMagicQueryParam();
private static final String MAGIC_PARAM_PREFIX_0 = "7DF471C4FF954CFA9C691580B8214B36-";
private static final String MAGIC_PARAM_PREFIX_1 = "EEBED1036A7B4991BF01CBFD47908031-";
private static final String MAGIC_PARAM_PREFIX_2 = "711BA240F1B0462C9359E3CC28D57EBE-";
private static final String MAGIC_PARAM_PREFIX_3 = "2A9E45FD425B477AB74272EF70478E1A-";
private static final String MAGIC_PARAM_PREFIX_4 = "91826EDF3A594498A9F761D685EEAE96-";
private static final String MAGIC_PARAM_PREFIX_5 = "ACC171586F9245B09C86C589102423B4-";
private static Map<String, String> generateMagicQueryParam() {
FormBodyBuilder formBodyBuilder = new FormBodyBuilder(true);
for (int i = 0; i < 6; i++) {
formBodyBuilder
.add("jx0415zbdiv_1", MAGIC_PARAM_PREFIX_0 + i + "-1")
.add("jx0415zbdiv_1", MAGIC_PARAM_PREFIX_1 + i + "-1")
.add("jx0415zbdiv_1", MAGIC_PARAM_PREFIX_2 + i + "-1")
.add("jx0415zbdiv_1", MAGIC_PARAM_PREFIX_3 + i + "-1")
.add("jx0415zbdiv_1", MAGIC_PARAM_PREFIX_4 + i + "-1")
.add("jx0415zbdiv_1", MAGIC_PARAM_PREFIX_5 + i + "-1")
.add("jx0415zbdiv_2", MAGIC_PARAM_PREFIX_0 + i + "-2")
.add("jx0415zbdiv_2", MAGIC_PARAM_PREFIX_1 + i + "-2")
.add("jx0415zbdiv_2", MAGIC_PARAM_PREFIX_2 + i + "-2")
.add("jx0415zbdiv_2", MAGIC_PARAM_PREFIX_3 + i + "-2")
.add("jx0415zbdiv_2", MAGIC_PARAM_PREFIX_4 + i + "-2")
.add("jx0415zbdiv_2", MAGIC_PARAM_PREFIX_5 + i + "-2");
}
formBodyBuilder
.add("jx0404id", "")
.add("cj0701id", "")
.add("zc", "")
.add("demo", "")
.add("sfFD", "1")
.add("kbjcmsid", "9486203B90F3E3CBE0532914A8C03BE2");
return formBodyBuilder.build();
}
}

@ -46,10 +46,7 @@ public class LibraryLogin {
HttpRequest testRequest = LibraryRequestFactory.makeHttpRequest(LibraryUrls.LIBRARY_COOKIE_TEST_URL, null, cookies); HttpRequest testRequest = LibraryRequestFactory.makeHttpRequest(LibraryUrls.LIBRARY_COOKIE_TEST_URL, null, cookies);
HttpResponse testResponse = requester.get(testRequest, option); HttpResponse testResponse = requester.get(testRequest, option);
// 响应居然是JSON,好评! // cookie不正确的话状态码会是401,而不是200
// 但是我们只要看是不是Unauthorized就行了 return testResponse.getStatusCode() == 200;
// 未认证的话是Unauthorized(如果人家没有抽风改掉的话)
byte[] responseData = testResponse.getBody();
return responseData != null && !new String(responseData).equalsIgnoreCase("Unauthorized");
} }
} }

@ -0,0 +1,66 @@
package cn.linghang.mywust.core.request.service.library;
import cn.linghang.mywust.core.exception.ApiException;
import cn.linghang.mywust.core.request.factory.library.LibraryRequestFactory;
import cn.linghang.mywust.network.Requester;
import cn.linghang.mywust.network.entitys.HttpRequest;
import cn.linghang.mywust.network.entitys.HttpResponse;
import java.io.IOException;
/**
* 图书馆相关接口由于返回的数据都是json特别好解析所以这里的数据获取到了之后可以直接拿来用自己来解析
*/
public class LibraryApiService extends LibraryApiServiceBase {
public LibraryApiService(Requester requester) {
super(requester);
}
public String search(String keyword, int page, int pageSize) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.bookSearchRequest(keyword, page, pageSize);
HttpResponse response = requester.post(request);
checkResponse(response);
return request.getStringData();
}
public String getBookDetail(String bookId) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.bookInfoRequest(bookId);
HttpResponse response = requester.post(request);
checkResponse(response);
return request.getStringData();
}
public String getBookCoverImageUrl(String isbn) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.bookCoverImageUrlRequest(isbn);
HttpResponse response = requester.post(request);
checkResponse(response);
return request.getStringData();
}
public String getOverdueSoon(String cookie) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.overdueSoonRequest(cookie);
HttpResponse response = requester.post(request);
checkResponse(response);
return request.getStringData();
}
public String getCurrentLoan(String cookie) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.currentLoanRequest(cookie);
HttpResponse response = requester.post(request);
checkResponse(response);
return request.getStringData();
}
public String getLoanHistory(String cookie) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.loanHistoryRequest(cookie);
HttpResponse response = requester.post(request);
checkResponse(response);
return request.getStringData();
}
}

@ -0,0 +1,20 @@
package cn.linghang.mywust.core.request.service.library;
import cn.linghang.mywust.core.exception.ApiException;
import cn.linghang.mywust.network.Requester;
import cn.linghang.mywust.network.entitys.HttpResponse;
public abstract class LibraryApiServiceBase {
protected final Requester requester;
public LibraryApiServiceBase(Requester requester) {
this.requester = requester;
}
public void checkResponse(HttpResponse response) throws ApiException {
// 检查响应是否正确
if (response.getStatusCode() != 200) {
throw new ApiException(ApiException.Code.COOKIE_INVALID);
}
}
}

@ -9,8 +9,8 @@ import cn.linghang.mywust.network.entitys.HttpResponse;
import java.io.IOException; import java.io.IOException;
public class PhysicsCourseApiServiceBase extends PhysicsApiServiceBase { public class PhysicsCourseApiService extends PhysicsApiServiceBase {
public PhysicsCourseApiServiceBase(Requester requester) { public PhysicsCourseApiService(Requester requester) {
super(requester); super(requester);
} }

@ -15,11 +15,11 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class PhysicsScoreApiServiceBase extends PhysicsApiServiceBase { public class PhysicsScoreApiService extends PhysicsApiServiceBase {
private static final PhysicsScoreListPageParser scoreListPageParser = new PhysicsScoreListPageParser(); private static final PhysicsScoreListPageParser scoreListPageParser = new PhysicsScoreListPageParser();
public PhysicsScoreApiServiceBase(Requester requester) { public PhysicsScoreApiService(Requester requester) {
super(requester); super(requester);
} }
Loading…
Cancel
Save