mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-06 04:18:07 +00:00
update 补全 接口文档注解 调整返回类型为 R
This commit is contained in:
@@ -1,37 +1,38 @@
|
||||
package com.ruoyi.gateway.handler;
|
||||
|
||||
import com.ruoyi.common.core.exception.CaptchaException;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.gateway.service.ValidateCodeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
import org.springframework.web.reactive.function.server.HandlerFunction;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 验证码获取
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class ValidateCodeHandler implements HandlerFunction<ServerResponse> {
|
||||
@Autowired
|
||||
private ValidateCodeService validateCodeService;
|
||||
|
||||
@Override
|
||||
public Mono<ServerResponse> handle(ServerRequest serverRequest) {
|
||||
AjaxResult ajax;
|
||||
try {
|
||||
ajax = validateCodeService.createCapcha();
|
||||
} catch (CaptchaException | IOException e) {
|
||||
return Mono.error(e);
|
||||
}
|
||||
return ServerResponse.status(HttpStatus.OK).body(BodyInserters.fromValue(ajax));
|
||||
}
|
||||
}
|
||||
package com.ruoyi.gateway.handler;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.exception.CaptchaException;
|
||||
import com.ruoyi.gateway.service.ValidateCodeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
import org.springframework.web.reactive.function.server.HandlerFunction;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 验证码获取
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class ValidateCodeHandler implements HandlerFunction<ServerResponse> {
|
||||
@Autowired
|
||||
private ValidateCodeService validateCodeService;
|
||||
|
||||
@Override
|
||||
public Mono<ServerResponse> handle(ServerRequest serverRequest) {
|
||||
R<Map<String, Object>> ajax;
|
||||
try {
|
||||
ajax = validateCodeService.createCapcha();
|
||||
} catch (CaptchaException | IOException e) {
|
||||
return Mono.error(e);
|
||||
}
|
||||
return ServerResponse.status(HttpStatus.OK).body(BodyInserters.fromValue(ajax));
|
||||
}
|
||||
}
|
||||
|
@@ -1,23 +1,24 @@
|
||||
package com.ruoyi.gateway.service;
|
||||
|
||||
import com.ruoyi.common.core.exception.CaptchaException;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 验证码处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ValidateCodeService {
|
||||
/**
|
||||
* 生成验证码
|
||||
*/
|
||||
AjaxResult createCapcha() throws IOException, CaptchaException;
|
||||
|
||||
/**
|
||||
* 校验验证码
|
||||
*/
|
||||
void checkCapcha(String key, String value) throws CaptchaException;
|
||||
}
|
||||
package com.ruoyi.gateway.service;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.exception.CaptchaException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 验证码处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ValidateCodeService {
|
||||
/**
|
||||
* 生成验证码
|
||||
*/
|
||||
R<Map<String, Object>> createCapcha() throws IOException, CaptchaException;
|
||||
|
||||
/**
|
||||
* 校验验证码
|
||||
*/
|
||||
void checkCapcha(String key, String value) throws CaptchaException;
|
||||
}
|
||||
|
@@ -5,11 +5,11 @@ import cn.hutool.captcha.generator.CodeGenerator;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.exception.CaptchaException;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.reflect.ReflectUtils;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.redis.utils.RedisUtils;
|
||||
import com.ruoyi.gateway.config.properties.CaptchaProperties;
|
||||
import com.ruoyi.gateway.enums.CaptchaType;
|
||||
@@ -18,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@@ -34,12 +36,12 @@ public class ValidateCodeServiceImpl implements ValidateCodeService {
|
||||
* 生成验证码
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult createCapcha() throws IOException, CaptchaException {
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
public R<Map<String, Object>> createCapcha() throws IOException, CaptchaException {
|
||||
Map<String, Object> ajax = new HashMap<>();
|
||||
boolean captchaOnOff = captchaProperties.getEnabled();
|
||||
ajax.put("captchaOnOff", captchaOnOff);
|
||||
if (!captchaOnOff) {
|
||||
return ajax;
|
||||
return R.ok(ajax);
|
||||
}
|
||||
|
||||
// 保存验证码信息
|
||||
@@ -57,7 +59,7 @@ public class ValidateCodeServiceImpl implements ValidateCodeService {
|
||||
RedisUtils.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
|
||||
ajax.put("uuid", uuid);
|
||||
ajax.put("img", captcha.getImageBase64());
|
||||
return ajax;
|
||||
return R.ok(ajax);
|
||||
}
|
||||
|
||||
private String getCodeResult(String capStr) {
|
||||
|
Reference in New Issue
Block a user