فهرست منبع

验证码登录

huangzhiguo 2 سال پیش
والد
کامیت
a31670bbd6

+ 1 - 1
src/main/java/com/caimei365/user/service/BaseService.java

@@ -37,7 +37,7 @@ public interface BaseService {
      * 获取短信验证码
      *
      * @param mobile           手机号
-     * @param activateCodeType 1:找回密码,2:手机号注册机构,3:供应商注册,4:修改手机号-旧手机验证码,5:修改手机号-新手机验证码
+     * @param activateCodeType 1:找回密码,2:手机号注册机构,3:供应商注册,4:修改手机号-旧手机验证码,5:修改手机号-新手机验证码,7:手机验证码登录
      * @param platformType     0:www,1:crm/h5,2:小程序
      * @param isCheckCaptcha   是否检查图片验证码,0:检查,1:不检查
      * @param imgCode          图片验证码

+ 36 - 29
src/main/java/com/caimei365/user/service/impl/BaseServiceImpl.java

@@ -117,7 +117,7 @@ public class BaseServiceImpl implements BaseService {
      * 获取短信验证码
      *
      * @param mobile           手机号
-     * @param activateCodeType 1:找回密码,2:手机号注册机构,3:供应商注册,4:修改手机号-旧手机验证码,5:修改手机号-新手机验证码
+     * @param activateCodeType 1:找回密码,2:手机号注册机构,3:供应商注册,4:修改手机号-旧手机验证码,5:修改手机号-新手机验证码,7:手机验证码登录
      * @param platformType     0:www,1:crm/h5,2:小程序
      * @param isCheckCaptcha   是否检查图片验证码,0:检查,1:不检查
      * @param imgCode          图片验证码
@@ -134,7 +134,7 @@ public class BaseServiceImpl implements BaseService {
         if (null == isCheckCaptcha || 0 == isCheckCaptcha) {
             Boolean checkFlag = checkCaptchaImage(token, imgCode, platformType);
             if (!checkFlag) {
-                return ResponseJson.error("图验证码错误");
+                return ResponseJson.error("图验证码错误");
             }
         }
         boolean sendFlag = false;
@@ -190,6 +190,35 @@ public class BaseServiceImpl implements BaseService {
             String content = "您正在采美平台发布二手商品,您的验证码为:" + randomCode + ",10分钟内有效,请勿泄露他人。";
             sendFlag = isBeta || remoteCallService.remoteSendSms(0, 1, mobile, content);
             codeTypeTxt = "更换联系人(旧手机号验证码)";
+        } else if (7 == activateCodeType) {
+            // 校验是否发送验证码
+            /*Object resCode = redisService.get("code:" + mobile);
+            long expireTime = redisService.getExpireTime("code:" + mobile);
+            if (!ObjectUtils.isEmpty(resCode) || expireTime >= 0) {
+                return ResponseJson.error("验证码已发送,请勿重复操作");
+            }*/
+            // 重复发送,删除前一个验证码
+            redisService.remove("code:"+ mobile);
+            Integer dbUserId = null;
+            // 根据手机号查询用户Id
+            dbUserId = baseMapper.getUserIdByMobile(mobile);
+            if (dbUserId == null) {
+                return ResponseJson.error("该手机号暂未注册");
+            }
+            // 您正在操作登录采美商城,验证码:{s6},请在5分钟内完成验证。如非本人操作,请忽略本短信。
+            String content = "您正在操作登录采美商城,验证码:"+ randomCode +",请在5分钟内完成验证。如非本人操作,请忽略本短信。";
+            boolean smsFlag = isBeta || remoteCallService.remoteSendSms(0,1,mobile,content);
+            if (!smsFlag) {
+                // 短信发送失败重试一次
+                smsFlag = remoteCallService.remoteSendSms(0,1,mobile,content);
+            }
+            if (smsFlag) {
+                redisService.set("code:"+ mobile, randomCode,300L);
+                log.info("登录短信,发送到"+ mobile + "的验证码为:"+ randomCode);
+                return ResponseJson.success("发送验证码成功");
+            } else {
+                return ResponseJson.error("发送验证码失败,请稍后再试");
+            }
         } else {
             return ResponseJson.error("参数错误:activateCodeType");
         }
@@ -351,39 +380,14 @@ public class BaseServiceImpl implements BaseService {
             return ResponseJson.error(result);
         }
 
-        Object resCode = redisService.get("code:" + mobile);
-        long expireTime = redisService.getExpireTime("code:" + mobile);
-        if (!ObjectUtils.isEmpty(resCode) || expireTime >= 0) {
-            return ResponseJson.error("验证码已发送,请勿重复操作");
-        }
-
         Integer dbUserId = null;
         // 根据手机号查询用户Id
         dbUserId = baseMapper.getUserIdByMobile(mobile);
         if (dbUserId == null) {
             return ResponseJson.error("该手机号暂未注册");
         }
-        // 生成6位数验证码
-        String randomCode = CodeUtil.generateCodeInt(6);
-        // 开发、测试环境下短信验证码固定为 666666
-        boolean isCode = "dev".equals(profile)|| "beta".equals(profile);
-        if (isCode) {
-            randomCode = "666666";
-        }
-        // 您正在操作登录采美商城,验证码:{s6},请在5分钟内完成验证。如非本人操作,请忽略本短信。
-        String content = "您正在操作登录采美商城,验证码:"+ randomCode +",请在5分钟内完成验证。如非本人操作,请忽略本短信。";
-        boolean smsFlag = isCode || remoteCallService.remoteSendSms(0,1,mobile,content);
-        if (!smsFlag) {
-            // 短信发送失败重试一次
-            smsFlag = remoteCallService.remoteSendSms(0,1,mobile,content);
-        }
-        if (smsFlag) {
-            redisService.set("code:"+ mobile, randomCode,300L);
-            log.info("登录短信,发送到"+ mobile + "的验证码为:"+ randomCode);
-            return ResponseJson.success("发送验证码成功");
-        } else {
-            return ResponseJson.error("发送验证码失败,请稍后再试");
-        }
+
+        return ResponseJson.success();
     }
 
     /**
@@ -399,12 +403,15 @@ public class BaseServiceImpl implements BaseService {
         if (result != null) {
             return ResponseJson.error(result);
         }
+        // 校验是否发送验证码
         Object resCode = redisService.get("code:" + mobile);
         long expireTime = redisService.getExpireTime("code:" + mobile);
         if (!ObjectUtils.isEmpty(resCode) || expireTime >= 0) {
             return ResponseJson.error("验证码已发送,请勿重复操作");
         }
 
+        // 重复发送,删除前一个验证码
+        /*redisService.remove("code:"+ mobile);*/
         Integer dbUserId = null;
         // 根据手机号查询用户Id
         dbUserId = baseMapper.getUserIdByMobile(mobile);