24
24
import cn .hutool .core .util .RandomUtil ;
25
25
import cn .hutool .core .util .StrUtil ;
26
26
import cn .hutool .extra .servlet .JakartaServletUtil ;
27
+ import cn .hutool .extra .spring .SpringUtil ;
27
28
import com .anji .captcha .model .common .RepCodeEnum ;
28
29
import com .anji .captcha .model .common .ResponseModel ;
29
30
import com .anji .captcha .model .vo .CaptchaVO ;
@@ -86,7 +87,6 @@ public class CaptchaController {
86
87
87
88
private final ApplicationProperties applicationProperties ;
88
89
private final CaptchaProperties captchaProperties ;
89
- private final CaptchaService behaviorCaptchaService ;
90
90
private final GraphicCaptchaService graphicCaptchaService ;
91
91
private final OptionService optionService ;
92
92
private final SmsConfigService smsConfigService ;
@@ -95,6 +95,7 @@ public class CaptchaController {
95
95
@ Operation (summary = "获取行为验证码" , description = "获取行为验证码(Base64编码)" )
96
96
@ GetMapping ("/behavior" )
97
97
public Object getBehaviorCaptcha (CaptchaVO captchaReq , HttpServletRequest request ) {
98
+ CaptchaService behaviorCaptchaService = SpringUtil .getBean (CaptchaService .class );
98
99
captchaReq .setBrowserInfo (JakartaServletUtil .getClientIP (request ) + request .getHeader (HttpHeaders .USER_AGENT ));
99
100
ResponseModel responseModel = behaviorCaptchaService .get (captchaReq );
100
101
CheckUtils .throwIf (() -> !StrUtil .equals (RepCodeEnum .SUCCESS .getCode (), responseModel
@@ -106,6 +107,7 @@ public Object getBehaviorCaptcha(CaptchaVO captchaReq, HttpServletRequest reques
106
107
@ Operation (summary = "校验行为验证码" , description = "校验行为验证码" )
107
108
@ PostMapping ("/behavior" )
108
109
public Object checkBehaviorCaptcha (@ RequestBody CaptchaVO captchaReq , HttpServletRequest request ) {
110
+ CaptchaService behaviorCaptchaService = SpringUtil .getBean (CaptchaService .class );
109
111
captchaReq .setBrowserInfo (JakartaServletUtil .getClientIP (request ) + request .getHeader (HttpHeaders .USER_AGENT ));
110
112
return behaviorCaptchaService .check (captchaReq );
111
113
}
@@ -152,6 +154,7 @@ public CaptchaResp getImageCaptcha() {
152
154
public R getMailCaptcha (@ NotBlank (message = "邮箱不能为空" ) @ Email (message = "邮箱格式不正确" ) String email ,
153
155
CaptchaVO captchaReq ) throws MessagingException {
154
156
// 行为验证码校验
157
+ CaptchaService behaviorCaptchaService = SpringUtil .getBean (CaptchaService .class );
155
158
ResponseModel verificationRes = behaviorCaptchaService .verification (captchaReq );
156
159
ValidationUtils .throwIfNotEqual (verificationRes .getRepCode (), RepCodeEnum .SUCCESS .getCode (), verificationRes
157
160
.getRepMsg ());
@@ -198,6 +201,7 @@ public R getMailCaptcha(@NotBlank(message = "邮箱不能为空") @Email(message
198
201
@ RateLimiter (name = CacheConstants .CAPTCHA_KEY_PREFIX , key = "#phone" , rate = 30 , interval = 1 , unit = TimeUnit .MINUTES , type = LimitType .IP , message = "获取验证码操作太频繁,请稍后再试" )})
199
202
public R getSmsCaptcha (@ NotBlank (message = "手机号不能为空" ) @ Mobile String phone , CaptchaVO captchaReq ) {
200
203
// 行为验证码校验
204
+ CaptchaService behaviorCaptchaService = SpringUtil .getBean (CaptchaService .class );
201
205
ResponseModel verificationRes = behaviorCaptchaService .verification (captchaReq );
202
206
ValidationUtils .throwIfNotEqual (verificationRes .getRepCode (), RepCodeEnum .SUCCESS .getCode (), verificationRes
203
207
.getRepMsg ());
0 commit comments