WANG 6 år sedan
förälder
incheckning
9c4f59ec58

+ 1 - 10
examcloud-exchange-inner-api-provider/src/main/java/cn/com/qmth/examcloud/exchange/inner/api/provider/SmsCloudServiceProvider.java

@@ -21,7 +21,6 @@ import cn.com.qmth.examcloud.exchange.inner.api.response.SendSmsResp;
 import cn.com.qmth.examcloud.exchange.inner.service.SmsService;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
 import cn.com.qmth.examcloud.support.cache.bean.SmsAssemblyCacheBean;
-import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.web.support.WithoutStackTrace;
 import io.swagger.annotations.ApiParam;
@@ -48,15 +47,7 @@ public class SmsCloudServiceProvider extends ControllerSupport implements SmsClo
 		// 获取短信配置信息
 		SmsAssemblyCacheBean assemblyCacheBean = CacheHelper.getSmsAssembly(smsAssemblyCode);
 
-		boolean virtualEnable = PropertyHolder.getBoolean("sms.virtual.enable", false);
-
-		if (!virtualEnable) {
-			try {
-				smsService.sendSms(assemblyCacheBean, phoneList, params);
-			} catch (Exception e) {
-				// ignore
-			}
-		}
+		smsService.sendSms(assemblyCacheBean, phoneList, params);
 
 		SendSmsResp resp = new SendSmsResp();
 		return resp;

+ 34 - 32
examcloud-exchange-inner-service/src/main/java/cn/com/qmth/examcloud/exchange/inner/service/impl/SmsServiceImpl.java

@@ -53,16 +53,21 @@ public class SmsServiceImpl implements SmsService {
 	@Override
 	public void sendSms(SmsAssemblyCacheBean smsAssembly, List<String> phoneList,
 			Map<String, String> params) {
-
-		execute(smsAssembly, "SendSms", phoneList, params);
+		boolean virtualEnable = PropertyHolder.getBoolean("sms.virtual.enable", false);
+		if (!virtualEnable) {
+			try {
+				execute(smsAssembly, "SendSms", phoneList, params);
+			} catch (Exception e) {
+				// ignore
+			}
+		}
 	}
 
 	@Override
 	public void sendSmsCode(String phone, String code) {
 		{
 
-			boolean virtualEnable = PropertyHolder.getBoolean("sms.securityCode.virtual.enable",
-					false);
+			boolean virtualEnable = PropertyHolder.getBoolean("sms.smsCode.virtual.enable", false);
 
 			if (virtualEnable) {
 				return;
@@ -119,42 +124,39 @@ public class SmsServiceImpl implements SmsService {
 
 	@Override
 	public void validateSmsCode(String phone, String code) {
-		{
 
-			boolean virtualEnable = PropertyHolder.getBoolean("sms.securityCode.virtual.enable",
-					false);
+		boolean virtualEnable = PropertyHolder.getBoolean("sms.smsCode.virtual.enable", false);
 
-			if (virtualEnable) {
-				String virtualCode = PropertyHolder.getString("sms.securityCode.virtual.code",
-						"5220");
-				if (!virtualCode.equals(code)) {
-					throw new StatusException("102008", "验证码错误");
-				} else {
-					return;
-				}
+		if (virtualEnable) {
+			String virtualCode = PropertyHolder.getString("sms.smsCode.virtual.code", "5220");
+			if (!virtualCode.equals(code)) {
+				throw new StatusException("102008", "验证码错误");
+			} else {
+				return;
 			}
+		}
 
-			String key = "$_SMS:" + phone;
-			ShortMessageInfo sm = redisClient.get(key, ShortMessageInfo.class);
+		String key = "$_SMS:" + phone;
+		ShortMessageInfo sm = redisClient.get(key, ShortMessageInfo.class);
 
-			if (null == sm) {
-				throw new StatusException("102001", "未发送验证码");
-			}
-			List<Date> sendTimeList = sm.getSendTimeList();
-			Date date = sendTimeList.get(sendTimeList.size() - 1);
-			Date now = new Date();
+		if (null == sm) {
+			throw new StatusException("102001", "未发送验证码");
+		}
+		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", "验证码过期");
-			}
+		if (now.getTime() - date.getTime() > 1000 * 60 * 5) {
+			throw new StatusException("102002", "验证码过期");
+		}
 
-			if (!sm.getLastMessage().equals(code)) {
-				throw new StatusException("102003", "验证码错误");
-			} else {
-				sm.setLastMessage(UUID.randomUUID());
-				redisClient.set(key, sm);
-			}
+		if (!sm.getLastMessage().equals(code)) {
+			throw new StatusException("102003", "验证码错误");
+		} else {
+			sm.setLastMessage(UUID.randomUUID());
+			redisClient.set(key, sm);
 		}
+
 	}
 
 	/**