浏览代码

Merge branch 'master' of http://git.dayaedu.com/yonge/mec

周箭河 5 年之前
父节点
当前提交
4242d68ce0
共有 1 个文件被更改,包括 26 次插入19 次删除
  1. 26 19
      mec-thirdparty/src/main/java/com/ym/mec/thirdparty/message/provider/YimeiSmsPlugin.java

+ 26 - 19
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/message/provider/YimeiSmsPlugin.java

@@ -1,24 +1,31 @@
 package com.ym.mec.thirdparty.message.provider;
 
-import com.alibaba.fastjson.JSONObject;
-import com.ym.mec.thirdparty.message.MessageSenderPlugin;
-import com.ym.mec.util.date.DateUtil;
-import com.ym.mec.util.http.HttpUtil;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
+import com.alibaba.fastjson.JSONObject;
+import com.ym.mec.thirdparty.exception.ThirdpartyException;
+import com.ym.mec.thirdparty.message.MessageSenderPlugin;
+import com.ym.mec.util.date.DateUtil;
+import com.ym.mec.util.http.HttpUtil;
 
 /**
  * 亿美短信
  */
 @Service
 public class YimeiSmsPlugin implements MessageSenderPlugin, InitializingBean {
+
+	private Logger logger = LoggerFactory.getLogger(YimeiSmsPlugin.class);
+
 	@Value("${com.properties.sms-appId:EUCP-EMY-SMS1-1AIHP}")
 	private String appId;
 	@Value("${com.properties.sms-secretKey:CBA790799C876DAD}")
@@ -30,30 +37,29 @@ public class YimeiSmsPlugin implements MessageSenderPlugin, InitializingBean {
 		return "yimei";
 	}
 
-	private String getParam(String subject, String content, String receiver,String host){
+	private String getParam(String subject, String content, String receiver, String host) {
 		try {
-			HashMap<String,Object> param = new HashMap();
-			param.put("appId",appId);
-			String timestamp = DateUtil.format(new Date(),new SimpleDateFormat("yyyyMMddHHmmss"));
+			HashMap<String, Object> param = new HashMap();
+			param.put("appId", appId);
+			String timestamp = DateUtil.format(new Date(), new SimpleDateFormat("yyyyMMddHHmmss"));
 			param.put("timestamp", timestamp);
 			param.put("sign", DigestUtils.md5Hex(appId + secretKey + timestamp));
-			param.put("content",content);
-			param.put("mobiles",receiver);
+			param.put("content", content);
+			param.put("mobiles", receiver);
 			return HttpUtil.postForHttp(host, param);
 		} catch (Exception e) {
-			e.printStackTrace();
+			throw new ThirdpartyException("调用发送短信接口出现异常", e);
 		}
-		return "";
 	}
 
 	@Override
 	public boolean send(String subject, String content, String receiver, String url) throws Exception {
 		String result = getParam(subject, content, receiver, host + "/simpleinter/sendSMS");
 		JSONObject json = JSONObject.parseObject(result);
-		if("SUCCESS".equals(json.get("code"))){
+		if ("SUCCESS".equals(json.get("code"))) {
 
 			return true;
-		}else {
+		} else {
 			throw new Exception(json.getString("code"));
 		}
 	}
@@ -62,10 +68,11 @@ public class YimeiSmsPlugin implements MessageSenderPlugin, InitializingBean {
 	public boolean batchSend(String subject, String content, String[] receivers, String url) throws Exception {
 		String join = StringUtils.join(receivers, ",");
 		String result = getParam(subject, content, join, host + "/simpleinter/sendSMS");
+		logger.info("调用短信接口返回:{}", result);
 		JSONObject json = JSONObject.parseObject(result);
-		if("SUCCESS".equals(json.get("code"))){
+		if ("SUCCESS".equals(json.get("code"))) {
 			return true;
-		}else {
+		} else {
 			throw new Exception(json.getString("code"));
 		}
 	}