将消息推送实现类移动到core项目下。
This commit is contained in:
@@ -0,0 +1,78 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||||
|
*/
|
||||||
|
package com.jeesite.modules.msg.send;
|
||||||
|
|
||||||
|
import org.apache.commons.mail.HtmlEmail;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.jeesite.common.config.Global;
|
||||||
|
import com.jeesite.common.lang.ExceptionUtils;
|
||||||
|
import com.jeesite.common.lang.StringUtils;
|
||||||
|
import com.jeesite.common.service.BaseService;
|
||||||
|
import com.jeesite.modules.msg.entity.MsgPush;
|
||||||
|
import com.jeesite.modules.msg.entity.content.EmailMsgContent;
|
||||||
|
import com.jeesite.modules.msg.send.MsgSendService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电子邮件发送服务实现
|
||||||
|
* @author ThinkGem
|
||||||
|
* @version 2018年5月13日
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class EmailSendService extends BaseService implements MsgSendService{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(MsgPush msgPush) {
|
||||||
|
try{
|
||||||
|
String fromAddress = Global.getProperty("msg.email.fromAddress");
|
||||||
|
String fromPassword = Global.getProperty("msg.email.fromPassword");
|
||||||
|
String fromHostName = Global.getProperty("msg.email.fromHostName");
|
||||||
|
Integer smtpPort = Global.getPropertyToInteger("msg.email.smtpPort", "25");
|
||||||
|
String sslOnConnect = Global.getProperty("msg.email.sslOnConnect", "false");
|
||||||
|
String sslSmtpPort = Global.getProperty("msg.email.sslSmtpPort", "465");
|
||||||
|
|
||||||
|
HtmlEmail htmlEmail = new HtmlEmail();
|
||||||
|
htmlEmail.setCharset("utf-8");
|
||||||
|
htmlEmail.setFrom(fromAddress);
|
||||||
|
htmlEmail.setAuthentication(fromAddress, fromPassword);
|
||||||
|
htmlEmail.setHostName(fromHostName);
|
||||||
|
htmlEmail.setSmtpPort(smtpPort);
|
||||||
|
if ("true".equals(sslOnConnect)) {
|
||||||
|
htmlEmail.setSSLOnConnect(true);
|
||||||
|
htmlEmail.setSslSmtpPort(sslSmtpPort);
|
||||||
|
}
|
||||||
|
htmlEmail.addTo(msgPush.getReceiveCode(), msgPush.getReceiveUserName());
|
||||||
|
|
||||||
|
// 内容
|
||||||
|
EmailMsgContent content = msgPush.parseMsgContent(EmailMsgContent.class);
|
||||||
|
htmlEmail.setSubject(content.getTitle());
|
||||||
|
htmlEmail.setMsg(content.getContent());
|
||||||
|
|
||||||
|
// 抄送
|
||||||
|
if (StringUtils.isNotBlank(content.getCc())) {
|
||||||
|
for (String email : content.getCc().split(";")) {
|
||||||
|
htmlEmail.addCc(email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 密送
|
||||||
|
if (StringUtils.isNotBlank(content.getBcc())) {
|
||||||
|
for (String email : content.getBcc().split(";")) {
|
||||||
|
htmlEmail.addBcc(email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送邮件
|
||||||
|
String result = htmlEmail.send();
|
||||||
|
|
||||||
|
// 发送成功
|
||||||
|
msgPush.setPushStatus(MsgPush.PUSH_STATUS_SUCCESS);
|
||||||
|
msgPush.addPushReturnContent(result);
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error("发送邮件失败! ", ex);
|
||||||
|
msgPush.setPushStatus(MsgPush.PUSH_STATUS_FAIL);
|
||||||
|
msgPush.addPushReturnContent(ExceptionUtils.getStackTraceAsString(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||||
|
*/
|
||||||
|
package com.jeesite.modules.msg.send;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.jeesite.common.lang.ExceptionUtils;
|
||||||
|
import com.jeesite.common.lang.ObjectUtils;
|
||||||
|
import com.jeesite.common.mapper.JsonMapper;
|
||||||
|
import com.jeesite.common.msg.SmsUtils;
|
||||||
|
import com.jeesite.common.service.BaseService;
|
||||||
|
import com.jeesite.modules.msg.entity.MsgPush;
|
||||||
|
import com.jeesite.modules.msg.entity.content.SmsMsgContent;
|
||||||
|
import com.jeesite.modules.msg.send.MsgSendService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信发送服务实现
|
||||||
|
* @author ThinkGem
|
||||||
|
* @version 2018年5月13日
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class SmsSendService extends BaseService implements MsgSendService{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(MsgPush msgPush) {
|
||||||
|
try{
|
||||||
|
// String url = Global.getProperty("msg.sms.url");
|
||||||
|
// String data = Global.getProperty("msg.sms.data");
|
||||||
|
// String prefix = Global.getProperty("msg.sms.prefix", "");
|
||||||
|
// String suffix = Global.getProperty("msg.sms.suffix", "");
|
||||||
|
// Connection conn = Jsoup.connect(url);
|
||||||
|
// conn.postDataCharset("UTF-8");
|
||||||
|
// conn.method(Method.POST);
|
||||||
|
// for (String param : StringUtils.split(data, "&")){
|
||||||
|
// String[] ss = StringUtils.split(param, "=");
|
||||||
|
// if (ss.length == 1){
|
||||||
|
// conn.data(ss[0], "");
|
||||||
|
// }else if (ss.length == 2){
|
||||||
|
// conn.data(ss[0], ss[1]);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// // 手机号码
|
||||||
|
// conn.data("mobile", msgPush.getReceiveCode());
|
||||||
|
// // 短信内容
|
||||||
|
// SmsMsgContent content = msgPush.parseMsgContent(SmsMsgContent.class);
|
||||||
|
// conn.data("content", prefix + content.getContent() + suffix);
|
||||||
|
// // 发送短信
|
||||||
|
// String result = conn.execute().body();
|
||||||
|
// String result = "{result:0,message:\"ok\"}"; // 模拟发送结果
|
||||||
|
// Map<String, Object> map = JsonMapper.fromJson(result, Map.class);
|
||||||
|
|
||||||
|
// 发送短信
|
||||||
|
SmsMsgContent content = msgPush.parseMsgContent(SmsMsgContent.class);
|
||||||
|
String result = SmsUtils.send(content.getContent(), msgPush.getReceiveCode());
|
||||||
|
Map<String, Object> map = JsonMapper.fromJson(result, Map.class);
|
||||||
|
|
||||||
|
// 发送成功
|
||||||
|
if (ObjectUtils.toInteger(map.get("result")) == 0){
|
||||||
|
msgPush.setPushStatus(MsgPush.PUSH_STATUS_SUCCESS);
|
||||||
|
msgPush.addPushReturnContent(result);
|
||||||
|
}
|
||||||
|
// 发送失败
|
||||||
|
else{
|
||||||
|
throw new RuntimeException(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error("发送短信失败! ", ex);
|
||||||
|
msgPush.setPushDate(new Date());
|
||||||
|
msgPush.setPushStatus(MsgPush.PUSH_STATUS_FAIL);
|
||||||
|
msgPush.addPushReturnContent(ExceptionUtils.getStackTraceAsString(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user