Merge branch 'mailgun' into develop

# Conflicts:
#	src/main/java/au/com/royalpay/payment/manage/task/PartnerInitEmailChecker.java
#	src/test/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImplTest.java
master
eason.qian 7 years ago
commit 23258a78bb

@ -16,11 +16,6 @@
<groupId>au.com.royalpay.payment</groupId>
<artifactId>tools</artifactId>
</dependency>
<dependency>
<groupId>cn.yixblog</groupId>
<artifactId>yixblog-platform</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>au.com.royalpay.payment</groupId>
<artifactId>payment-core</artifactId>

@ -493,3 +493,15 @@ 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,1day'
CREATE TABLE `sys_mail_send` (
`id` int(11) NOT NULL,
`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

@ -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);
}

@ -71,6 +71,8 @@ public interface ClientManager {
void checkEmailStatus();
void newCheckEmailStatus();
@Transactional
void switchPermission(JSONObject manager, String clientMoniker, String permissionKey, boolean allow);

@ -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,8 +148,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 +265,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";
@ -572,6 +581,11 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
clientApplyMapper.updatePartnerApplication(apply);
}
}
try {
mailGunService.addClientToMailList(partner);
}catch (Exception e){
logger.error("邮件列表添加成员失败",e);
}
return partner;
}
@ -607,6 +621,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);
}
@ -790,7 +807,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
if (StringUtils.isEmpty(mailTo)) {
throw new EmailException("Client Contact Email is invalid");
}
final List<String> emails = new ArrayList<>();
final Set<String> emails = new HashSet<>();
for (JSONObject bd : bds) {
String email = bd.getString("email");
if (StringUtils.isNotEmpty(email)) {
@ -801,9 +818,16 @@ 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<String> to = new HashSet<>();
to.add(mailTo);
sendMail.setFrom("postmaster@mail.royalpay.com.au");
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 +861,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
}
List<JSONObject> bds = clientBDMapper.listClientBDInfoAvailable(client.getIntValue("client_id"), new Date());
final List<String> emails = new ArrayList<>();
final Set<String> emails = new HashSet<>();
for (JSONObject bd : bds) {
String email = bd.getString("email");
if (StringUtils.isNotEmpty(email)) {
@ -848,9 +872,16 @@ 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<String> to = new HashSet<>();
to.add(mailTo);
sendMail.setMailTos(to);
sendMail.setFrom("postmaster@mail.royalpay.com.au");
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);
}
@ -907,6 +938,37 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
}
}
@Override
public void newCheckEmailStatus() {
List<JSONObject> 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);

@ -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();

@ -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
*/
@ -73,7 +76,7 @@ public class ManualSettleSupportImpl implements ManualSettleSupport {
@Override
public JSONObject findCurrentSettle(int clientId, boolean includingUnsettleData) {
JSONObject client = merchantInfoProvider.getClientInfo(clientId);
JSONObject client = merchantInfoProvider.getClientInfoWithConfig(clientId);
if (!client.getBooleanValue("manual_settle")) {
throw new ForbiddenException("Manual Settlement Not Enabled");
}

@ -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,8 +40,10 @@ 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.Resource;
@ -60,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
@ -306,12 +309,14 @@ 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<String> to = new HashSet<>();
to.add(contact_email);
sendMail.setMailTos(to);
sendMail.setFrom("postmaster@mail.royalpay.com.au");
sendMail.setTitle("Reset Password");
sendMail.setContent(content);
mailService.sendMail(sendMail);
return contact_email;
@ -363,4 +368,5 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
account.put("is_password_expired", 0);
clientAccountMapper.update(account);
}
}

@ -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<String> mailTo, String content) throws URISyntaxException, IOException ;
}

@ -0,0 +1,167 @@
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<String, String> 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<String, String> 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<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@mail.royalpay.com.au");
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) {
continue;
}
map.put(tmpArr[0], tmpArr[1]);
}
return map;
}
}

@ -1,22 +1,30 @@
package au.com.royalpay.payment.manage.system.web;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import au.com.royalpay.payment.manage.system.core.MailGunService;
import org.springframework.web.bind.annotation.RequestBody;
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.servlet.http.HttpServletRequest;
import javax.annotation.Resource;
@RestController
@RequestMapping(value = "/mailgun")
public class MailCallBackController {
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(@RequestBody String content) throws Exception {
mailService.dealDroppedNotify(content);
}
}

@ -27,6 +27,7 @@ public class PartnerInitEmailChecker {
if (PlatformEnvironment.getEnv().taskEnabled()) {
synchronizedScheduler.executeProcess("manage_task:checkPartnerInitEmail", 120_000,
() -> clientManager.checkEmailStatus());
// clientManager.newCheckEmailStatus();
}
}
}

@ -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

@ -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

@ -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("<html><p>Hi kira</p ></html>");
// Set<String> mailCCs = new HashSet<>();
// mailCCs.add("164851225@qq.com");
// sendMail.setMailCcs(mailCCs);
// Set<String> 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("postmaster@mail.royalpay.com.au");
sendMail.setContent("<html><p>Hi kira</p ></html>");
Set<String> mailCCs = new HashSet<>();
mailCCs.add("asd1159111@163.com");
sendMail.setMailCcs(mailCCs);
Set<String> mailtos = new HashSet<>();
mailtos.add("1029811920@qq.com");
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());
}
}

@ -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\", \"<mailto:u+mq6timzygy2dmjtjhuzdamjyga2tcnbrge2dmmrzfyys4msdivdecmkegi3uenbwgu4ugnbfgqygizlwfzzwq33xmnxwizltfzrw63jgna6tgmbummzdqnjzga2tkylggfqwkzjqhbrwiyzumzqtkztgg44donrgnu6tknjugqytomjgoi6tinrugu3dgmjrhastimdroexgg33nezwxslldovzxi33nfvsgc5dbhustoqrfgizgwzlzeuzdejjtiestemtwmfwhkzjfgizckn2e@dev.showcodes.com>\"], [\"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\", \"<info.dev.showcodes.com>\"], [\"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();
}
}
}
Loading…
Cancel
Save