|
@@ -0,0 +1,76 @@
|
|
|
|
+package com.ruoyi.web.controller.manage;
|
|
|
|
+
|
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
+import com.ruoyi.common.core.redis.RedisCache;
|
|
|
|
+import com.ruoyi.system.service.ISysConfigService;
|
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
+
|
|
|
|
+import static com.ruoyi.common.constant.Constants.*;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Author: tjf
|
|
|
|
+ * @Date: 2025/8/14 星期四 14:05
|
|
|
|
+ * @Describe:
|
|
|
|
+ */
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/manage/common")
|
|
|
|
+public class ManageCommonController {
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisCache redisCache;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysConfigService sysConfigService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生产6位数动态码
|
|
|
|
+ */
|
|
|
|
+ @GetMapping("/getDynamicPassword")
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('manage:common:getDynamicPassword')")
|
|
|
|
+ public AjaxResult warnManageIndex() {
|
|
|
|
+ String code = getCode(6);
|
|
|
|
+ redisCache.setCacheObject(DYNAMIC_PASSWORD + code, code, CAPTCHA_EXPIRATION_FIVE, TimeUnit.MINUTES);
|
|
|
|
+ return AjaxResult.success("操作成功", code);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 验证6位数动态码
|
|
|
|
+ */
|
|
|
|
+ @GetMapping("/checkDynamicPassword/{code}")
|
|
|
|
+ public AjaxResult warnManageIndex(@PathVariable("code") String code) {
|
|
|
|
+ Object codeRedis = redisCache.getCacheObject(DYNAMIC_PASSWORD + code);
|
|
|
|
+ if (ObjectUtils.isNotEmpty(codeRedis)) {
|
|
|
|
+ if (code.equals(codeRedis)) {
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //匹配固定密码
|
|
|
|
+ String passWord = sysConfigService.selectConfigByKey(SYS_DYNAMIC_PASSWORD);
|
|
|
|
+ if (StringUtils.isNotEmpty(passWord)) {
|
|
|
|
+ if (StringUtils.equals(passWord, code)) {
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return AjaxResult.error();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //生成X位验证码
|
|
|
|
+ public static String getCode(Integer num) {
|
|
|
|
+ String[] codes = {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"};
|
|
|
|
+ StringBuilder code = new StringBuilder();
|
|
|
|
+ for (int i = 0; i < num; i++) {
|
|
|
|
+ int j = (int) (Math.random() * 10);
|
|
|
|
+ code.append(codes[j]);
|
|
|
|
+ }
|
|
|
|
+ return code.toString();
|
|
|
|
+ }
|
|
|
|
+}
|