Browse Source

短信修改

tudc 3 years ago
parent
commit
1631d40364

+ 5 - 0
tianhu-system/pom.xml

@@ -255,6 +255,11 @@
             <artifactId>log4j</artifactId>
             <version>1.2.16</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.github.penggle</groupId>
+            <artifactId>kaptcha</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

+ 24 - 1
tianhu-system/src/main/java/com/tianhu/system/controller/MessageController.java

@@ -3,13 +3,20 @@ package com.tianhu.system.controller;
 import com.alibaba.fastjson.JSONObject;
 import com.keao.tianhu.core.entity.R;
 import com.tianhu.common.core.web.controller.BaseController;
-import com.tianhu.common.security.service.TokenService;
+import com.tianhu.common.core.web.domain.AjaxResult;
+import com.tianhu.common.log.annotation.Log;
+import com.tianhu.common.log.enums.BusinessType;
+import com.tianhu.common.redis.common.RedisUtils;
 import com.tianhu.system.common.IMessageUtilsService;
+import com.tianhu.system.common.ValidateCodeService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -24,6 +31,8 @@ public class MessageController extends BaseController
 {
     @Autowired
     private IMessageUtilsService iMessageUtilsService;
+    @Autowired
+    private ValidateCodeService validateCodeService;
 
     /**
      *
@@ -40,4 +49,18 @@ public class MessageController extends BaseController
         iMessageUtilsService.sendMessageCode(mobileNo, templateCode, param, random);
         return R.ok();
     }
+
+    @Log(title = "发送短信", businessType = BusinessType.INSERT)
+    @Transactional(rollbackFor=Exception.class)
+    @PostMapping("/sendShortMessage")
+    public AjaxResult sendShortMessage(@RequestBody Map<String, String> requestBody) throws Exception {
+        validateCodeService.checkCapcha(requestBody.get("imgCode"), requestBody.get("uuid"), false);
+        String random = iMessageUtilsService.genRandomNum(6);
+        Map<String, String> param = new HashMap<>();
+        param.put("code", random);
+        // 获取注册模板ID
+        String templateCode = RedisUtils.getDictValue("aliyun_message_code", "zhuce");
+        iMessageUtilsService.sendMessageCode(requestBody.get("phone"), templateCode, param, random);
+        return AjaxResult.success();
+    }
 }

+ 6 - 0
tianhu-system/src/main/java/com/tianhu/system/controller/SysUserController.java

@@ -23,6 +23,7 @@ import com.tianhu.system.api.domain.SysDept;
 import com.tianhu.system.api.domain.SysRole;
 import com.tianhu.system.api.domain.SysUser;
 import com.tianhu.system.api.model.LoginUser;
+import com.tianhu.system.common.ValidateCodeService;
 import com.tianhu.system.domain.*;
 import com.tianhu.system.domain.vo.TreeSelect;
 import com.tianhu.system.mapper.SysDeptMapper;
@@ -91,6 +92,8 @@ public class SysUserController extends BaseController
     private SysUserRoleMapper userRoleMapper;
     @Autowired
     private SysDeptMapper deptMapper;
+    @Autowired
+    private ValidateCodeService validateCodeService;
 
     //    下载模板
     @PostMapping("/importTemplate")
@@ -131,12 +134,15 @@ public class SysUserController extends BaseController
     @Transactional(rollbackFor = Exception.class)
     public R<Map<String, Object>> info(@RequestParam(value = "type", required = false) String type,
                                        @RequestParam(value = "code", required = false) String code,
+                                       @RequestParam(value = "uuid", required = false) String uuid,
                                        @RequestParam(value = "unionId", required = false) String unionId,
                                        @RequestParam(value = "username") String username,
                                        @RequestParam(value = "shortMessageCode", required = false) String shortMessageCode)
     {
         Map<String, Object> resMap = new HashMap<>();
 
+        validateCodeService.checkCapcha(code, uuid, true);
+
         SysUser sysUser = userService.selectUserByUserName(username);
         // 短信验证码登陆 或者 验证码注册
         if ("1".equals(type) || "2".equals(type)) {