master
wangning 7 years ago
parent f32e2205fb
commit 2b2b5563d4

@ -3,15 +3,13 @@ package au.com.royalpay.payment.manage.notice.core.impls;
import au.com.royalpay.payment.manage.notice.beans.NoticeBean;
import au.com.royalpay.payment.manage.notice.core.MailService;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
import cn.yixblog.platform.http.HttpRequestGenerator;
import cn.yixblog.platform.http.HttpRequestResult;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
@ -27,6 +25,9 @@ import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import cn.yixblog.platform.http.HttpRequestGenerator;
import cn.yixblog.platform.http.HttpRequestResult;
/**
* Created by yishuqian on 18/01/2017.
*/
@ -97,6 +98,12 @@ public class MailServiceImp implements MailService {
noticeBean.setSenderAddress("info@royalpay.com.au");
noticeBean.setPassword("Vaba6439");
String postUrl = mailHost + "/mail?" + generateMailSignParam();
HttpRequestResult result = new HttpRequestGenerator(postUrl, RequestMethod.POST).setJSONEntity(noticeBean).execute();
if (result.isSuccess()) {
String mail_id = result.getResponseContentJSONObj().getString("mail_id");

@ -10,6 +10,7 @@ import au.com.royalpay.payment.manage.notice.beans.NoticeInfo;
import au.com.royalpay.payment.manage.notice.beans.NoticeQuery;
import au.com.royalpay.payment.manage.notice.core.MailService;
import au.com.royalpay.payment.manage.notice.core.NoticeManage;
import au.com.royalpay.payment.manage.system.core.MailGunService;
import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
import au.com.royalpay.payment.tools.utils.PageListUtils;
@ -29,7 +30,9 @@ import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.Resource;
@ -50,6 +53,8 @@ public class NoticeManageImpl implements NoticeManage {
@Resource
private MailService mailService;
@Resource
private MailGunService mailGunService;
@Resource
private RetailAppService retailAppService;
@Resource
private NotifyErrorLogMapper notifyErrorLogMapper;
@ -156,19 +161,13 @@ public class NoticeManageImpl implements NoticeManage {
if (info.getStatus() != null && info.getSend_clients() != null) {
if (info.getStatus().equals("1") && noticeInfo.getString("status").equals("0") && !info.getSend_clients().isEmpty()) {
String client_monikers []=info.getSend_clients().split(",");
List<JSONObject> mailto = new ArrayList<>();
Set<String> mailto = new HashSet<>();
ArrayList<String> mailboxs = new ArrayList<>();
for (String clientMoniker : client_monikers) {
JSONObject client = clientManager.getClientInfoByMoniker(clientMoniker);
JSONObject c = new JSONObject();
c.put("create_time", date);
c.put("notice_id", noticeId);
c.put("client_id", client.getIntValue("client_id"));
noticePartnerMapper.save(c);
String contact_email = client.getString("contact_email");
if (contact_email!=null && !mailboxs.contains(contact_email)){
c.put("mailto",contact_email);
mailto.add(c);
mailto.add(contact_email);
mailboxs.add(contact_email);
}
}
@ -177,17 +176,13 @@ public class NoticeManageImpl implements NoticeManage {
if (info.isIs_tomail_cc_stockholder()){
String stockholder_mails_mailto [] = stockholder_mails.trim().split(",");
for (String stockholder_mailto:stockholder_mails_mailto){
JSONObject stockholder = new JSONObject();
stockholder.put("mailto",stockholder_mailto);
stockholder.put("client_id",0);
mailto.add(stockholder);
mailto.add(stockholder_mailto);
}
}
try {
logger.info(noticeId+"|"+info.getTitle()+"|"+mailto);
String mail_id = mailService.sendEmail(noticeId,info.getTitle(),mailto,info.getContent());
notice.put("mail_id",mail_id);
JSONObject mailResult = mailGunService.sendEmail(noticeId,info.getTitle(),mailto,info.getContent());
notice.put("mail_id",mailResult.getString("mail_id"));
noticeManageMapper.updateNotice(notice);
} catch (URISyntaxException | IOException e) {
e.printStackTrace();

@ -5,6 +5,10 @@ import au.com.royalpay.payment.tools.mail.SendMail;
import com.alibaba.fastjson.JSONObject;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Set;
public interface MailGunService {
void dealNotify(String nofityString) throws Exception;
@ -14,4 +18,7 @@ public interface MailGunService {
JSONObject addClientToMailList(JSONObject client);
JSONObject updateClientOfMailList(JSONObject newClient,JSONObject oldClient);
JSONObject sendEmail(String notice_id, String title, Set<String> mailTo, String content) throws URISyntaxException, IOException ;
}

@ -1,22 +1,31 @@
package au.com.royalpay.payment.manage.system.core.impl;
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
import au.com.royalpay.payment.manage.mappers.system.MailSendMapper;
import au.com.royalpay.payment.manage.system.core.MailGunService;
import au.com.royalpay.payment.tools.connections.attachment.core.AttachmentClient;
import au.com.royalpay.payment.tools.mail.MailGunClient;
import au.com.royalpay.payment.tools.mail.SendMail;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
@ -30,12 +39,11 @@ public class MailGunServiceImpl implements MailGunService {
@Resource
private MailGunClient mailGunClient;
@Resource
private ClientMapper clientMapper;
@Value("${mail.mailgun.default.merchantlist}")
private String mailListDefault;
@Resource
private AttachmentClient attachmentClient;
@Override
public void dealNotify(String nofityString) throws Exception {
@ -68,34 +76,67 @@ public class MailGunServiceImpl implements MailGunService {
JSONObject var = new JSONObject();
var.put("client_moniker", client.getString("client_moniker"));
var.put("short_name", client.getString("short_name"));
result = mailGunClient.addListMember(client.getString("contact_email"),mailListDefault,client.getString("contact_person"),var);
}catch (Exception ignore){
logger.info("add Mail List Failed email:"+client.getString("contact_email")+" client_moniker:"+client.getString("client_moniker"));
result = mailGunClient.addListMember(client.getString("contact_email"), mailListDefault, client.getString("contact_person"), var);
} catch (Exception ignore) {
logger.info("add Mail List Failed email:" + client.getString("contact_email") + " client_moniker:" + client.getString("client_moniker"));
}
return result;
return result;
}
@Override
public JSONObject updateClientOfMailList(JSONObject newClient, JSONObject oldClient) {
JSONObject result= null;
JSONObject result = null;
try {
JSONObject var = new JSONObject();
var.put("client_moniker", newClient.getString("client_moniker"));
var.put("short_name", newClient.getString("short_name"));
result = mailGunClient.updateClientOfMailList(newClient.getString("contact_email"),mailListDefault,newClient.getString("contact_person"),oldClient.getString("contact_email"),var);
}catch (Exception ignore){
logger.info("Modify Mail List Failed oldEmail:"+oldClient.getString("contact_email")+" client_moniker:"+newClient.getString("client_moniker") + " newEmail:"+newClient.getString("contact_email"));
result = mailGunClient.updateClientOfMailList(newClient.getString("contact_email"), mailListDefault, newClient.getString("contact_person"),
oldClient.getString("contact_email"), var);
} catch (Exception ignore) {
logger.info("Modify Mail List Failed oldEmail:" + oldClient.getString("contact_email") + " client_moniker:" + newClient.getString("client_moniker")
+ " newEmail:" + newClient.getString("contact_email"));
}
return result;
return result;
}
@Override
public JSONObject sendEmail(String notice_id, String title, Set<String> mailTo, String content) throws URISyntaxException, IOException {
Document doc = Jsoup.parse(content);
Elements links = doc.select("a[href]");
List<JSONObject> files = new ArrayList<>();
for (Element link : links) {
String linkHref = link.attr("href");
String linkText = link.text();
Element e = link.previousElementSibling();
if (e != null && "img".equalsIgnoreCase(e.tagName())) {
e.remove();
}
if (linkHref.contains("mailto")) {
continue;
}
JSONObject file = new JSONObject();
file.put("name", linkText);
file.put("byteArr", attachmentClient.getFileByUrl(linkHref));
files.add(file);
}
SendMail sendMail = new SendMail();
sendMail.setFrom("postmaster@dev.showcodes.com");
sendMail.setTitle(title);
sendMail.setContent(doc.outerHtml());
sendMail.setNotice_id(notice_id);
sendMail.setMailTos(mailTo);
sendMail.setAttachFiles(files);
return mailGunClient.sendMail(sendMail);
}
public Map<String, String> getQueryMap(String query) {
String[] params = query.split("&");
Map<String, String> map = new HashMap<>();
for (String param : params) {
String [] tmpArr= param.split("=");
if(tmpArr.length<2){
String[] tmpArr = param.split("=");
if (tmpArr.length < 2) {
continue;
}
map.put(tmpArr[0], tmpArr[1]);

Loading…
Cancel
Save