mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 12:18:42 +08:00 
			
		
		
		
	refactor: captcha-plus
This commit is contained in:
		@@ -1,10 +1,8 @@
 | 
			
		||||
package cn.iocoder.yudao.module.system.controller.admin.captcha;
 | 
			
		||||
 | 
			
		||||
import cn.hutool.core.util.StrUtil;
 | 
			
		||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
 | 
			
		||||
import com.anji.captcha.model.common.ResponseModel;
 | 
			
		||||
import com.anji.captcha.model.vo.CaptchaVO;
 | 
			
		||||
import com.anji.captcha.service.CaptchaService;
 | 
			
		||||
import io.swagger.annotations.Api;
 | 
			
		||||
import io.swagger.annotations.ApiOperation;
 | 
			
		||||
import org.springframework.web.bind.annotation.PostMapping;
 | 
			
		||||
@@ -12,7 +10,6 @@ import org.springframework.web.bind.annotation.RequestBody;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.RestController;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Resource;
 | 
			
		||||
import javax.annotation.security.PermitAll;
 | 
			
		||||
import javax.servlet.http.HttpServletRequest;
 | 
			
		||||
 | 
			
		||||
@@ -27,19 +24,14 @@ import javax.servlet.http.HttpServletRequest;
 | 
			
		||||
@Api(tags = "管理后台 - 验证码")
 | 
			
		||||
@RestController("adminCaptchaController")
 | 
			
		||||
@RequestMapping("/system/captcha")
 | 
			
		||||
public class CaptchaController {
 | 
			
		||||
 | 
			
		||||
    @Resource
 | 
			
		||||
    private CaptchaService captchaService;
 | 
			
		||||
public class CaptchaController extends com.anji.captcha.controller.CaptchaController {
 | 
			
		||||
 | 
			
		||||
    @PostMapping({"/get"})
 | 
			
		||||
    @ApiOperation("获得验证码")
 | 
			
		||||
    @PermitAll
 | 
			
		||||
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
 | 
			
		||||
    public ResponseModel get(@RequestBody CaptchaVO data, HttpServletRequest request) {
 | 
			
		||||
        assert request.getRemoteHost() != null;
 | 
			
		||||
        data.setBrowserInfo(getRemoteId(request));
 | 
			
		||||
        return captchaService.get(data);
 | 
			
		||||
        return super.get(data, request);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/check")
 | 
			
		||||
@@ -47,26 +39,7 @@ public class CaptchaController {
 | 
			
		||||
    @PermitAll
 | 
			
		||||
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
 | 
			
		||||
    public ResponseModel check(@RequestBody CaptchaVO data, HttpServletRequest request) {
 | 
			
		||||
        data.setBrowserInfo(getRemoteId(request));
 | 
			
		||||
        return captchaService.check(data);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String getRemoteId(HttpServletRequest request) {
 | 
			
		||||
        String xfwd = request.getHeader("X-Forwarded-For");
 | 
			
		||||
        String ip = getRemoteIpFromXfwd(xfwd);
 | 
			
		||||
        String ua = request.getHeader("user-agent");
 | 
			
		||||
        if (StrUtil.isNotBlank(ip)) {
 | 
			
		||||
            return ip + ua;
 | 
			
		||||
        }
 | 
			
		||||
        return request.getRemoteAddr() + ua;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static String getRemoteIpFromXfwd(String xfwd) {
 | 
			
		||||
        if (StrUtil.isNotBlank(xfwd)) {
 | 
			
		||||
            String[] ipList = xfwd.split(",");
 | 
			
		||||
            return StrUtil.trim(ipList[0]);
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
        return super.check(data, request);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user