From a46cfe5444cb4f0bb8035562f07a604ca832651d Mon Sep 17 00:00:00 2001 From: wangning <164851225@qq.com> Date: Tue, 15 May 2018 16:37:17 +0800 Subject: [PATCH] modify mail send --- .../core/impls/ClientManagerImpl.java | 34 ++++++++++++++----- .../core/impls/SignInAccountServiceImpl.java | 4 +-- .../{MailService.java => MailGunService.java} | 2 +- ...rviceImpl.java => MailGunServiceImpl.java} | 4 +-- .../system/web/MailCallBackController.java | 4 +-- src/main/resources/application.properties | 2 ++ .../impls/CustomerImpressionImplTest.java | 26 ++++++++++---- ...lTest.java => MailGunServiceImplTest.java} | 6 ++-- 8 files changed, 57 insertions(+), 25 deletions(-) rename src/main/java/au/com/royalpay/payment/manage/system/core/{MailService.java => MailGunService.java} (88%) rename src/main/java/au/com/royalpay/payment/manage/system/core/impl/{MailServiceImpl.java => MailGunServiceImpl.java} (94%) rename src/test/java/au/com/royalpay/payment/manage/system/core/impl/{MailServiceImplTest.java => MailGunServiceImplTest.java} (94%) diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java index f7a08274c..7ac00730b 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java @@ -69,6 +69,7 @@ import au.com.royalpay.payment.manage.signin.beans.TodoNotice; import au.com.royalpay.payment.manage.signin.core.ManagerTodoNoticeProvider; import au.com.royalpay.payment.manage.signin.core.SignInAccountService; import au.com.royalpay.payment.manage.system.core.ClientContractService; +import au.com.royalpay.payment.manage.system.core.MailGunService; import au.com.royalpay.payment.manage.tradelog.beans.TradeLogQuery; import au.com.royalpay.payment.tools.connections.attachment.core.AttachmentClient; import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi; @@ -83,6 +84,7 @@ import au.com.royalpay.payment.tools.exceptions.NotFoundException; import au.com.royalpay.payment.tools.exceptions.ServerErrorException; import au.com.royalpay.payment.tools.exceptions.event.WechatExceptionEvent; import au.com.royalpay.payment.tools.locale.LocaleSupport; +import au.com.royalpay.payment.tools.mail.SendMail; import au.com.royalpay.payment.tools.merchants.beans.QRCodeConfig; import au.com.royalpay.payment.tools.merchants.beans.UpdateSurchargeDTO; import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider; @@ -145,8 +147,10 @@ import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Objects; +import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.zip.ZipEntry; @@ -260,6 +264,8 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid private ClientInfoCacheSupport clientInfoCacheSupport; @Resource private MongoTemplate mongoTemplate; + @Resource + private MailGunService mailGunService; private static final String SOURCE_AGREE_FILE = "source_agree_file"; private static final String CLIENT_BANK_FILE = "client_bank_file"; @@ -790,7 +796,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid if (StringUtils.isEmpty(mailTo)) { throw new EmailException("Client Contact Email is invalid"); } - final List emails = new ArrayList<>(); + final Set emails = new HashSet<>(); for (JSONObject bd : bds) { String email = bd.getString("email"); if (StringUtils.isNotEmpty(email)) { @@ -801,9 +807,15 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid @Override public void run() { try { - String emailId = mailService.sendEmail("Your RoyalPay Cross-border Payment has been set up", mailTo, - emails.isEmpty() ? "" : StringUtils.join(emails, ","), content); - clientModifySupport.processClientModify(new EmailModify(account, client.getString("client_moniker"), 3, emailId)); + SendMail sendMail = new SendMail(); + Set to = new HashSet<>(); + to.add(mailTo); + sendMail.setMailTos(to); + sendMail.setMailCcs(emails); + sendMail.setTitle("Your RoyalPay Cross-border Payment has been set up"); + sendMail.setContent(content); + JSONObject mailResult = mailGunService.sendMail(sendMail); + clientModifySupport.processClientModify(new EmailModify(account, client.getString("client_moniker"), 3, mailResult.getString("mail_id"))); } catch (Exception e) { clientModifySupport.processClientModify(new EmailModify(account, client.getString("client_moniker"), 0, null)); throw new EmailException("Email Sending Failed", e); @@ -837,7 +849,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid } List bds = clientBDMapper.listClientBDInfoAvailable(client.getIntValue("client_id"), new Date()); - final List emails = new ArrayList<>(); + final Set emails = new HashSet<>(); for (JSONObject bd : bds) { String email = bd.getString("email"); if (StringUtils.isNotEmpty(email)) { @@ -848,9 +860,15 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid @Override public void run() { try { - String emailId = mailService.sendEmail("Your Partner Account Has Been Authenticated Successfully", mailTo, - emails.isEmpty() ? "" : StringUtils.join(emails, ","), content); - clientModifySupport.processClientModify(new EmailModify(account, client.getString("client_moniker"), 3, emailId)); + SendMail sendMail = new SendMail(); + Set to = new HashSet<>(); + to.add(mailTo); + sendMail.setMailTos(to); + sendMail.setMailCcs(emails); + sendMail.setTitle("Your Partner Account Has Been Authenticated Successfully"); + sendMail.setContent(content); + JSONObject mailResult = mailGunService.sendMail(sendMail); + clientModifySupport.processClientModify(new EmailModify(account, client.getString("client_moniker"), 3, mailResult.getString("mail_id"))); } catch (Exception e) { throw new EmailException("Email Sending Failed", e); } diff --git a/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInAccountServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInAccountServiceImpl.java index 0435dfd8f..dd6da4053 100644 --- a/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInAccountServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInAccountServiceImpl.java @@ -15,7 +15,7 @@ import au.com.royalpay.payment.manage.signin.core.SignInAccountService; import au.com.royalpay.payment.manage.signin.core.SignInStatusManager; import au.com.royalpay.payment.manage.signin.events.ClientLoginEvent; import au.com.royalpay.payment.manage.signin.events.ManagerLoginEvent; -import au.com.royalpay.payment.manage.system.core.MailService; +import au.com.royalpay.payment.manage.system.core.MailGunService; import au.com.royalpay.payment.tools.env.PlatformEnvironment; import au.com.royalpay.payment.tools.env.RequestEnvironment; import au.com.royalpay.payment.tools.exceptions.BadRequestException; @@ -63,7 +63,7 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati @Resource private ClientMapper clientMapper; @Resource - private MailService mailService; + private MailGunService mailService; @Resource private PermissionManager permissionManager; @Resource diff --git a/src/main/java/au/com/royalpay/payment/manage/system/core/MailService.java b/src/main/java/au/com/royalpay/payment/manage/system/core/MailGunService.java similarity index 88% rename from src/main/java/au/com/royalpay/payment/manage/system/core/MailService.java rename to src/main/java/au/com/royalpay/payment/manage/system/core/MailGunService.java index 542ec8854..984b80281 100644 --- a/src/main/java/au/com/royalpay/payment/manage/system/core/MailService.java +++ b/src/main/java/au/com/royalpay/payment/manage/system/core/MailGunService.java @@ -5,7 +5,7 @@ import au.com.royalpay.payment.tools.mail.SendMail; import com.alibaba.fastjson.JSONObject; -public interface MailService { +public interface MailGunService { void dealNotify(String nofityString) throws Exception; diff --git a/src/main/java/au/com/royalpay/payment/manage/system/core/impl/MailServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/system/core/impl/MailGunServiceImpl.java similarity index 94% rename from src/main/java/au/com/royalpay/payment/manage/system/core/impl/MailServiceImpl.java rename to src/main/java/au/com/royalpay/payment/manage/system/core/impl/MailGunServiceImpl.java index be96a9027..0390287f0 100644 --- a/src/main/java/au/com/royalpay/payment/manage/system/core/impl/MailServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/system/core/impl/MailGunServiceImpl.java @@ -1,7 +1,7 @@ package au.com.royalpay.payment.manage.system.core.impl; import au.com.royalpay.payment.manage.mappers.system.MailSendMapper; -import au.com.royalpay.payment.manage.system.core.MailService; +import au.com.royalpay.payment.manage.system.core.MailGunService; import au.com.royalpay.payment.tools.mail.MailGunClient; import au.com.royalpay.payment.tools.mail.SendMail; @@ -19,7 +19,7 @@ import java.util.Map; import javax.annotation.Resource; @Service -public class MailServiceImpl implements MailService { +public class MailGunServiceImpl implements MailGunService { Logger logger = LoggerFactory.getLogger(getClass()); @Resource diff --git a/src/main/java/au/com/royalpay/payment/manage/system/web/MailCallBackController.java b/src/main/java/au/com/royalpay/payment/manage/system/web/MailCallBackController.java index 250245963..45ea7ac90 100644 --- a/src/main/java/au/com/royalpay/payment/manage/system/web/MailCallBackController.java +++ b/src/main/java/au/com/royalpay/payment/manage/system/web/MailCallBackController.java @@ -1,6 +1,6 @@ package au.com.royalpay.payment.manage.system.web; -import au.com.royalpay.payment.manage.system.core.MailService; +import au.com.royalpay.payment.manage.system.core.MailGunService; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -14,7 +14,7 @@ import javax.annotation.Resource; public class MailCallBackController { @Resource - private MailService mailService; + private MailGunService mailService; @RequestMapping(value = "/callback", method = RequestMethod.POST) public void contractList(@RequestBody String content) throws Exception { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ace9ceb57..316d47f7d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -100,3 +100,5 @@ app.ofei.md5-key=Khjx6wejblaJzmG0JBWFlPFKAUxhFIXQ app.ofei.pwd=aomi@8888 app.ofei.sp-code=A1407200 mail.mailgun.api_key=api:key-96fa3b5866ace125b8ec5a9d27e19353 +mail.mailgun.domain=dev.showcodes.com + diff --git a/src/test/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImplTest.java b/src/test/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImplTest.java index adf357c4e..4e3e7203e 100644 --- a/src/test/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImplTest.java +++ b/src/test/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImplTest.java @@ -34,7 +34,7 @@ import cn.yixblog.platform.http.HttpRequestResult; * Created by wangning on 05/01/2018. */ @SpringBootTest -@ActiveProfiles({ "proxy", "alipay", "wechat", "jd", "bestpay" }) +@ActiveProfiles({ "local", "alipay", "wechat", "jd", "bestpay" }) @RunWith(SpringRunner.class) public class CustomerImpressionImplTest { @Resource @@ -49,6 +49,7 @@ public class CustomerImpressionImplTest { @Resource private MailGunClient mailGunClient; + // @Test // public void redisQueue() { // BoundListOperations ops = stringRedisTemplate.boundListOps("customer_impression"); @@ -96,13 +97,9 @@ public class CustomerImpressionImplTest { @Test public void sendSimpleMessage() throws Exception { - String url = "https://api.mailgun.net/v3/dev.showcodes.com/messages"; + String url = "https://api.mailgun.net/v3/dev.showcodes.com/messages?from=postmaster@dev.showcodes.com&to=164851225@qq.com,1029811920@qq.com&subject=啊是记录&text=暗杀苏&v:my-custom-data={\"key\":\"value\"}"; + String asd = "王宁测试标题"; HttpRequestGenerator generator = new HttpRequestGenerator(url, RequestMethod.POST).addHeader("Authorization", getHeader()); - generator.initFileEntity().attachExternalParam("from", "postmaster@dev.showcodes.com").attachExternalParam("to", "info@dev.showcodes.com") - .attachExternalParam("v:my-custom-data","{\"key\":\"value\"}") - .attachExternalParam("subject", "阿克江啊啊艾克安居客逻辑").attachExternalParam("subscribed", "false") - .attachExternalParam("text", "扯大额卡加二胺二胺傲娇了阿姐拿进来") - .attachExternalParam("html", "

啊看见的那会计师你打卡机难爱的那是的拉屎加上就开始啦看见了

").attachExternalParam("o:tag", "test1"); HttpRequestResult res = null; try { @@ -163,6 +160,21 @@ public class CustomerImpressionImplTest { sendMail.setMailCcs(mailCCs); Set mailtos = new HashSet<>(); mailtos.add("1029811920@qq.com"); + mailtos.add("164851225@qq.com"); + mailtos.add("1@qq.com"); + mailtos.add("5@qq.com"); + mailtos.add("6@qq.com"); + mailtos.add("12@qq.com"); + mailtos.add("13@qq.com"); + mailtos.add("14@qq.com"); + mailtos.add("15@qq.com"); + mailtos.add("16@qq.com"); + mailtos.add("17@qq.com"); + mailtos.add("18@qq.com"); + mailtos.add("19@qq.com"); + mailtos.add("2@qq.com"); + mailtos.add("4@qq.com"); + mailtos.add("3@qq.com"); sendMail.setMailTos(mailtos); sendMail.setTitle("Final Test"); diff --git a/src/test/java/au/com/royalpay/payment/manage/system/core/impl/MailServiceImplTest.java b/src/test/java/au/com/royalpay/payment/manage/system/core/impl/MailGunServiceImplTest.java similarity index 94% rename from src/test/java/au/com/royalpay/payment/manage/system/core/impl/MailServiceImplTest.java rename to src/test/java/au/com/royalpay/payment/manage/system/core/impl/MailGunServiceImplTest.java index 2f423b10a..d929b6259 100644 --- a/src/test/java/au/com/royalpay/payment/manage/system/core/impl/MailServiceImplTest.java +++ b/src/test/java/au/com/royalpay/payment/manage/system/core/impl/MailGunServiceImplTest.java @@ -1,6 +1,6 @@ package au.com.royalpay.payment.manage.system.core.impl; -import au.com.royalpay.payment.manage.system.core.MailService; +import au.com.royalpay.payment.manage.system.core.MailGunService; import org.junit.Test; import org.junit.runner.RunWith; @@ -13,10 +13,10 @@ import javax.annotation.Resource; @SpringBootTest @ActiveProfiles({ "local", "alipay", "wechat", "jd", "bestpay" }) @RunWith(SpringRunner.class) -public class MailServiceImplTest { +public class MailGunServiceImplTest { @Resource - MailService mailService; + MailGunService mailService; @Test public void dealNotify() { String dd= "timestamp=1526298391&token=b7ad8dc0905c46b1c4853200941d30417b4d3f3695815dc729&signature=a3507be4d7ad2b48c4b57202eabd6f63b75abfacd974a9bc7773dc968a12c34e&X-Mailgun-Sid=WyJlMjYwYSIsICI0NjQ1NjMxMThAcXEuY29tIiwgIjQzODY0NiJd&domain=dev.showcodes.com&X-Mailgun-Tag=test1&event=delivered&event-timestamp=1526298391.16&message-headers=[[\"X-Mailgun-Sending-Ip\", \"184.173.153.207\"], [\"X-Mailgun-Sid\", \"WyJlMjYwYSIsICI0NjQ1NjMxMThAcXEuY29tIiwgIjQzODY0NiJd\"], [\"List-Unsubscribe\", \"\"], [\"Received\", \"by luna.mailgun.net with SMTP X-Mailgun-List-Id=5544171, 8794346058393; Mon, 14 May 2018 11:46:29 +0000\"], [\"X-Mailgun-List-Id\", \"5544171\"], [\"X-Mailgun-List-Address\", \"info@dev.showcodes.com\"], [\"List-Id\", \"\"], [\"Received\", \"by luna.mailgun.net with HTTP; Mon, 14 May 2018 11:46:27 +0000\"], [\"Date\", \"Mon, 14 May 2018 11:46:27 +0000\"], [\"Sender\", \"postmaster@dev.showcodes.com\"], [\"X-Mailgun-Variables\", \"{\\\"my-custom-data\\\": \\\"{\\\\\\\"key\\\\\\\":\\\\\\\"value\\\\\\\"}\\\"}\"], [\"X-Mailgun-Tag\", \"test1\"], [\"From\", \"postmaster@dev.showcodes.com\"], [\"Subject\", \"Testqweasdzxc1\"], [\"Mime-Version\", \"1.0\"], [\"Content-Type\", [\"multipart/alternative\", {\"boundary\": \"12109fc0295a479385fcbed01f501455\"}]], [\"Message-Id\", \"<20180514114629.1.2CEFA1D27B4659C4@dev.showcodes.com>\"], [\"To\", \"yz <464563118@qq.com>\"]]&Message-Id=<20180514114629.1.2CEFA1D27B4659C4@dev.showcodes.com>&recipient=464563118@qq.com&my-custom-data={\"id\":\"123\"}&body-plain=";