|
|
@@ -1,6 +1,7 @@
|
|
|
package com.uas.ps.message.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.uas.message.mail.domain.MailLog;
|
|
|
import com.uas.message.mail.service.MailService;
|
|
|
import com.uas.ps.message.dao.AppDao;
|
|
|
import com.uas.ps.message.dao.MessageDao;
|
|
|
@@ -27,9 +28,14 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
/**
|
|
|
* Created by wangyc on 2018/1/13.
|
|
|
@@ -43,23 +49,36 @@ public class MessageServiceImpl implements MessageService {
|
|
|
|
|
|
private final AppDao appDao;
|
|
|
|
|
|
- private final MailService mailService;
|
|
|
+ private RestTemplate restTemplate;
|
|
|
|
|
|
private static final String EMAIL_REGEX = "\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}";
|
|
|
|
|
|
private static final String TEL_REGEXP = "^((\\(\\d{3}\\))|(\\d{3}\\-))?(13|15|18|17)\\d{9}$";
|
|
|
|
|
|
- private final static String PROD_URL = "http://113.105.74.140:8092/tigase/baiduPush";
|
|
|
+ private static final String PROD_URL = "http://113.105.74.140:8092/tigase/baiduPush";
|
|
|
+ /**
|
|
|
+ * 邮件服务主机地址
|
|
|
+ */
|
|
|
+// @Value("#{sys.messageServiceIp ?: 'http://message.ubtob.com/'}")
|
|
|
+ private static final String MAIL_CONSOLE_HOST = "http://message.ubtob.com/";
|
|
|
|
|
|
+ /**
|
|
|
+ * 发送邮件给单个人url
|
|
|
+ */
|
|
|
+ private static final String MAIL_SEND_URL = "mail/send";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送邮件给多个人 url
|
|
|
+ */
|
|
|
+ private static final String MAIL_SEND_MANY_URL = "mail/send/o2m";
|
|
|
/**
|
|
|
* 短信接口
|
|
|
*/
|
|
|
private final String messageUrl = "http://message.ubtob.com/sms/send";
|
|
|
|
|
|
@Autowired
|
|
|
- public MessageServiceImpl(MessageDao messageDao, AppDao appDao, MailService mailService) {
|
|
|
+ public MessageServiceImpl(MessageDao messageDao, AppDao appDao) {
|
|
|
this.messageDao = messageDao;
|
|
|
- this.mailService = mailService;
|
|
|
this.appDao = appDao;
|
|
|
}
|
|
|
|
|
|
@@ -252,17 +271,18 @@ public class MessageServiceImpl implements MessageService {
|
|
|
* @param message 消息
|
|
|
*/
|
|
|
private void sendMail(Message message) {
|
|
|
- Map<String, Object> model = new HashMap<>();
|
|
|
- // TODO 账户中心获取用户邮箱
|
|
|
- String templetId = "";
|
|
|
- User user = FastjsonUtils.fromJson(message.getReceiver(), User.class);
|
|
|
- if (user.getUserEmail() != null && user.getUserEmail().matches(EMAIL_REGEX)) {
|
|
|
- try {
|
|
|
- mailService.send(templetId, user.getUserEmail(), model);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
+ headers.setContentType(type);
|
|
|
+ headers.add("Accept", MediaType.APPLICATION_JSON.toString());
|
|
|
+
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("templateId", message.getMailTemplate());
|
|
|
+ object.put("receiver", message.getReceiver());
|
|
|
+ object.put("params", message.getContent());
|
|
|
+
|
|
|
+ HttpEntity<String> formEntity = new HttpEntity<String>(object.toJSONString(), headers);
|
|
|
+ ResponseEntity<MailLog> responseEntity = restTemplate.postForEntity(MAIL_CONSOLE_HOST + MAIL_SEND_URL, formEntity, MailLog.class);
|
|
|
}
|
|
|
|
|
|
/**
|