admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/SMSController.java
@@ -11,10 +11,12 @@
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.exception.SMSException;
import com.yeshi.fanli.exception.config.SMSException;
import com.yeshi.fanli.service.inter.user.ForbiddenUserIdentifyCodeService;
import com.yeshi.fanli.service.inter.user.SMSService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.RedisKeyEnum;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.annotation.RequestSerializableByKey;
@@ -31,18 +33,22 @@
   @Resource
   private UserInfoService userInfoService;
   @Resource
   private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService;
   // 发送短信
   @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);
   }
   @RequestSerializableByKey(key = "key")
   public void sendMSM(AcceptData acceptData, String phone, Long uid, Integer type, String key, PrintWriter out) {
      try {
         if (phone.contains("**") && uid != null && uid > 0) {
@@ -68,10 +74,10 @@
         out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
      }
   }
   /**
    * 1.5.3  登录发送短信
    * 1.5.3 登录发送短信
    *
    * @param acceptData
    * @param phone
    * @param uid
@@ -84,82 +90,93 @@
         return;
      }
      phone = phone.replaceAll(" ", "");
      sendMSNnew(phone,slideVerify, 1, StringUtil.Md5(phone + "-" + acceptData.getDevice()), out);
      if (Constant.IS_TEST) {
         out.print(JsonUtil.loadTrueResult("发送成功"));
         return;
      }
      sendMSNnew(phone, slideVerify, 1, StringUtil.Md5(phone + "-" + acceptData.getDevice()), out);
   }
   /**
    * 1.5.3 绑定发送短信
    *
    * @param acceptData
    * @param phone
    * @param uid
    * @param out
    */
   @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;
      }
      phone = phone.replaceAll(" ", "");
      // 判断手机号码是否被封禁
//      ForbiddenUserIdentifyCode identifyCode1 = forbiddenUserIdentifyCodeService
//            .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone, phone);
//      if (identifyCode1 != null && identifyCode1.getEffective() != null && identifyCode1.getEffective()) {
//         out.print(JsonUtil.loadFalseResult(9001,"该电话号码被占用"));
//         return;
//      }
//
      // ForbiddenUserIdentifyCode identifyCode1 =
      // forbiddenUserIdentifyCodeService
      // .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone,
      // phone);
      // if (identifyCode1 != null && identifyCode1.getEffective() != null &&
      // identifyCode1.getEffective()) {
      // out.print(JsonUtil.loadFalseResult(9001,"该电话号码被占用"));
      // return;
      // }
      //
      // 判断手机号码是否被封禁
      UserInfo phoneUser = userInfoService.getEffectiveUserInfoByPhone(phone);
      if (phoneUser != null) {
         out.print(JsonUtil.loadFalseResult(9001,"该电话号码被占用"));
      if (phoneUser != null && uid != null) {
         out.print(JsonUtil.loadFalseResult(9001, "该电话号码被占用"));
         return;
      }
      sendMSNnew(phone,slideVerify, 2, StringUtil.Md5(phone + "-" + acceptData.getDevice()), out);
      if (Constant.IS_TEST) {
         out.print(JsonUtil.loadTrueResult("发送成功"));
         return;
      }
      sendMSNnew(phone, slideVerify, 2, StringUtil.Md5(phone + "-" + acceptData.getDevice()), out);
   }
   @RequestSerializableByKey(key = "key")
   public void sendMSNnew(String phone, boolean slideVerify, int type, String key, PrintWriter out) {
      try {
         int count = 0;
         String cachekey = null;
         if (type == 1) {
            // 登录验证码
            cachekey = "sendMSNLoginCount" + phone;
            cachekey = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSLoginCount, phone + "");
         } else if (type == 2) {
            // 绑定验证码
            cachekey = "sendMSNBindCount" + phone;
            cachekey = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSBindCount, phone + "");
         }
         if (cachekey == null) {
            out.print(JsonUtil.loadFalseResult(1,"发送失败"));
            out.print(JsonUtil.loadFalseResult(1, "发送失败"));
            return;
         }
         String cacheValue = redisManager.getCommonString(cachekey);
         if (!StringUtil.isNullOrEmpty(cacheValue)) {
            count = Integer.parseInt(cacheValue);
            // 限制3次
            if (count >= 3) {
               out.print(JsonUtil.loadFalseResult(3,"验证码次数超限,请稍后再试"));
               out.print(JsonUtil.loadFalseResult(3, "验证码次数超限,请稍后再试"));
               return;
            }
         }
         if (count == 2 && !slideVerify) {
            out.print(JsonUtil.loadFalseResult(2,"需要滑动验证"));
            out.print(JsonUtil.loadFalseResult(2, "需要滑动验证"));
            return;
         }
         }
         // 缓存一个小时
         count ++;
         count++;
         redisManager.cacheCommonString(cachekey, count + "", 60 * 60);
         if (type == 1) {
            // 登录验证码
            smsService.sendLoginVCode(phone, 4);
@@ -167,9 +184,9 @@
            // 绑定验证码
            smsService.sendBindVCode(phone, 4);
         }
         out.print(JsonUtil.loadTrueResult("发送成功"));
      } catch (SMSException e) {
         out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
      } catch (Exception e) {