From f84d149459b73928c864eb5aebf764cf58105c73 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期三, 07 五月 2025 16:11:24 +0800
Subject: [PATCH] 命令生成器修改注释、代码优化。
---
pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/util/CaptchaUtil.java | 67 +++++++++++++++++++++++++++++++++
1 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/util/CaptchaUtil.java b/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/util/CaptchaUtil.java
new file mode 100644
index 0000000..7aeccc0
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/util/CaptchaUtil.java
@@ -0,0 +1,67 @@
+package com.dy.pipIrrApp.util;
+
+import java.security.SecureRandom;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-09-11 15:48
+ * @LastEditTime 2024-09-11 15:48
+ * @Description
+ */
+
+public class CaptchaUtil {
+ /**
+ * 鐢熸垚鏁板鏂囨湰绠楀紡锛屼緥濡�1+1=锛�
+ * @param a 鏁板瓧
+ * @param b 鏁板瓧
+ * @return 瀛楃
+ */
+ public static Map<String, String> mathTextCreator(int a, int b) {
+ Random random = new SecureRandom();
+ // 鐢熸垚闅忔満鎿嶄綔锛屾搷浣滆寖鍥达細[0,4)锛屽垎鍒〃绀猴細 + - * /
+ int op = random.nextInt(4);
+ // 瀹氫箟璁$畻鐨勭粨鏋�
+ Integer result = 0;
+ // 瀹氫箟鏋勫缓鐨勭畻寮忓瓧绗︿覆
+ StringBuilder resultString = new StringBuilder();
+ // 杩愮畻绗︼細-
+ if (1 == op) {
+ if (a >= b) {
+ result = a - b;
+ resultString.append(a).append("-").append(b).append("=?@").append(result);
+ } else {
+ result = b - a;
+ resultString.append(b).append("-").append(a).append("=?@").append(result);
+ }
+ }
+ // 杩愮畻绗︼細*
+ else if (2 == op) {
+ result = a * b;
+ resultString.append(a).append("*").append(b).append("=?@").append(result);
+ }
+ // 杩愮畻绗︼細/
+ else if (3 == op) {
+ if (a != 0 && b % a == 0) {
+ result = b / a;
+ resultString.append(b).append("/").append(a).append("=?@").append(result);
+ } else if (b != 0 && a % b == 0) {
+ result = a / b;
+ resultString.append(a).append("/").append(b).append("=?@").append(result);
+ } else {
+ return mathTextCreator(a, b);
+ }
+ }
+ // 杩愮畻绗︼細+
+ else {
+ result = b + a;
+ resultString.append(a).append("+").append(b).append("=?@").append(result);
+ }
+ Map<String, String> ret = new HashMap<String, String>();
+ ret.put("resultCode", result.toString());
+ ret.put("resultString", resultString.toString());
+ return ret;
+ }
+}
--
Gitblit v1.8.0