diff --git a/src/main/java/com/cool/core/plugin/consts/PluginConsts.java b/src/main/java/com/cool/core/plugin/consts/PluginConsts.java index d0d1ddb..eb07fee 100644 --- a/src/main/java/com/cool/core/plugin/consts/PluginConsts.java +++ b/src/main/java/com/cool/core/plugin/consts/PluginConsts.java @@ -10,6 +10,11 @@ public interface PluginConsts { */ String uploadHook = "upload"; + /** + * 验证码hook + */ + String captchaHook = "captcha"; + /** * 插件调用入口方法 */ diff --git a/src/main/java/com/cool/modules/base/controller/admin/AdminBaseOpenController.java b/src/main/java/com/cool/modules/base/controller/admin/AdminBaseOpenController.java index 584578e..ed87680 100644 --- a/src/main/java/com/cool/modules/base/controller/admin/AdminBaseOpenController.java +++ b/src/main/java/com/cool/modules/base/controller/admin/AdminBaseOpenController.java @@ -1,14 +1,26 @@ package com.cool.modules.base.controller.admin; +import static com.cool.core.plugin.consts.PluginConsts.captchaHook; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ObjUtil; +import cn.hutool.json.JSONObject; import com.cool.core.annotation.CoolRestController; +import com.cool.core.cache.CoolCache; import com.cool.core.enums.UserTypeEnum; import com.cool.core.eps.CoolEps; +import com.cool.core.plugin.service.CoolPluginService; import com.cool.core.request.R; +import com.cool.core.util.CoolPluginInvokers; import com.cool.modules.base.dto.sys.BaseSysLoginDto; import com.cool.modules.base.service.sys.BaseSysLoginService; +import com.cool.modules.plugin.entity.PluginInfoEntity; +import io.micrometer.common.util.StringUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.Map; +import java.util.concurrent.ThreadLocalRandom; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; @@ -21,8 +33,9 @@ import org.springframework.web.bind.annotation.*; public class AdminBaseOpenController { final private BaseSysLoginService baseSysLoginService; - + final private CoolPluginService coolPluginService; final private CoolEps coolEps; + final private CoolCache coolCache; @Operation(summary = "实体信息与路径", description = "系统所有的实体信息与路径,供前端自动生成代码与服务") @GetMapping("/eps") @@ -55,4 +68,54 @@ public class AdminBaseOpenController { public R refreshToken(String refreshToken) { return R.ok(baseSysLoginService.refreshToken(refreshToken)); } + + @RequestMapping("/gen") + @ResponseBody + public Object genCaptcha(@RequestParam(value = "type", required = false)String type) { + if (StringUtils.isBlank(type)) { + type = "SLIDER"; + } + if ("RANDOM".equals(type)) { + int i = ThreadLocalRandom.current().nextInt(0, 4); + if (i == 0) { + type = "SLIDER"; + } else if (i == 1) { + type = "CONCAT"; + } else if (i == 2) { + type = "ROTATE"; + } else{ + type = "WORD_IMAGE_CLICK"; + } + + } + return CoolPluginInvokers.invoke("tianai", "generateCaptcha", type); + } + + @PostMapping("/check") + @ResponseBody + public Object checkCaptcha(@RequestAttribute() JSONObject requestParams) { + Object result = CoolPluginInvokers.invoke("tianai", "matching", requestParams); + Map map = BeanUtil.beanToMap(result); + if (ObjUtil.equals(map.get("code"), 200)) { + String code = ThreadLocalRandom.current().nextInt(100000, 999999) + ""; + coolCache.set("verify:img:" + requestParams.getStr("id"), code, 1800); + R r = new R(); + r.put("data", Map.of("id", requestParams.getStr("id"), + "code", code)); + r.put("code", map.get("code")); + return r; + } + return result; + } + + @Operation(summary = "验证码类型") + @GetMapping("/captchaMode") + public R captchaMode() { + PluginInfoEntity pluginInfoEntity = coolPluginService.getPluginInfoEntityByHook( + captchaHook); + if (pluginInfoEntity != null) { + return R.ok(CoolPluginInvokers.invoke(pluginInfoEntity.getKey(), "getMode")); + } + return R.ok(Map.of("mode", "common")); + } } diff --git a/src/main/resources/cool/captcha/bgimages/48.jpg b/src/main/resources/cool/captcha/bgimages/48.jpg new file mode 100644 index 0000000..ae731e4 Binary files /dev/null and b/src/main/resources/cool/captcha/bgimages/48.jpg differ diff --git a/src/main/resources/cool/captcha/bgimages/a.jpg b/src/main/resources/cool/captcha/bgimages/a.jpg new file mode 100644 index 0000000..cef38ec Binary files /dev/null and b/src/main/resources/cool/captcha/bgimages/a.jpg differ diff --git a/src/main/resources/cool/captcha/bgimages/b.jpg b/src/main/resources/cool/captcha/bgimages/b.jpg new file mode 100644 index 0000000..72fdb56 Binary files /dev/null and b/src/main/resources/cool/captcha/bgimages/b.jpg differ diff --git a/src/main/resources/cool/captcha/bgimages/c.jpg b/src/main/resources/cool/captcha/bgimages/c.jpg new file mode 100644 index 0000000..7c8274f Binary files /dev/null and b/src/main/resources/cool/captcha/bgimages/c.jpg differ diff --git a/src/main/resources/cool/captcha/bgimages/d.jpg b/src/main/resources/cool/captcha/bgimages/d.jpg new file mode 100644 index 0000000..6057faa Binary files /dev/null and b/src/main/resources/cool/captcha/bgimages/d.jpg differ diff --git a/src/main/resources/cool/captcha/bgimages/e.jpg b/src/main/resources/cool/captcha/bgimages/e.jpg new file mode 100644 index 0000000..b5e22e3 Binary files /dev/null and b/src/main/resources/cool/captcha/bgimages/e.jpg differ diff --git a/src/main/resources/cool/captcha/bgimages/g.jpg b/src/main/resources/cool/captcha/bgimages/g.jpg new file mode 100644 index 0000000..ae707ba Binary files /dev/null and b/src/main/resources/cool/captcha/bgimages/g.jpg differ diff --git a/src/main/resources/cool/captcha/bgimages/h.jpg b/src/main/resources/cool/captcha/bgimages/h.jpg new file mode 100644 index 0000000..2326c88 Binary files /dev/null and b/src/main/resources/cool/captcha/bgimages/h.jpg differ diff --git a/src/main/resources/cool/captcha/bgimages/i.jpg b/src/main/resources/cool/captcha/bgimages/i.jpg new file mode 100644 index 0000000..f9714d9 Binary files /dev/null and b/src/main/resources/cool/captcha/bgimages/i.jpg differ diff --git a/src/main/resources/cool/captcha/bgimages/j.jpg b/src/main/resources/cool/captcha/bgimages/j.jpg new file mode 100644 index 0000000..8f9056f Binary files /dev/null and b/src/main/resources/cool/captcha/bgimages/j.jpg differ