WANG 6 gadi atpakaļ
vecāks
revīzija
c252cab1f5

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

@@ -19,8 +19,6 @@ import cn.com.qmth.examcloud.exchange.inner.api.response.CheckSmsCodeResp;
 import cn.com.qmth.examcloud.exchange.inner.api.response.SendSmsCodeResp;
 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.support.ControllerSupport;
 import cn.com.qmth.examcloud.web.support.WithoutStackTrace;
 import io.swagger.annotations.ApiParam;
@@ -40,14 +38,12 @@ public class SmsCloudServiceProvider extends ControllerSupport implements SmsClo
 	@Override
 	@RequestMapping(method = RequestMethod.POST, value = "sendSms")
 	public SendSmsResp sendSms(@RequestBody @Valid @ApiParam(required = true) SendSmsReq req) {
+
 		String smsAssemblyCode = req.getSmsAssemblyCode();
 		List<String> phoneList = req.getPhoneList();
 		Map<String, String> params = req.getParams();
 
-		// 获取短信配置信息
-		SmsAssemblyCacheBean assemblyCacheBean = CacheHelper.getSmsAssembly(smsAssemblyCode);
-
-		smsService.sendSms(assemblyCacheBean, phoneList, params);
+		smsService.sendSms(smsAssemblyCode, phoneList, params);
 
 		SendSmsResp resp = new SendSmsResp();
 		return resp;

+ 30 - 28
examcloud-exchange-inner-service/src/main/java/cn/com/qmth/examcloud/exchange/inner/service/SmsService.java

@@ -1,38 +1,40 @@
 package cn.com.qmth.examcloud.exchange.inner.service;
 
-import cn.com.qmth.examcloud.support.cache.bean.SmsAssemblyCacheBean;
-
 import java.util.List;
 import java.util.Map;
 
 public interface SmsService {
-    /**
-     * 验证码配置代码
-     */
-    String YZM_SMS_ASSEMBLY_CODE="YZM";
+	/**
+	 * 验证码配置代码
+	 */
+	String YZM_SMS_ASSEMBLY_CODE = "YZM";
 
-    /**
-     * 发送短信
-     *
-     * @param smsAssembly
-     * @param phoneList
-     * @param params
-     */
-    void sendSms(SmsAssemblyCacheBean smsAssembly, List<String> phoneList, Map<String, String> params);
+	/**
+	 * 发送短信
+	 *
+	 * @param smsAssemblyCode
+	 * @param phoneList
+	 * @param params
+	 */
+	void sendSms(String smsAssemblyCode, List<String> phoneList, Map<String, String> params);
 
-    /**
-     * 发送短信验证码
-     *
-     * @param phone 手机号
-     * @param code 验证码
-     */
-    void sendSmsCode(String phone, String code);
+	/**
+	 * 发送短信验证码
+	 *
+	 * @param phone
+	 *            手机号
+	 * @param code
+	 *            验证码
+	 */
+	void sendSmsCode(String phone, String code);
 
-    /**
-     * 校验短信验证码
-     *
-     * @param phone 手机号
-     * @param code 验证码
-     */
-    void validateSmsCode(String phone, String code);
+	/**
+	 * 校验短信验证码
+	 *
+	 * @param phone
+	 *            手机号
+	 * @param code
+	 *            验证码
+	 */
+	void validateSmsCode(String phone, String code);
 }

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

@@ -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);