滑动验证码,通过用户行为分析是否是真人操作,比图形验证码更能让用户接受。
public interface FwCaptchaClient {
public boolean verify(String raw, String userIp);
}
raw: 前端传过来的原始报文
support包中默认提供 AjOpenSourceFwCaptchaClient、QCloudFwCaptchaClient 两种不同的验证码,QCloud是腾讯云的,是需要收费的,AjOpenSource则是开源项目,dobbinfw将其集成进来,推荐使用AjOpenSource。
在启动类上加上 @EnableCaptcha 注解
@EnableCaptcha
public class UcProviderApplication {
FwCaptchaProperties 在Properties中,选择实现类 enable=aj 或 qcloud
@Autowired
private FwCaptchaClient captchaClient;
public String sendVerifyCode(Integer scene, String phone, String ip, String captchaRaw) throws ServiceException {
// 验证滑动验证码
if (!captchaClient.verify(captchaRaw, ip)) {
throw new AdminServiceException(ExceptionDefinition.ADMIN_CAPTCHA_ERROR);
}