# Conflicts: # src/main/java/au/com/royalpay/payment/manage/task/PartnerInitEmailChecker.java # src/test/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImplTest.javamaster
commit
23258a78bb
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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
|
@ -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…
Reference in new issue