|
@@ -15,6 +15,9 @@ import org.springframework.stereotype.Service;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.keao.edu.thirdparty.exception.ThirdpartyException;
|
|
|
import com.keao.edu.thirdparty.message.MessageSenderPlugin;
|
|
|
+import com.keao.edu.thirdparty.message.MessageSenderPluginContext;
|
|
|
+import com.keao.edu.thirdparty.message.SendMode;
|
|
|
+import com.keao.edu.thirdparty.message.MessageSenderPluginContext.MessageSender;
|
|
|
import com.keao.edu.util.date.DateUtil;
|
|
|
import com.keao.edu.util.http.HttpUtil;
|
|
|
|
|
@@ -33,8 +36,14 @@ public class YimeiSmsPlugin implements MessageSenderPlugin, InitializingBean {
|
|
|
@Value("${com.properties.sms-host-dev:http://bjmtn.b2m.cn}")
|
|
|
private String host;
|
|
|
|
|
|
- public static String getName() {
|
|
|
- return "yimei";
|
|
|
+ @Override
|
|
|
+ public String getName() {
|
|
|
+ return MessageSender.YIMEI.name();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SendMode sendMode() {
|
|
|
+ return SendMode.SMS;
|
|
|
}
|
|
|
|
|
|
private String getParam(String subject, String content, String receiver, String host) {
|
|
@@ -46,11 +55,9 @@ public class YimeiSmsPlugin implements MessageSenderPlugin, InitializingBean {
|
|
|
param.put("sign", DigestUtils.md5Hex(appId + secretKey + timestamp));
|
|
|
param.put("content", content);
|
|
|
param.put("mobiles", receiver);
|
|
|
-
|
|
|
- long startTime = System.currentTimeMillis();
|
|
|
- String result = HttpUtil.postForHttp(host, param);
|
|
|
- logger.info("调用亿美接口共消耗{}毫秒",System.currentTimeMillis() - startTime);
|
|
|
-
|
|
|
+
|
|
|
+ String result = HttpUtil.postForHttp(host, param);
|
|
|
+
|
|
|
return result;
|
|
|
} catch (Exception e) {
|
|
|
throw new ThirdpartyException("调用发送短信接口出现异常", e);
|
|
@@ -58,7 +65,7 @@ public class YimeiSmsPlugin implements MessageSenderPlugin, InitializingBean {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean send(String subject, String content, String receiver, String url,String jpushType) throws Exception {
|
|
|
+ public boolean send(String subject, String content, String receiver, String url, String jpushType) throws Exception {
|
|
|
String result = getParam(subject, content, receiver, host + "/simpleinter/sendSMS");
|
|
|
JSONObject json = JSONObject.parseObject(result);
|
|
|
if ("SUCCESS".equals(json.get("code"))) {
|
|
@@ -70,7 +77,7 @@ public class YimeiSmsPlugin implements MessageSenderPlugin, InitializingBean {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean batchSend(String subject, String content, String[] receivers, String url,String jpushType) throws Exception {
|
|
|
+ public boolean batchSend(String subject, String content, String[] receivers, String url, String jpushType) throws Exception {
|
|
|
String join = StringUtils.join(receivers, ",");
|
|
|
String result = getParam(subject, content, join, host + "/simpleinter/sendSMS");
|
|
|
logger.info("调用短信接口返回:{}", result);
|
|
@@ -84,6 +91,6 @@ public class YimeiSmsPlugin implements MessageSenderPlugin, InitializingBean {
|
|
|
|
|
|
@Override
|
|
|
public void afterPropertiesSet() throws Exception {
|
|
|
-
|
|
|
+ MessageSenderPluginContext.addMessageSender(this);
|
|
|
}
|
|
|
}
|