|
@@ -51,15 +51,15 @@ public class SmsServiceImpl implements SmsService {
|
|
|
protected ExamCloudLog log = ExamCloudLogFactory.getLog(this.getClass());
|
|
|
|
|
|
@Override
|
|
|
- public void sendSms(SmsAssemblyCacheBean smsAssembly, List<String> phoneList,
|
|
|
+ public void sendSms(String smsAssemblyCode, List<String> phoneList,
|
|
|
Map<String, String> params) {
|
|
|
+ SmsAssemblyCacheBean smsAssembly = CacheHelper.getSmsAssembly(smsAssemblyCode);
|
|
|
+ if (null == smsAssembly) {
|
|
|
+ throw new StatusException("101040", "smsAssemblyCode is wrong");
|
|
|
+ }
|
|
|
boolean virtualEnable = PropertyHolder.getBoolean("sms.virtual.enable", false);
|
|
|
if (!virtualEnable) {
|
|
|
- try {
|
|
|
- execute(smsAssembly, "SendSms", phoneList, params);
|
|
|
- } catch (Exception e) {
|
|
|
- // ignore
|
|
|
- }
|
|
|
+ execute(smsAssembly, "SendSms", phoneList, params);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -94,25 +94,22 @@ public class SmsServiceImpl implements SmsService {
|
|
|
List<Date> sendTimeList = sm.getSendTimeList();
|
|
|
|
|
|
if (10 <= sendTimeList.size()) {
|
|
|
- throw new StatusException("102000", "一天内发送次数超过10次");
|
|
|
+ throw new StatusException("101000", "一天内发送次数超过10次");
|
|
|
} else if (5 <= sendTimeList.size()) {
|
|
|
Date d = sendTimeList.get(sendTimeList.size() - 5);
|
|
|
if (now.getTime() - d.getTime() < 1000 * 60 * 60) {
|
|
|
- throw new StatusException("102000", "一小时内发送次数超过5次");
|
|
|
+ throw new StatusException("101000", "一小时内发送次数超过5次");
|
|
|
}
|
|
|
} else {
|
|
|
Date d = sendTimeList.get(sendTimeList.size() - 1);
|
|
|
if (now.getTime() - d.getTime() < 1000 * 60) {
|
|
|
- throw new StatusException("102000", "一分钟内发送次数超过1次");
|
|
|
+ throw new StatusException("101000", "一分钟内发送次数超过1次");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // 获取短信配置信息
|
|
|
- SmsAssemblyCacheBean assemblyCacheBean = CacheHelper
|
|
|
- .getSmsAssembly(YZM_SMS_ASSEMBLY_CODE);
|
|
|
Map<String, String> params = Maps.newHashMap();
|
|
|
params.put("code", code);
|
|
|
- this.sendSms(assemblyCacheBean, Arrays.asList(new String[]{phone}), params);
|
|
|
+ this.sendSms(YZM_SMS_ASSEMBLY_CODE, Arrays.asList(new String[]{phone}), params);
|
|
|
|
|
|
sm.getSendTimeList().add(now);
|
|
|
sm.setTimes(sm.getSendTimeList().size());
|
|
@@ -140,18 +137,18 @@ public class SmsServiceImpl implements SmsService {
|
|
|
ShortMessageInfo sm = redisClient.get(key, ShortMessageInfo.class);
|
|
|
|
|
|
if (null == sm) {
|
|
|
- throw new StatusException("102001", "未发送验证码");
|
|
|
+ throw new StatusException("101001", "未发送验证码");
|
|
|
}
|
|
|
List<Date> sendTimeList = sm.getSendTimeList();
|
|
|
Date date = sendTimeList.get(sendTimeList.size() - 1);
|
|
|
Date now = new Date();
|
|
|
|
|
|
if (now.getTime() - date.getTime() > 1000 * 60 * 5) {
|
|
|
- throw new StatusException("102002", "验证码过期");
|
|
|
+ throw new StatusException("101002", "验证码过期");
|
|
|
}
|
|
|
|
|
|
if (!sm.getLastMessage().equals(code)) {
|
|
|
- throw new StatusException("102003", "验证码错误");
|
|
|
+ throw new StatusException("101003", "验证码错误");
|
|
|
} else {
|
|
|
sm.setLastMessage(UUID.randomUUID());
|
|
|
redisClient.set(key, sm);
|