diff --git a/pom.xml b/pom.xml index 45470f47f..d2d370dfe 100644 --- a/pom.xml +++ b/pom.xml @@ -16,11 +16,6 @@ au.com.royalpay.payment tools - - cn.yixblog - yixblog-platform - 1.2.0 - au.com.royalpay.payment payment-core diff --git a/src/db/modify.sql b/src/db/modify.sql index 33cff6cca..12073aaad 100644 --- a/src/db/modify.sql +++ b/src/db/modify.sql @@ -493,3 +493,16 @@ CREATE TABLE `pmt_directed_bill_code` ( ALTER TABLE `act_red_packets_customer` ADD COLUMN `rule_max_num_limit` tinyint(1) DEFAULT 1 COMMENT '0:Whole Activity,1:day' + +CREATE TABLE `sys_mail_send` ( + `id` int(11) NOT NULL, + `mail_address` varchar(100) NOT NULL COMMENT '邮箱地址', + `cc_mail_address` varchar(100) NOT NULL COMMENT '邮箱地址', + `message_id` varchar(60) NOT NULL COMMENT 'Mailgun Message id', + `status` int(9) NOT NULL DEFAULT 0, + `create_time` datetime not null DEFAULT now(), + `title` varchar(50) NOT NULL comment '邮件标题', + PRIMARY KEY (`id`,`mail_address`), + KEY `mail_address` (`mail_address`), + KEY `id` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 \ No newline at end of file diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/system/MailSendMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/system/MailSendMapper.java new file mode 100644 index 000000000..5d98a5880 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/system/MailSendMapper.java @@ -0,0 +1,24 @@ +package au.com.royalpay.payment.manage.mappers.system; + +import com.alibaba.fastjson.JSONObject; + +import java.util.List; + +import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper; +import cn.yixblog.support.mybatis.autosql.annotations.AutoSql; +import cn.yixblog.support.mybatis.autosql.annotations.SqlType; + +/** + * Create by yixian at 2017-12-13 19:10 + */ +@AutoMapper(tablename = "sys_mail_send", pkName = "id") +public interface MailSendMapper { + @AutoSql(type = SqlType.INSERT) + void save(JSONObject record); + + @AutoSql(type = SqlType.UPDATE) + void update(JSONObject record); + + @AutoSql(type = SqlType.SELECT) + JSONObject find(String emailId, String contact_email); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientManager.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientManager.java index dd3a36ba7..a9e1b0313 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientManager.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientManager.java @@ -71,6 +71,8 @@ public interface ClientManager { void checkEmailStatus(); + void newCheckEmailStatus(); + @Transactional void switchPermission(JSONObject manager, String clientMoniker, String permissionKey, boolean allow); 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..00c29e2c3 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 @@ -29,6 +29,7 @@ import au.com.royalpay.payment.manage.mappers.system.ClientMapper; import au.com.royalpay.payment.manage.mappers.system.ClientRateMapper; import au.com.royalpay.payment.manage.mappers.system.ClientsContractMapper; import au.com.royalpay.payment.manage.mappers.system.CommoditiesMapper; +import au.com.royalpay.payment.manage.mappers.system.MailSendMapper; import au.com.royalpay.payment.manage.mappers.system.ManagerMapper; import au.com.royalpay.payment.manage.mappers.system.OrgMapper; import au.com.royalpay.payment.manage.mappers.system.SysWxMerchantApplyMapper; @@ -69,6 +70,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 +85,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,13 +148,16 @@ 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; import java.util.zip.ZipOutputStream; +import javax.annotation.PostConstruct; import javax.annotation.Resource; import javax.imageio.ImageIO; import javax.servlet.ServletOutputStream; @@ -260,6 +266,10 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid private ClientInfoCacheSupport clientInfoCacheSupport; @Resource private MongoTemplate mongoTemplate; + @Resource + private MailGunService mailGunService; + @Resource + private MailSendMapper mailSendMapper; private static final String SOURCE_AGREE_FILE = "source_agree_file"; private static final String CLIENT_BANK_FILE = "client_bank_file"; @@ -267,6 +277,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid private static final String CLIENT_AGREE_FILE = "client_agree_file"; private static final String CLIENT_COMPANY_FILE = "client_company_file"; private static final String CLIENT_APPLY_FILE = "client_apply_file"; + private static final List tags = new ArrayList<>(); @Value("${app.agreetemplate.classic.path}") private String agreetemplatePdfPath; @@ -276,6 +287,11 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid @Resource private MpWechatApiProvider mpWechatApiProvider; + + @PostConstruct + public void init(){ + tags.add("account"); + } @Override public JSONObject getSysRateConfig() { String rateConfig = sysConfigManager.getSysConfig().getString("sys_rates"); @@ -572,6 +588,11 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid clientApplyMapper.updatePartnerApplication(apply); } } + try { + mailGunService.addClientToMailList(partner); + }catch (Exception e){ + logger.error("邮件列表添加成员失败",e); + } return partner; } @@ -607,6 +628,9 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid } } clientMapper.update(updateInfo); + if(client.getString("contact_email").equals(updateInfo.getString("contact_email"))){ + mailGunService.updateClientOfMailList(updateInfo,client); + } clientInfoCacheSupport.clearClientCache(clientId); } @@ -712,6 +736,9 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid } private void initAdminUserAndSendEmail(JSONObject manager, String clientMoniker, JSONObject client) { + if(StringUtils.isEmpty(client.getString("sub_merchant_id"))){ + throw new BadRequestException("Sub Merchant ID Can't be null "); + } String username = clientMoniker + client.getString("sub_merchant_id"); boolean duplicated = true; String pwd = RandomStringUtils.random(8, true, true); @@ -790,7 +817,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 +828,17 @@ 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.setFrom("info@mail.royalpay.com.au"); + sendMail.setMailTos(to); + sendMail.setMailCcs(emails); + sendMail.setTitle("Your RoyalPay Cross-border Payment has been set up"); + sendMail.setContent(content); + sendMail.setTags(tags); + 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 +872,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 +883,17 @@ 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.setFrom("info@mail.royalpay.com.au"); + sendMail.setMailCcs(emails); + sendMail.setTitle("Your Partner Account Has Been Authenticated Successfully"); + sendMail.setContent(content); + sendMail.setTags(tags); + 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); } @@ -907,6 +950,37 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid } } + @Override + public void newCheckEmailStatus() { + List clients = clientMapper.listClientsWithEmailNotVerify(); + for (JSONObject client : clients) { + try { + String emailId = client.getString("approve_email_id"); + JSONObject status = mailSendMapper.find(emailId,client.getString("contact_email")); + if (status!=null) { + int statusNo = status.getIntValue("status"); + logger.debug("get mail status:" + emailId + "--" + statusNo); + int mailStatus = 3; + switch (statusNo) { + case 1: + mailStatus = 1; + break; + case 2: + mailStatus = 2; + break; + } + updateClientApproveEmailStatus(mailStatus, null, client.getString("client_moniker")); + } else { + logger.debug("get mail status:" + emailId + "-- none"); + // updateClientApproveEmailStatus(client.getIntValue("client_id"), 0); + } + + } catch (Exception e) { + logger.error("check email status failed", e); + } + } + } + @Override public void switchPermission(JSONObject manager, String clientMoniker, String permissionKey, boolean allow) { JSONObject client = getClientInfoByMoniker(clientMoniker); diff --git a/src/main/java/au/com/royalpay/payment/manage/notice/core/impls/MailServiceImp.java b/src/main/java/au/com/royalpay/payment/manage/notice/core/impls/MailServiceImp.java index 7605dcf26..7bf017d05 100644 --- a/src/main/java/au/com/royalpay/payment/manage/notice/core/impls/MailServiceImp.java +++ b/src/main/java/au/com/royalpay/payment/manage/notice/core/impls/MailServiceImp.java @@ -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"); diff --git a/src/main/java/au/com/royalpay/payment/manage/notice/core/impls/NoticeManageImpl.java b/src/main/java/au/com/royalpay/payment/manage/notice/core/impls/NoticeManageImpl.java index 372e414ee..341611d72 100644 --- a/src/main/java/au/com/royalpay/payment/manage/notice/core/impls/NoticeManageImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/notice/core/impls/NoticeManageImpl.java @@ -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 mailto = new ArrayList<>(); + Set mailto = new HashSet<>(); ArrayList 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(); diff --git a/src/main/java/au/com/royalpay/payment/manage/settlement/core/impls/ManualSettleSupportImpl.java b/src/main/java/au/com/royalpay/payment/manage/settlement/core/impls/ManualSettleSupportImpl.java index bcaf9412a..77942c37a 100644 --- a/src/main/java/au/com/royalpay/payment/manage/settlement/core/impls/ManualSettleSupportImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/settlement/core/impls/ManualSettleSupportImpl.java @@ -12,18 +12,21 @@ import au.com.royalpay.payment.tools.locale.LocaleSupport; import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider; import au.com.royalpay.payment.tools.permission.enums.PartnerRole; import au.com.royalpay.payment.tools.utils.CurrencyAmountUtils; + import com.alibaba.fastjson.JSONObject; + import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateUtils; import org.springframework.stereotype.Service; -import javax.annotation.Resource; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; +import javax.annotation.Resource; + /** * Create by yixian at 2018-03-20 17:44 */ 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 b085daed0..fd25de569 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 @@ -9,18 +9,19 @@ import au.com.royalpay.payment.manage.mappers.system.ManagerMapper; import au.com.royalpay.payment.manage.mappers.system.OrgMapper; import au.com.royalpay.payment.manage.merchants.core.ClientConfigService; import au.com.royalpay.payment.manage.merchants.core.ClientManager; -import au.com.royalpay.payment.manage.notice.core.MailService; import au.com.royalpay.payment.manage.signin.beans.ChangePwdBean; import au.com.royalpay.payment.manage.signin.beans.LoginInfo; 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.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; import au.com.royalpay.payment.tools.exceptions.ForbiddenException; import au.com.royalpay.payment.tools.locale.LocaleSupport; +import au.com.royalpay.payment.tools.mail.SendMail; import au.com.royalpay.payment.tools.utils.PasswordUtils; import com.alibaba.fastjson.JSONObject; @@ -39,9 +40,12 @@ import org.thymeleaf.spring4.SpringTemplateEngine; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; +import javax.annotation.PostConstruct; import javax.annotation.Resource; /** @@ -60,7 +64,7 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati @Resource private ClientMapper clientMapper; @Resource - private MailService mailService; + private MailGunService mailService; @Resource private PermissionManager permissionManager; @Resource @@ -72,7 +76,13 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati @Resource private ClientConfigService clientConfigService; private ApplicationEventPublisher publisher; + private static final List tags = new ArrayList<>(); + + @PostConstruct + public void init(){ + tags.add("account"); + } @Override @Cacheable(value = ":login:managers:", key = "''+#accountId") public JSONObject getManager(String accountId) { @@ -306,12 +316,15 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati // final String content = VelocityEngineUtils.mergeTemplateIntoString(null, "mail/reset_password.vm", // "utf-8", map); - new Thread(() -> { - try { - mailService.sendEmail("Reset Password", contact_email, "", content); - } catch (Exception ignored) { - } - }).start(); + SendMail sendMail = new SendMail(); + Set to = new HashSet<>(); + to.add(contact_email); + sendMail.setMailTos(to); + sendMail.setFrom("info@mail.royalpay.com.au"); + sendMail.setTitle("Reset Password"); + sendMail.setContent(content); + sendMail.setTags(tags); + mailService.sendMail(sendMail); return contact_email; @@ -363,4 +376,5 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati account.put("is_password_expired", 0); clientAccountMapper.update(account); } + } diff --git a/src/main/java/au/com/royalpay/payment/manage/system/core/MailGunService.java b/src/main/java/au/com/royalpay/payment/manage/system/core/MailGunService.java new file mode 100644 index 000000000..8e888c0e8 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/system/core/MailGunService.java @@ -0,0 +1,26 @@ +package au.com.royalpay.payment.manage.system.core; + + +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; + + void dealDroppedNotify(String content) throws Exception; + + JSONObject sendMail(SendMail sendMail); + + JSONObject addClientToMailList(JSONObject client); + + JSONObject updateClientOfMailList(JSONObject newClient,JSONObject oldClient); + + JSONObject sendEmail(String notice_id, String title, Set mailTo, String content) throws URISyntaxException, IOException ; + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/system/core/impl/MailGunServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/system/core/impl/MailGunServiceImpl.java new file mode 100644 index 000000000..0676117cb --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/system/core/impl/MailGunServiceImpl.java @@ -0,0 +1,169 @@ +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.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; + +@Service +public class MailGunServiceImpl implements MailGunService { + Logger logger = LoggerFactory.getLogger(getClass()); + + @Resource + private MailSendMapper mailSendMapper; + + @Resource + private MailGunClient mailGunClient; + + @Value("${mail.mailgun.default.merchantlist}") + private String mailListDefault; + + @Resource + private AttachmentClient attachmentClient; + + @Override + public void dealNotify(String nofityString) throws Exception { + String dd = URLDecoder.decode(nofityString, "UTF-8"); + Map mailgunNotify = getQueryMap(dd); + String myData = mailgunNotify.get("my-custom-data"); + String recipient = mailgunNotify.get("recipient"); + if (StringUtils.isNotEmpty(myData) && StringUtils.isNotEmpty(recipient)) { + JSONObject tmpJSONObject = JSONObject.parseObject(myData); + String[] mailAddresses = recipient.split(","); + for (String mailAddress : mailAddresses) { + JSONObject record = new JSONObject(); + record.put("id", tmpJSONObject.getString("id")); + record.put("mail_address", mailAddress); + record.put("status", 1); + mailSendMapper.update(record); + } + } + } + + @Override + public void dealDroppedNotify(String content) throws Exception { + String dd = URLDecoder.decode(content, "UTF-8"); + Map mailgunNotify = getQueryMap(dd); + String myData = mailgunNotify.get("my-custom-data"); + String recipient = mailgunNotify.get("recipient"); + if (StringUtils.isNotEmpty(myData) && StringUtils.isNotEmpty(recipient)) { + JSONObject tmpJSONObject = JSONObject.parseObject(myData); + String[] mailAddresses = recipient.split(","); + for (String mailAddress : mailAddresses) { + JSONObject record = new JSONObject(); + record.put("id", tmpJSONObject.getString("id")); + record.put("mail_address", mailAddress); + record.put("status", 2); + mailSendMapper.update(record); + } + } + } + + @Override + public JSONObject sendMail(SendMail sendMail) { + return mailGunClient.sendMail(sendMail); + } + + @Override + public JSONObject addClientToMailList(JSONObject client) { + JSONObject result = null; + try { + 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")); + } + return result; + } + + @Override + public JSONObject updateClientOfMailList(JSONObject newClient, JSONObject oldClient) { + 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")); + } + return result; + } + + @Override + public JSONObject sendEmail(String notice_id, String title, Set mailTo, String content) throws URISyntaxException, IOException { + List tags = new ArrayList<>(); + tags.add("notice"); + Document doc = Jsoup.parse(content); + Elements links = doc.select("a[href]"); + List 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("info@mail.royalpay.com.au"); + sendMail.setTitle(title); + sendMail.setContent(doc.outerHtml()); + sendMail.setNotice_id(notice_id); + sendMail.setMailTos(mailTo); + sendMail.setAttachFiles(files); + sendMail.setTags(tags); + return mailGunClient.sendMail(sendMail); + } + + + + public Map getQueryMap(String query) { + String[] params = query.split("&"); + Map map = new HashMap<>(); + for (String param : params) { + String[] tmpArr = param.split("="); + if (tmpArr.length < 2) { + continue; + } + map.put(tmpArr[0], tmpArr[1]); + } + return map; + } +} 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 7b172ce52..0452a7c8e 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,5 +1,7 @@ package au.com.royalpay.payment.manage.system.web; +import au.com.royalpay.payment.manage.system.core.MailGunService; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.RequestBody; @@ -7,16 +9,29 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import java.util.Map; - +import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; @RestController @RequestMapping(value = "/mailgun") public class MailCallBackController { - Logger logger = LoggerFactory.getLogger(getClass()); + + private Logger logger = LoggerFactory.getLogger(getClass()); + @Resource + private MailGunService mailService; + @RequestMapping(value = "/callback", method = RequestMethod.POST) - public void contractList(@RequestBody String content, HttpServletRequest req) { - logger.info(content); + public void dealSuccessNptify(@RequestBody String content) throws Exception { + mailService.dealNotify(content); } -} + + + @RequestMapping(value = "/callback/dropped", method = RequestMethod.POST) + public void contractList(HttpServletRequest req, HttpServletResponse res) throws Exception { + logger.info("kira"+req.getRequestURL().toString()); +// logger.info("kira"+content); +// mailService.dealDroppedNotify(content); + } + +} \ No newline at end of file diff --git a/src/main/java/au/com/royalpay/payment/manage/task/PartnerInitEmailChecker.java b/src/main/java/au/com/royalpay/payment/manage/task/PartnerInitEmailChecker.java index b1f1e31cc..4f19c375c 100644 --- a/src/main/java/au/com/royalpay/payment/manage/task/PartnerInitEmailChecker.java +++ b/src/main/java/au/com/royalpay/payment/manage/task/PartnerInitEmailChecker.java @@ -26,7 +26,7 @@ public class PartnerInitEmailChecker { public void checkPartnerInitEmail() { if (PlatformEnvironment.getEnv().taskEnabled()) { synchronizedScheduler.executeProcess("manage_task:checkPartnerInitEmail", 120_000, - () -> clientManager.checkEmailStatus()); + () -> clientManager.newCheckEmailStatus()); } } } diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index f2f13acd0..91173a856 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -1,6 +1,6 @@ spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.schema-name=royalpay_production -spring.datasource.host=192.168.99.103:3306 +spring.datasource.host=192.168.0.49:3306 spring.datasource.url=jdbc:mysql://${spring.datasource.host}/${spring.datasource.schema-name}?useUnicode=true&characterEncoding=utf8&useSSL=false spring.datasource.username=root spring.datasource.password=root \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 7a0ba348a..bc53561d1 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ server.port=5000 -spring.profiles.active=local,alipay,bestpay,jd,wechat +spring.profiles.active=dev,alipay,bestpay,jd,wechat env.company=RoyalPay @@ -99,3 +99,10 @@ app.foreign-currency=AUD app.ofei.md5-key=Khjx6wejblaJzmG0JBWFlPFKAUxhFIXQ app.ofei.pwd=aomi@8888 app.ofei.sp-code=A1407200 + +mail.mailgun.api_key=api:key-2e67b891a1a7974bf3a40ea440d5a77f +mail.mailgun.public_key=api:pubkey-1aaaffc2662ba1b400c409d3e974ba7e +mail.mailgun.domain=mail.royalpay.com.au +mail.mailgun.default.merchantlist=merchants@mail.royalpay.com.au + + diff --git a/src/main/ui/static/risk/templates/risk_history.html b/src/main/ui/static/risk/templates/risk_history.html index baa2e7916..d076acb63 100644 --- a/src/main/ui/static/risk/templates/risk_history.html +++ b/src/main/ui/static/risk/templates/risk_history.html @@ -31,7 +31,7 @@ Client Moniker Create Time - Waring Time + Expire Time Risk Types Status Risk Counts 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 615a1ee29..4c9146935 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 @@ -3,6 +3,10 @@ package au.com.royalpay.payment.manage.apps.core.impls; import au.com.royalpay.payment.manage.mappers.payment.OrderMapper; import au.com.royalpay.payment.manage.mappers.system.ClientMapper; import au.com.royalpay.payment.manage.mappers.system.OrgMapper; +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.codec.binary.Base64; import org.apache.commons.lang3.time.DateUtils; @@ -18,6 +22,8 @@ import java.io.IOException; import java.net.URISyntaxException; import java.nio.charset.Charset; import java.util.Date; +import java.util.HashSet; +import java.util.Set; import javax.annotation.Resource; @@ -28,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 @@ -40,8 +46,9 @@ public class CustomerImpressionImplTest { private ClientMapper clientMapper; @Resource private OrgMapper orgMapper; -// @Resource -// private MailGunClient mailGunClient; + @Resource + private MailGunClient mailGunClient; + // @Test // public void redisQueue() { @@ -87,12 +94,37 @@ public class CustomerImpressionImplTest { // } // } + @Test public void sendSimpleMessage() throws Exception { + String url = "https://api.mailgun.net/v3/dev.showcodes.com/messages?from=postmaster@mail.royalpay.com.au&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()); + + HttpRequestResult res = null; + try { + res = generator.execute(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + System.out.println(res.getException()); + System.out.println(); + System.out.println(); + + try { + System.out.println(res.getResponseContentJSONObj().toJSONString()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void sendSimeMessage() throws Exception { String url = "https://api.mailgun.net/v3/dev.showcodes.com/events"; HttpRequestGenerator generator = new HttpRequestGenerator(url, RequestMethod.POST).addHeader("Authorization", getHeader()); generator.addQueryString("ascending", "yes"); + generator.addQueryString("v:my-custom-data", "123456789"); generator.addQueryString("limit", "12"); System.out.println(String.valueOf(DateUtils.addDays(new Date(),1))); HttpRequestResult res = null; @@ -119,22 +151,24 @@ public class CustomerImpressionImplTest { return authHeader; } -// @Test -// public void sendSimpleMessages() throws Exception { -// SendMail sendMail = new SendMail(); -// sendMail.setContent("

Hi kira

"); -// Set mailCCs = new HashSet<>(); -// mailCCs.add("164851225@qq.com"); -// sendMail.setMailCcs(mailCCs); -// Set mailtos = new HashSet<>(); -// mailtos.add("1029811920@qq.com"); -// sendMail.setMailTos(mailtos); -// sendMail.setTitle("Final Test"); -// -// JSONObject result = mailGunClient.sendMail(sendMail); -// System.out.println(result.toJSONString()); -// System.out.println(result.toJSONString()); -// System.out.println(result.toJSONString()); -// } + @Test + public void sendSimpleMessages() throws Exception { + SendMail sendMail = new SendMail(); + sendMail.setFrom("info@mail.royalpay.com.au"); + sendMail.setContent("

Hi kira

"); + Set mailCCs = new HashSet<>(); + mailCCs.add("asd1159111@163.com"); + sendMail.setMailCcs(mailCCs); + Set mailtos = new HashSet<>(); + mailtos.add("eason.qian@royalpay.com.au"); + mailtos.add("164851225@qq.com"); + sendMail.setMailTos(mailtos); + sendMail.setTitle("Final Test"); + + JSONObject result = mailGunClient.sendMail(sendMail); + System.out.println(result.toJSONString()); + System.out.println(result.toJSONString()); + System.out.println(result.toJSONString()); + } } \ No newline at end of file diff --git a/src/test/java/au/com/royalpay/payment/manage/system/core/impl/MailGunServiceImplTest.java b/src/test/java/au/com/royalpay/payment/manage/system/core/impl/MailGunServiceImplTest.java new file mode 100644 index 000000000..6cc02386f --- /dev/null +++ b/src/test/java/au/com/royalpay/payment/manage/system/core/impl/MailGunServiceImplTest.java @@ -0,0 +1,30 @@ +package au.com.royalpay.payment.manage.system.core.impl; + +import au.com.royalpay.payment.manage.system.core.MailGunService; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +@SpringBootTest +@ActiveProfiles({ "local", "alipay", "wechat", "jd", "bestpay" }) +@RunWith(SpringRunner.class) +public class MailGunServiceImplTest { + + @Resource + 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@mail.royalpay.com.au\"], [\"X-Mailgun-Variables\", \"{\\\"my-custom-data\\\": \\\"{\\\\\\\"key\\\\\\\":\\\\\\\"value\\\\\\\"}\\\"}\"], [\"X-Mailgun-Tag\", \"test1\"], [\"From\", \"postmaster@mail.royalpay.com.au\"], [\"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="; + try { + mailService.dealNotify(dd); + + } catch (Exception e) { + e.printStackTrace(); + } + } +} \ No newline at end of file