通过粗暴地比较响应字节前几个字符是否为登录跳转特征字符判断是否需要重新登录
+ *只比较前若干个字节,在数据较大时比较有用
*对于null对象,一律认为不需要
* * @param response 响应的字节 * @return 是否需要重新登录 */ - public static boolean hasLoginFinger(byte[] response) { + public static boolean needLogin(byte[] response) { if (response == null) { return false; } @@ -29,4 +32,39 @@ public class BkjxUtil { return true; } + + /** + *检查是否为专属选课时间封号
+ *对于null对象,一律认为不是
+ * + * @param response HttpResponse响应 + * @return 是否为封号响应 + */ + public static boolean isBannedResponse(HttpResponse response) { + if (response == null || response.getBody() == null) { + return false; + } + + // 这里用了个取巧的办法,如果响应体大于400bytes,则直接认为不是封号的响应,不继续比较关键字 + if (response.getBody().length > 400) { + return false; + } + + return isBannedResponse(response.getStringBody()); + } + + /** + *检查是否为专属选课时间封号
+ *对于null对象,一律认为不是
+ * + * @param responseText 响应字符串 + * @return 是否为封号响应 + */ + public static boolean isBannedResponse(String responseText) { + if (responseText == null) { + return false; + } + + return responseText.contains("当前登录帐号已被禁用"); + } }