| | |
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.SMSHistoryMapper;
|
| | | import com.yeshi.fanli.entity.bus.user.SMSHistory;
|
| | | import com.yeshi.fanli.exception.SMSException;
|
| | | 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 net.sf.json.JSONObject;
|
| | |
|
| | | @Service
|
| | | public class SMSServiceImpl implements SMSService {
|
| | |
| | | boolean limit = redisManager.isSmsFrequencyLimit(phone, SMSHistory.TYPE_LOGIN);
|
| | | if (limit)
|
| | | throw new SMSException(1001, "请过60秒再试");
|
| | | |
| | |
|
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, StringUtil.Md5("sms-login-tencent-latest-" + phone));
|
| | |
|
| | | String msgCode = StringUtil.getVerifyCode(codeLength);
|
| | | // 验证码模板
|
| | | String msg = Constant.smsConfig.getSmsLogin().replace("[签名]", Constant.smsConfig.getSmsSign()).replace("[验证码]",
|
| | | msgCode);
|
| | | // 发送短信
|
| | | TencentSMSUtil.sendSingleMsg(phone, msg);
|
| | | // 发送间隔2分钟内的采用阿里云短信发送
|
| | | String cacheString = redisManager.getCommonString(key);
|
| | | if (StringUtil.isNullOrEmpty(cacheString) || Integer.parseInt(cacheString) < 2) {
|
| | | TencentSMSUtil.sendSingleMsg(phone, msg);
|
| | | redisManager.increase(key);
|
| | | redisManager.expire(key, 120);
|
| | | } else {
|
| | | redisManager.removeCommonString(key);
|
| | | // 发送阿里云短信
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("code", msgCode);
|
| | | AliyunSMSUtil.sendSingleMsg(phone, Constant.smsConfig.getAliyunLoginTemplatecode(), data.toString());
|
| | | }
|
| | | // 缓存
|
| | | redisManager.sendSms(phone, SMSHistory.TYPE_LOGIN);
|
| | | redisManager.saveSMSVCode(phone, SMSHistory.TYPE_LOGIN, msgCode);
|
| | | |
| | |
|
| | | SMSHistory smsHistory = new SMSHistory();
|
| | | smsHistory.setContent(msg);
|
| | | smsHistory.setCreateTime(new Date());
|
| | |
| | | if (limit)
|
| | | throw new SMSException(1001, "请过60秒再试");
|
| | | String msgCode = StringUtil.getVerifyCode(codeLength);
|
| | | |
| | |
|
| | | // 验证码模板
|
| | | String msg = Constant.smsConfig.getSmsBind().replace("[签名]", Constant.smsConfig.getSmsSign()).replace("[验证码]",
|
| | | msgCode);
|
| | | // 发送短信
|
| | | TencentSMSUtil.sendSingleMsg(phone, msg);
|
| | | |
| | |
|
| | | // 缓存
|
| | | redisManager.sendSms(phone, SMSHistory.TYPE_BIND);
|
| | | redisManager.saveSMSVCode(phone, SMSHistory.TYPE_BIND, msgCode);
|
| | | |
| | |
|
| | | SMSHistory smsHistory = new SMSHistory();
|
| | | smsHistory.setContent(msg);
|
| | | smsHistory.setCreateTime(new Date());
|