Procházet zdrojové kódy

修改滑块验证码服务以及放端口

nahida před 1 rokem
rodič
revize
cc0c114c2f

+ 31 - 27
zksy-admin/src/main/java/com/zksy/web/controller/basicData/OwLeavingMessageController.java

@@ -8,12 +8,15 @@ import com.zksy.common.enums.BusinessType;
 import com.zksy.common.utils.StringUtils;
 import com.zksy.common.utils.file.ExcelUtils;
 import com.zksy.system.basicData.domain.OwLeavingMessage;
+import com.zksy.system.basicData.domain.dto.OwLeavingMessageDTO;
 import com.zksy.system.basicData.service.CaptchaService;
 import com.zksy.system.basicData.service.OwLeavingMessageService;
 import com.zksy.utils.DowntemplateUtil;
 import com.zksy.utils.SearchUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.aspectj.weaver.loadtime.Aj;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -21,6 +24,7 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -32,7 +36,7 @@ import java.util.List;
 @RestController
 @RequestMapping("/owLeavingMessage")
 @Api(tags = "官网留言", description = "官网留言desc")
-public class OwLeavingMessageController extends BaseController{
+public class OwLeavingMessageController extends BaseController {
 
     @Autowired
     private OwLeavingMessageService service;
@@ -62,19 +66,21 @@ public class OwLeavingMessageController extends BaseController{
      */
     @PostMapping("/save")
     @ApiOperation(value = "官网留言新增")
-    @Log(title = "新增官网留言", businessType = BusinessType.INSERT)
-    public AjaxResult save(@RequestBody OwLeavingMessage owLeavingMessage) {
-        if (owLeavingMessage.getNeedAuthCode()) {
-            String msg = captchaService.checkImageCode(owLeavingMessage.getImageKey(),owLeavingMessage.getImageCode());
-            if (StringUtils.isNotBlank(msg)) {
-                return AjaxResult.error(msg);
-            }
+//    @Log(title = "新增官网留言", businessType = BusinessType.INSERT)
+    public AjaxResult save(@RequestBody OwLeavingMessageDTO dto) {
+//        if (dto.getNeedAuthCode()) {
+        String msg = captchaService.checkImageCode(dto.getImageKey(), dto.getImageCode());
+        if (StringUtils.isNotBlank(msg)) {
+            return AjaxResult.error(999,msg);
         }
+//        }
+        OwLeavingMessage owLeavingMessage = new OwLeavingMessage();
+        BeanUtils.copyProperties(dto, owLeavingMessage);
         owLeavingMessage.setCreateTime(new Date());
         Boolean flag = service.save(owLeavingMessage);
-        if(flag){
+        if (flag) {
             return AjaxResult.success("留言成功");
-        }else {
+        } else {
             return AjaxResult.success("留言失败");
         }
     }
@@ -96,21 +102,20 @@ public class OwLeavingMessageController extends BaseController{
     @ApiOperation("官网留言导入")
     @Log(title = "官网留言", businessType = BusinessType.IMPORT)
     @PostMapping("/importData")
-    public AjaxResult importData(MultipartFile file)
-    {
+    public AjaxResult importData(MultipartFile file) {
         try {
             List<OwLeavingMessage> owLeavingMessageAll = service.list();
-            List<OwLeavingMessage> list = ExcelUtils.readMultipartFile(file, OwLeavingMessage.class,OwLeavingMessage.class.getDeclaredFields().length - 2);
-            if(owLeavingMessageAll != null && owLeavingMessageAll.size() > 0){
+            List<OwLeavingMessage> list = ExcelUtils.readMultipartFile(file, OwLeavingMessage.class, OwLeavingMessage.class.getDeclaredFields().length - 2);
+            if (owLeavingMessageAll != null && owLeavingMessageAll.size() > 0) {
                 //return AjaxResult.error("数据已存在,如需重新导入请清空数据");
             }
-            if(list.size() > 0){
+            if (list.size() > 0) {
                 service.saveBatch(list);
-                return success("导入成功,共计:"+list.size()+"条");
-            }else{
+                return success("导入成功,共计:" + list.size() + "条");
+            } else {
                 return AjaxResult.error("无数据");
             }
-        }catch (Exception e){
+        } catch (Exception e) {
             e.printStackTrace();
             return AjaxResult.error("导入数据失败");
         }
@@ -119,12 +124,12 @@ public class OwLeavingMessageController extends BaseController{
     @ApiOperation("官网留言导出")
     @Log(title = "官网留言", businessType = BusinessType.EXPORT)
     @PostMapping("/exportData")
-    public AjaxResult exportData(HttpServletResponse response, String conditionJson){
+    public AjaxResult exportData(HttpServletResponse response, String conditionJson) {
         try {
             List<OwLeavingMessage> wrapperList = service.list(SearchUtil.parseWhereSql(conditionJson));
-            ExcelUtils.export(response,"官网留言",wrapperList,OwLeavingMessage.class);
+            ExcelUtils.export(response, "官网留言", wrapperList, OwLeavingMessage.class);
             return AjaxResult.success("导出数据成功");
-        }catch (Exception e){
+        } catch (Exception e) {
             e.printStackTrace();
             return AjaxResult.error("导出数据失败");
         }
@@ -133,26 +138,25 @@ public class OwLeavingMessageController extends BaseController{
     @Log(title = "官网留言", businessType = BusinessType.DELETE)
     @PostMapping("/delete")
     @ApiOperation(value = "删除官网留言", notes = "删除官网留言")
-    public AjaxResult delete(@RequestBody List<String> ids)
-    {
+    public AjaxResult delete(@RequestBody List<String> ids) {
         return toAjax(service.removeByIds(ids));
     }
 
     @DeleteMapping("/deleteAll")
     @ApiOperation(value = "清除数据", notes = "清除数据")
-    public AjaxResult deleteAll(){
+    public AjaxResult deleteAll() {
         return service.deleteAll();
     }
 
     @PostMapping("/getUploadTemplate")
     @ApiOperation(value = "获取上传模板", notes = "获取上传模板")
     public void getUploadTemplate(HttpServletResponse response) throws IOException {
-        DowntemplateUtil.downloadTemplate(response,"官网留言模板");
+        DowntemplateUtil.downloadTemplate(response, "官网留言模板");
     }
 
     @PostMapping("/generateVoucher")
-    public void generateVoucher(HttpServletResponse response,String name,Long id) throws Exception {
-        service.generateVoucher(response,name,id);
+    public void generateVoucher(HttpServletResponse response, String name, Long id) throws Exception {
+        service.generateVoucher(response, name, id);
     }
 }
 

+ 1 - 1
zksy-admin/src/main/java/com/zksy/web/controller/common/CaptchaSliderController.java

@@ -25,7 +25,7 @@ public class CaptchaSliderController {
 
     @ApiOperation(value = "生成验证码拼图")
     @PostMapping("getCaptcha")
-    public AjaxResult getCaptcha(@RequestBody Captcha captcha) {
+    public AjaxResult getCaptcha(@RequestBody(required = false) Captcha captcha) {
         return AjaxResult.success(captchaService.getCaptcha(captcha));
     }
 }

+ 2 - 2
zksy-admin/src/main/resources/application-druid.yml

@@ -84,7 +84,7 @@ spring:
   # redis 配置
   redis:
     # 地址
-    host: 127.0.0.1
+    host: 192.168.110.30
     # 端口,默认为6379
     port: 6379
     # 数据库索引
@@ -105,7 +105,7 @@ spring:
         max-wait: -1ms
   redisson:
     # 单机
-    address: 127.0.0.1:6379
+    address: 192.168.110.30:6379
     database: 10
     #password:
 

+ 24 - 0
zksy-admin/src/test/java/com/zksy/web/controller/common/CaptchaSliderControllerTest.java

@@ -0,0 +1,24 @@
+package com.zksy.web.controller.common;
+
+import com.zksy.system.basicData.domain.Captcha;
+import com.zksy.zksyApplication;
+import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@SpringBootTest(classes = zksyApplication.class)
+@RunWith(SpringRunner.class)
+public class CaptchaSliderControllerTest extends TestCase {
+    @Autowired
+    private CaptchaSliderController captchaSliderController;
+    @Test
+    public void testGetCaptcha() {
+        long l = System.currentTimeMillis();
+        System.out.println(captchaSliderController.getCaptcha(new Captcha()));
+        long a = System.currentTimeMillis();
+        System.out.println(a-l);
+    }
+}

+ 2 - 1
zksy-framework/src/main/java/com/zksy/framework/config/SecurityConfig.java

@@ -141,7 +141,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
                         "/crmComplain/save",
                         "/owSelfReporting/save",
                         "/commonFile/uploadFile",
-                        "/owLeavingMessage/save"
+                        "/owLeavingMessage/save",
+                        "/captchaSlider/getCaptcha"
                 ).permitAll()
                 .antMatchers("/swagger-ui.html").anonymous()
                 .antMatchers("/system/dict/data/selectSysDictDataAll").anonymous()

+ 4 - 0
zksy-system/src/main/java/com/zksy/system/basicData/domain/Captcha.java

@@ -1,8 +1,12 @@
 package com.zksy.system.basicData.domain;
 
+import lombok.AllArgsConstructor;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 @Data
+@AllArgsConstructor
+@NoArgsConstructor
 public class Captcha {
 
     /**

+ 0 - 6
zksy-system/src/main/java/com/zksy/system/basicData/domain/OwLeavingMessage.java

@@ -81,10 +81,4 @@ private static final long serialVersionUID=1L;
     private Date createTime;
     @ApiModelProperty(value = "更新时间")
     private Date updateTime;
-    @TableField(exist = false)
-    private String imageKey;
-    @TableField(exist = false)
-    private String imageCode;
-    @TableField(exist = false)
-    private Boolean needAuthCode;
         }

+ 19 - 0
zksy-system/src/main/java/com/zksy/system/basicData/domain/dto/OwLeavingMessageDTO.java

@@ -0,0 +1,19 @@
+package com.zksy.system.basicData.domain.dto;
+
+
+import com.zksy.system.basicData.domain.OwLeavingMessage;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class OwLeavingMessageDTO extends OwLeavingMessage {
+
+    private String imageKey;
+
+    private String imageCode;
+
+//    private Boolean needAuthCode;
+}

+ 8 - 3
zksy-system/src/main/java/com/zksy/system/utils/CaptchaUtils.java

@@ -24,7 +24,8 @@ public class CaptchaUtils {
     /**
      * 本地图片地址
      **/
-    private final static String IMG_PATH = "E:/Temp/wallpaper/%s.jpg";
+    private final static String IMG_PATH = "D:/Temp/%s.jpg";
+    private static int usedImgNumber;
 
     /**
      * 入参校验设置默认值
@@ -52,7 +53,7 @@ public class CaptchaUtils {
         }
         //设置图片来源默认值
         if (captcha.getPlace() == null) {
-            captcha.setPlace(0);
+            captcha.setPlace(1);
         }
     }
 
@@ -70,7 +71,11 @@ public class CaptchaUtils {
     public static BufferedImage getBufferedImage(Integer place) {
         try {
             //随机图片
-            int nonce = getNonceByRange(0, 1000);
+            int nonce = getNonceByRange(1, 10);
+            while (nonce == usedImgNumber){
+                nonce = getNonceByRange(1, 10);
+            }
+            usedImgNumber = nonce;
             //获取网络资源图片
             if (0 == place) {
                 String imgUrl = String.format(IMG_URL, nonce);