jinshihui 2 viikkoa sitten
vanhempi
commit
1f89fd883a

+ 50 - 44
nightFragrance-admin/src/main/java/com/ylx/web/controller/common/CaptchaController.java

@@ -6,6 +6,8 @@ import java.util.concurrent.TimeUnit;
 import javax.annotation.Resource;
 import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletResponse;
+
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.FastByteArrayOutputStream;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -26,8 +28,8 @@ import com.ylx.system.service.ISysConfigService;
  * @author ylx
  */
 @RestController
-public class CaptchaController
-{
+@Slf4j
+public class CaptchaController {
     @Resource(name = "captchaProducer")
     private Producer captchaProducer;
 
@@ -39,56 +41,60 @@ public class CaptchaController
 
     @Autowired
     private ISysConfigService configService;
+
+
     /**
      * 生成验证码
+     *
+     * @param response 响应
+     * @return AjaxResult 验证码图片
+     * @throws IOException 异常
      */
     @GetMapping("/captchaImage")
-    public AjaxResult getCode(HttpServletResponse response) throws IOException
-    {
-        AjaxResult ajax = AjaxResult.success();
-        boolean captchaEnabled = configService.selectCaptchaEnabled();
-        ajax.put("captchaEnabled", captchaEnabled);
-        if (!captchaEnabled)
-        {
-            return ajax;
-        }
+    public AjaxResult getCode(HttpServletResponse response) throws IOException {
+        try {
+            AjaxResult ajax = AjaxResult.success();
+            boolean captchaEnabled = configService.selectCaptchaEnabled();
+            ajax.put("captchaEnabled", captchaEnabled);
+            if (!captchaEnabled) {
+                return ajax;
+            }
 
-        // 保存验证码信息
-        String uuid = IdUtils.simpleUUID();
-        String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid;
+            // 保存验证码信息
+            String uuid = IdUtils.simpleUUID();
+            String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid;
 
-        String capStr = null, code = null;
-        BufferedImage image = null;
+            String capStr = null, code = null;
+            BufferedImage image = null;
 
-        // 生成验证码
-        String captchaType = RuoYiConfig.getCaptchaType();
-        if ("math".equals(captchaType))
-        {
-            String capText = captchaProducerMath.createText();
-            capStr = capText.substring(0, capText.lastIndexOf("@"));
-            code = capText.substring(capText.lastIndexOf("@") + 1);
-            image = captchaProducerMath.createImage(capStr);
-        }
-        else if ("char".equals(captchaType))
-        {
-            capStr = code = captchaProducer.createText();
-            image = captchaProducer.createImage(capStr);
-        }
+            // 生成验证码
+            String captchaType = RuoYiConfig.getCaptchaType();
+            if ("math".equals(captchaType)) {
+                log.info("生成数学验证码");
+                String capText = captchaProducerMath.createText();
+                capStr = capText.substring(0, capText.lastIndexOf("@"));
+                code = capText.substring(capText.lastIndexOf("@") + 1);
+                image = captchaProducerMath.createImage(capStr);
+            } else if ("char".equals(captchaType)) {
+                capStr = code = captchaProducer.createText();
+                image = captchaProducer.createImage(capStr);
+            }
 
-        redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
-        // 转换流信息写出
-        FastByteArrayOutputStream os = new FastByteArrayOutputStream();
-        try
-        {
-            ImageIO.write(image, "jpg", os);
-        }
-        catch (IOException e)
-        {
-            return AjaxResult.error(e.getMessage());
-        }
+            redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
+            // 转换流信息写出
+            FastByteArrayOutputStream os = new FastByteArrayOutputStream();
+            try {
+                ImageIO.write(image, "jpg", os);
+            } catch (IOException e) {
+                return AjaxResult.error(e.getMessage());
+            }
 
-        ajax.put("uuid", uuid);
-        ajax.put("img", Base64.encode(os.toByteArray()));
-        return ajax;
+            ajax.put("uuid", uuid);
+            ajax.put("img", Base64.encode(os.toByteArray()));
+            return ajax;
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException(e);
+        }
     }
 }

+ 21 - 9
nightFragrance-admin/src/main/java/com/ylx/web/controller/massage/MaTechnicianController.java

@@ -109,6 +109,13 @@ public class MaTechnicianController extends BaseController {
 
     public static final String PHONE_THREEUSERPARTCLIENT_CODE_KEY = "sys:clientLogin:phone:";
 
+    /**
+     * 发送短信验证码
+     *
+     * @param phone 手机号
+     * @param request
+     * @return Result
+     */
     @GetMapping("/sendMsg")
     @ApiOperation(value = "短信发送", notes = "短信发送")
     public Result sendMsg(@RequestParam String phone, HttpServletRequest request) {
@@ -119,9 +126,7 @@ public class MaTechnicianController extends BaseController {
         // randNumber 将被赋值为一个 MIN 和 MAX 范围内的随机数
         int randNumber = rand.nextInt(9999 - 1000 + 1) + 1000;
         // 保存验证码到redis
-        redisTemplate.opsForValue()
-                .set("userH5:order:phone:" + phone, String.valueOf(randNumber), 5L
-                        , TimeUnit.MINUTES);
+        redisTemplate.opsForValue().set("userH5:order:phone:" + phone, String.valueOf(randNumber), 5L, TimeUnit.MINUTES);
         try {
             SMSVerificationCode smsVerificationCode = new SMSVerificationCode(String.valueOf(randNumber));
             String jsonString = JSON.toJSONString(smsVerificationCode);
@@ -134,12 +139,12 @@ public class MaTechnicianController extends BaseController {
     }
 
     /**
-     * 商户登录接口
+     * 商户手机号密码登录
      *
      * @param thirdPartyLoginsVo
      * @return Result<WxLoginUser>
      */
-    @ApiOperation(value = "商户登录", notes = "商户登录")
+    @ApiOperation(value = "商户手机号密码登录", notes = "商户手机号密码登录")
     @PostMapping(value = "/clientLogin")
     @Transactional
     public Result<WxLoginUser> login(@RequestBody ThirdPartyLoginsVo thirdPartyLoginsVo) throws Exception {
@@ -196,7 +201,6 @@ public class MaTechnicianController extends BaseController {
         result.setResult(wxUser);
         // 登录成功删除验证码
         redisTemplate.delete(PHONE_THREEUSERPARTCLIENT_CODE_KEY + thirdPartyLoginsVo.getPhone());
-
         result.success("登录成功");
         return result;
     }
@@ -239,12 +243,21 @@ public class MaTechnicianController extends BaseController {
 
     /**
      * 校验图形验证码接口
+     *
+     * @param req
+     * @return Result<?>
      */
     @PostMapping("/getValidateCaptcha")
     @ApiOperation("校验图形验证码接口")
     public Result<?> getValidateCaptcha(@RequestBody ValidateCaptchaDto req) {
-        validateCaptcha(req.getPhone(), req.getCode(), req.getUuid());
-        return Result.ok("校验成功");
+        try {
+            log.info("校验图形验证码的请求参数:{}", JSON.toJSONString(req));
+            validateCaptcha(req.getPhone(), req.getCode(), req.getUuid());
+            return Result.ok("校验成功");
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException(e);
+        }
     }
 
     /**
@@ -295,7 +308,6 @@ public class MaTechnicianController extends BaseController {
      * @param username 用户名
      * @param code     验证码
      * @param uuid     唯一标识
-     * @return 结果
      */
     public void validateCaptcha(String username, String code, String uuid) {
         boolean captchaEnabled = configService.selectCaptchaEnabled();

+ 2 - 4
nightFragrance-common/src/main/java/com/ylx/common/exception/user/CaptchaExpireException.java

@@ -5,12 +5,10 @@ package com.ylx.common.exception.user;
  *
  * @author ylx
  */
-public class CaptchaExpireException extends UserException
-{
+public class CaptchaExpireException extends UserException {
     private static final long serialVersionUID = 1L;
 
-    public CaptchaExpireException()
-    {
+    public CaptchaExpireException() {
         super("user.jcaptcha.expire", null);
     }
 }

+ 1 - 1
nightFragrance-framework/src/main/java/com/ylx/framework/config/SecurityConfig.java

@@ -108,7 +108,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
                 // 过滤请求
                 .authorizeRequests()
                 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
-                .antMatchers("/login", "/register", "/captchaImage", "/wx/login",
+                .antMatchers("/login", "/register", "/captchaImage", "/technician/technician/getValidateCaptcha","/technician/technician/sendMsg","/wx/login",
                         "/api/lbt/v1/getAll", "/api/js/v1/select", "/api/xiangmu/v1/wx/getAll", "/api/order/v1/getStatus",
                         "/api/xiangmu/v1/getByid", "/api/xiangmu/v1/highlights", "/api/js/v1/wx/getByid", "/api/js/v1/wx/select", "/api/js/v1/wx/add", "/api/recharge/v1/test",
                         "/wx/pay/payNotify", "/wx/pay/refundNotify", "/weChat/getAccessToken","/weChat/phoneLogin","/weChat/sendMsg", "/weChat/getCode", "/weChat/verifyToken", "/sq/getAccessToken",

+ 1 - 1
nightFragrance-massage/src/main/java/com/ylx/massage/domain/dto/ValidateCaptchaDto.java

@@ -4,7 +4,7 @@ import lombok.Data;
 
 @Data
 public class ValidateCaptchaDto {
-    //用户名
+    //手机号
     private String phone;
     //验证码的uuid标识
     private String uuid;

+ 7 - 0
nightFragrance-massage/src/main/java/com/ylx/message/enums/TriggerEventEnum.java

@@ -52,7 +52,14 @@ public enum TriggerEventEnum {
     /** 获得奖品 */
     PRIZE_RECEIVED(12,"prize_received");
 
+    /**
+     * 事件编码
+     */
     private final Integer code;
+
+    /**
+     * 事件描述
+     */
     private final String desc;
 
     TriggerEventEnum(Integer code, String desc) {

+ 1 - 0
nightFragrance-system/src/main/java/com/ylx/system/service/impl/SysConfigServiceImpl.java

@@ -63,6 +63,7 @@ public class SysConfigServiceImpl implements ISysConfigService {
      */
     @Override
     public String selectConfigByKey(String configKey) {
+        log.info("configKey的值:{}", configKey);
         String configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey)));
 
         if (StringUtils.isNotEmpty(configValue)) {