yujian
2020-06-28 1e28ac69827ff7578a418a79bd95aff2c6637f5c
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/SMSController.java
@@ -42,6 +42,10 @@
   @RequestSerializableByKey(key = "#phone+'-'+#uid+'-'+#type")
   @RequestMapping(value = "sendSMS", method = RequestMethod.POST)
   public void sendMSM(AcceptData acceptData, String phone, Long uid, Integer type, PrintWriter out) {
      if (Constant.IS_TEST) {
         out.print(JsonUtil.loadTrueResult("发送成功"));
         return;
      }
      sendMSM(acceptData, phone, uid, type, StringUtil.Md5(phone + "-" + "-" + uid + "-" + type), out);
   }
@@ -86,7 +90,7 @@
         return;
      }
      phone = phone.replaceAll(" ", "");
      if (Constant.IS_TEST) {
         out.print(JsonUtil.loadTrueResult("发送成功"));
         return;
@@ -105,7 +109,7 @@
    */
   @RequestSerializableByKey(key = "#acceptData.device+'-'+#phone")
   @RequestMapping(value = "sendMSMBind", method = RequestMethod.POST)
   public void sendMSMBind(AcceptData acceptData, String phone, boolean slideVerify, PrintWriter out) {
   public void sendMSMBind(AcceptData acceptData, String phone, boolean slideVerify, Long uid, PrintWriter out) {
      if (phone == null || !StringUtil.isMobile(phone.replaceAll(" ", ""))) {
         out.print(JsonUtil.loadFalseResult(1, "手机号输入有误,请修改"));
         return;
@@ -125,7 +129,7 @@
      //
      // 判断手机号码是否被封禁
      UserInfo phoneUser = userInfoService.getEffectiveUserInfoByPhone(phone);
      if (phoneUser != null) {
      if (phoneUser != null && uid != null) {
         out.print(JsonUtil.loadFalseResult(9001, "该电话号码被占用"));
         return;
      }
@@ -134,7 +138,7 @@
         out.print(JsonUtil.loadTrueResult("发送成功"));
         return;
      }
      sendMSNnew(phone, slideVerify, 2, StringUtil.Md5(phone + "-" + acceptData.getDevice()), out);
   }
@@ -144,10 +148,10 @@
         String cachekey = null;
         if (type == 1) {
            // 登录验证码
            cachekey = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSLoginCount, phone + "" );
            cachekey = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSLoginCount, phone + "");
         } else if (type == 2) {
            // 绑定验证码
            cachekey = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSBindCount, phone + "" );
            cachekey = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSBindCount, phone + "");
         }
         if (cachekey == null) {
@@ -190,4 +194,69 @@
         e.printStackTrace();
      }
   }
   /**
    * 注销账户短信验证
    * @param acceptData
    * @param uid
    * @param phone
    * @param out
    */
   @RequestMapping(value = "sendMSMRemove")
   public void sendMSMRemove(String callback, AcceptData acceptData, Long uid, String phone, PrintWriter out) {
      if (Constant.IS_TEST) {
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("发送成功"));
         return;
      }
      if (uid == null || uid <= 0) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "用户未登录"));
         return;
      }
      if (phone == null || !StringUtil.isMobile(phone.replaceAll(" ", ""))) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "请输入正确手机号"));
         return;
      }
      phone = phone.replaceAll(" ", "").trim();
      UserInfo userInfo = userInfoService.selectAvailableByPrimaryKey(uid);
      if (userInfo == null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "用户不存在"));
         return;
      }
      if (!phone.equals(userInfo.getPhone())) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "请输入正确手机号"));
         return;
      }
      try {
         int count = 0;
         String cachekey = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSBindRemove, phone + "");
         String cacheValue = redisManager.getCommonString(cachekey);
         if (!StringUtil.isNullOrEmpty(cacheValue)) {
            count = Integer.parseInt(cacheValue);
            // 限制3次
            if (count >= 3) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "验证码次数超限,请稍后再试"));
               return;
            }
         }
         // 缓存一个小时
         count++;
         redisManager.cacheCommonString(cachekey, count + "", 60 * 60);
         // 发送验证码
         smsService.sendRemoveVCode(phone, 4);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("发送成功"));
      } catch (SMSException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "发送失败"));
         e.printStackTrace();
      }
   }
}