yujian
2020-06-28 1e28ac69827ff7578a418a79bd95aff2c6637f5c
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/SMSController.java
@@ -194,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();
      }
   }
}