Skip to content

Commit 2a93edd

Browse files
committed
天加新的HTTP 状态码并修改kk-anti-reptile
1 parent af54de9 commit 2a93edd

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

src/main/java/com/company/project/core/ResultCode.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.company.project.core;
22

3+
import org.springframework.http.HttpStatus;
4+
35
/**
46
* 响应码枚举,参考HTTP状态码的语义
57
*
@@ -22,8 +24,8 @@ public enum ResultCode {
2224
/**接口不存在*/
2325
NOT_FOUND(404),
2426
/**服务器内部错误*/
25-
INTERNAL_SERVER_ERROR(500);
26-
27+
INTERNAL_SERVER_ERROR(500),
28+
BANDWIDTH_LIMIT_EXCEEDED(509);
2729
private final int code;
2830

2931
ResultCode(int code) {

src/main/java/com/company/project/kkantireptile/cn/keking/anti_reptile/config/AntiReptileProperties.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
/**
1010
* @author kl @kailing.pub
1111
* @since 2019/7/9
12+
*
13+
* @Editor:zhuoqianmingyue
14+
* @ModifiedDate: 2020/8/11
15+
* @Description:添加拦截提示类型
1216
*/
1317
@ConfigurationProperties(prefix = "anti.reptile.manager")
1418
public class AntiReptileProperties {
@@ -18,7 +22,7 @@ public class AntiReptileProperties {
1822
*/
1923
private boolean enabled;
2024
/**
21-
* 拦截类型 JSON、HTML
25+
* 拦截提示类型 JSON、HTML
2226
*/
2327
private String interceptionType = "HTML";
2428

src/main/java/com/company/project/kkantireptile/cn/keking/anti_reptile/interceptor/AntiReptileInterceptor.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
/**
3232
* @author chenjh
3333
* @since 2020/2/4 17:45
34+
*
35+
* @Editor:zhuoqianmingyue
36+
* @ModifiedDate: 2020/8/11
37+
* @Description:添加触发规则后JSON格式提醒
3438
*/
3539
public class AntiReptileInterceptor extends HandlerInterceptorAdapter {
3640

@@ -93,17 +97,17 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
9397

9498

9599
String data = "";
100+
response.setStatus(ResultCode.BANDWIDTH_LIMIT_EXCEEDED.code());
96101
if("JSON".equals(interceptionType)){
97-
response.setStatus(509);
102+
98103
response.setCharacterEncoding("UTF-8");
99104
response.setContentType("application/json; charset=utf-8");
100105
Result result = new Result();
101-
result.setCode(ResultCode.UNAUTHORIZED);
102-
result.setMessage("您访问的太频繁");
106+
result.setCode(ResultCode.BANDWIDTH_LIMIT_EXCEEDED);
107+
result.setMessage("您访问的太频繁或者改设备禁止访问!");
103108
JsonConvertUtil.toJson(result);
104109
}
105110
if("HTML".equals(interceptionType)){
106-
response.setStatus(509);
107111
response.setContentType("text/html;charset=utf-8");
108112
VerifyImageDTO verifyImage = verifyImageUtil.generateVerifyImg();
109113
verifyImageUtil.saveVerifyCodeToRedis(verifyImage);

0 commit comments

Comments
 (0)