admin
2020-08-26 26f7accb815f55f18f8eedfca4324700a96884ec
fanli/src/main/java/com/yeshi/fanli/service/impl/user/SMSServiceImpl.java
@@ -1,24 +1,17 @@
package com.yeshi.fanli.service.impl.user;
import java.math.BigDecimal;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.mybatis.SMSHistoryMapper;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.bus.user.SMSHistory;
import com.yeshi.fanli.exception.config.SMSException;
import com.yeshi.fanli.service.inter.user.SMSService;
import com.yeshi.fanli.util.AliyunSMSUtil;
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.TencentSMSUtil;
import com.yeshi.fanli.util.*;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
@Service
public class SMSServiceImpl implements SMSService {
@@ -30,7 +23,7 @@
   private RedisManager redisManager;
   @Override
   public String sendLoginVCode(String phone, int codeLength) throws SMSException {
   public String sendLoginVCode(SystemEnum system, String phone, int codeLength) throws SMSException {
      boolean limit = redisManager.isSmsFrequencyLimit(phone, SMSHistory.TYPE_LOGIN);
      if (limit)
         throw new SMSException(1001, "请过60秒再试");
@@ -39,7 +32,7 @@
      String msgCode = StringUtil.getVerifyCode(codeLength);
      // 验证码模板
      String msg = Constant.smsConfig.getSmsLogin().replace("[签名]", Constant.smsConfig.getSmsSign()).replace("[验证码]",
      String msg = Constant.smsConfig.getSmsLogin().replace("[签名]", system.getSmsAlias()).replace("[验证码]",
            msgCode);
      // 发送短信
      // 发送间隔2分钟内的采用阿里云短信发送
@@ -69,14 +62,14 @@
   }
   @Override
   public void sendBindVCode(String phone, int codeLength) throws SMSException {
   public void sendBindVCode(SystemEnum system,String phone, int codeLength) throws SMSException {
      boolean limit = redisManager.isSmsFrequencyLimit(phone, SMSHistory.TYPE_BIND);
      if (limit)
         throw new SMSException(1001, "请过60秒再试");
      String msgCode = StringUtil.getVerifyCode(codeLength);
      // 验证码模板
      String msg = Constant.smsConfig.getSmsBind().replace("[签名]", Constant.smsConfig.getSmsSign()).replace("[验证码]",
      String msg = Constant.smsConfig.getSmsBind().replace("[签名]", system.getSmsAlias()).replace("[验证码]",
            msgCode);
      // 发送短信
      TencentSMSUtil.sendSingleMsg(phone, msg);
@@ -94,12 +87,37 @@
   }
   @Override
   public void sendExtractVCode(String phone) throws SMSException {
   public void sendRemoveVCode(SystemEnum system,String phone, int codeLength) throws SMSException {
      boolean limit = redisManager.isSmsFrequencyLimit(phone, SMSHistory.TYPE_REMVOE);
      if (limit)
         throw new SMSException(1001, "请过60秒再试");
      String msgCode = StringUtil.getVerifyCode(codeLength);
      // 验证码模板
      String msg = Constant.smsConfig.getSmsBind().replace("[签名]", system.getSmsAlias()).replace("[验证码]",
            msgCode);
      // 发送短信
      TencentSMSUtil.sendSingleMsg(phone, msg);
      // 缓存
      redisManager.sendSms(phone, SMSHistory.TYPE_REMVOE);
      redisManager.saveSMSVCode(phone, SMSHistory.TYPE_REMVOE, msgCode);
      SMSHistory smsHistory = new SMSHistory();
      smsHistory.setContent(msg);
      smsHistory.setCreateTime(new Date());
      smsHistory.setPhone(phone);
      smsHistory.setType(SMSHistory.TYPE_REMVOE);
      smsHistoryMapper.insertSelective(smsHistory);
   }
   @Override
   public void sendExtractVCode(SystemEnum system,String phone) throws SMSException {
      boolean limit = redisManager.isSmsFrequencyLimit(phone, SMSHistory.TYPE_EXTRACT);
      if (limit)
         throw new SMSException(1001, "请过60秒再试");
      String msgCode = StringUtil.getRandomCode(6);
      String msg = Constant.smsConfig.getSmsExtract().replace("[签名]", Constant.smsConfig.getSmsSign())
      String msg = Constant.smsConfig.getSmsExtract().replace("[签名]",system.getSmsAlias())
            .replace("[验证码]", msgCode);
      // 发送短信
      TencentSMSUtil.sendSingleMsg(phone, msg);
@@ -109,16 +127,16 @@
   }
   @Override
   public void sendExtractSuccessMsg(String phone, BigDecimal money) throws SMSException {
      String msg = Constant.smsConfig.getSmsExtractSuccess().replace("[签名]", Constant.smsConfig.getSmsSign())
   public void sendExtractSuccessMsg(SystemEnum system,String phone, BigDecimal money) throws SMSException {
      String msg = Constant.smsConfig.getSmsExtractSuccess().replace("[签名]", system.getSmsAlias())
            .replace("[金额]", money.toString());
      // 发送短信
      TencentSMSUtil.sendSingleMsg(phone, msg);
   }
   @Override
   public void sendExtractFailMsg(String phone, BigDecimal money) throws SMSException {
      String msg = Constant.smsConfig.getSmsExtractFail().replace("[签名]", Constant.smsConfig.getSmsSign())
   public void sendExtractFailMsg(SystemEnum system,String phone, BigDecimal money) throws SMSException {
      String msg = Constant.smsConfig.getSmsExtractFail().replace("[签名]", system.getSmsAlias())
            .replace("[金额]", money.toString());
      // 发送短信
      TencentSMSUtil.sendSingleMsg(phone, msg);