Merge branch 'hotfix-mailpassword' into develop

master
yixian 6 years ago
commit b70b34f55f

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>au.com.royalpay.payment</groupId> <groupId>au.com.royalpay.payment</groupId>
<artifactId>payment-parent</artifactId> <artifactId>payment-parent</artifactId>
<version>0.2.0-dev</version> <version>0.2.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

@ -4,6 +4,8 @@ import au.com.royalpay.payment.manage.mappers.system.MailUnsubMapper;
import au.com.royalpay.payment.manage.merchants.core.ClientManager; import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.manage.notice.beans.NoticeBean; import au.com.royalpay.payment.manage.notice.beans.NoticeBean;
import au.com.royalpay.payment.manage.notice.core.MailService; import au.com.royalpay.payment.manage.notice.core.MailService;
import au.com.royalpay.payment.tools.codec.AESCrypt;
import au.com.royalpay.payment.tools.env.SysConfigManager;
import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.exceptions.NotFoundException; import au.com.royalpay.payment.tools.exceptions.NotFoundException;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException; import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
@ -18,6 +20,8 @@ import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.net.util.Base64;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
@ -26,10 +30,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -53,7 +60,11 @@ public class MailServiceImp implements MailService {
@Resource @Resource
private MailUnsubMapper mailUnsubMapper; private MailUnsubMapper mailUnsubMapper;
@Resource @Resource
private SysConfigManager sysConfigManager;
@Resource
private ClientManager clientManager; private ClientManager clientManager;
@Value("${app.settle.aes-key}")
private String settleAESKey;
/* @Override /* @Override
public void sendEmail(NoticeBean noticeBean) { public void sendEmail(NoticeBean noticeBean) {
@ -79,8 +90,8 @@ public class MailServiceImp implements MailService {
public String sendEmailNotice(String notice_id, String title, List<JSONObject> mailTo, String content) throws URISyntaxException, IOException { public String sendEmailNotice(String notice_id, String title, List<JSONObject> mailTo, String content) throws URISyntaxException, IOException {
List<String> unsubAddress = mailUnsubMapper.getAllAddress(); List<String> unsubAddress = mailUnsubMapper.getAllAddress();
List<JSONObject> mailToWithoutUnsub = new ArrayList<>(); List<JSONObject> mailToWithoutUnsub = new ArrayList<>();
mailTo.parallelStream().forEach(p->{ mailTo.parallelStream().forEach(p -> {
if(!unsubAddress.contains(p.getString("mailto"))){ if (!unsubAddress.contains(p.getString("mailto"))) {
mailToWithoutUnsub.add(p); mailToWithoutUnsub.add(p);
} }
}); });
@ -91,7 +102,7 @@ public class MailServiceImp implements MailService {
String linkHref = link.attr("href"); String linkHref = link.attr("href");
String linkText = link.text(); String linkText = link.text();
Element e = link.previousElementSibling(); Element e = link.previousElementSibling();
if (e!=null && "img".equalsIgnoreCase(e.tagName())) { if (e != null && "img".equalsIgnoreCase(e.tagName())) {
e.remove(); e.remove();
} }
@ -120,17 +131,13 @@ public class MailServiceImp implements MailService {
String postUrl = mailHost + "/mail?" + generateMailSignParam(); String postUrl = mailHost + "/mail?" + generateMailSignParam();
HttpRequestResult result = new HttpRequestGenerator(postUrl, RequestMethod.POST).setJSONEntity(noticeBean).execute(); HttpRequestResult result = new HttpRequestGenerator(postUrl, RequestMethod.POST).setJSONEntity(noticeBean).execute();
if (result.isSuccess()) { if (result.isSuccess()) {
String mail_id = result.getResponseContentJSONObj().getString("mail_id"); String mail_id = result.getResponseContentJSONObj().getString("mail_id");
return mail_id; return mail_id;
//System.out.println("send Mail=============="+mail_id); //System.out.println("send Mail=============="+mail_id);
} else { } else {
throw new ServerErrorException("Error Connection "+result.getStatusCode()); throw new ServerErrorException("Error Connection " + result.getStatusCode());
} }
} }
@ -201,25 +208,25 @@ public class MailServiceImp implements MailService {
@Override @Override
public JSONObject queryUnsubPageable(JSONObject params, int limit, int page) { public JSONObject queryUnsubPageable(JSONObject params, int limit, int page) {
return PageListUtils.buildPageListResult(mailUnsubMapper.queryPageable(params,new PageBounds(page, limit, Order.formString("create_time.desc")))); return PageListUtils.buildPageListResult(mailUnsubMapper.queryPageable(params, new PageBounds(page, limit, Order.formString("create_time.desc"))));
} }
@Override @Override
public void addUnsub(String ClientMoniker) { public void addUnsub(String ClientMoniker) {
JSONObject client = clientManager.getClientInfoByMoniker(ClientMoniker); JSONObject client = clientManager.getClientInfoByMoniker(ClientMoniker);
if(client==null){ if (client == null) {
throw new NotFoundException("Merchant not Found"); throw new NotFoundException("Merchant not Found");
} }
JSONObject existRecord = mailUnsubMapper.getOne(null,client.getString("contact_email")); JSONObject existRecord = mailUnsubMapper.getOne(null, client.getString("contact_email"));
if(existRecord!=null){ if (existRecord != null) {
throw new BadRequestException("Client has already existed"); throw new BadRequestException("Client has already existed");
} }
JSONObject record= new JSONObject(); JSONObject record = new JSONObject();
record.put("id", IdUtil.getId()); record.put("id", IdUtil.getId());
record.put("address",client.getString("contact_email")); record.put("address", client.getString("contact_email"));
record.put("client_id",client.getIntValue("client_id")); record.put("client_id", client.getIntValue("client_id"));
record.put("client_moniker",client.getString("client_moniker")); record.put("client_moniker", client.getString("client_moniker"));
mailUnsubMapper.save(record); mailUnsubMapper.save(record);
} }
@ -234,8 +241,13 @@ public class MailServiceImp implements MailService {
mailClients.add(mailClient); mailClients.add(mailClient);
noticeBean.setMailClients(mailClients); noticeBean.setMailClients(mailClients);
noticeBean.setContent(content); noticeBean.setContent(content);
noticeBean.setSenderAddress("settlement@royalpay.com.au"); JSONObject sysConfig = sysConfigManager.getSysConfig();
noticeBean.setPassword("MMKdMn7dJj49jp"); noticeBean.setSenderAddress(sysConfig.getString("settle.email.address"));
String mailPwdEncrypted = sysConfig.getString("settle.email.password");
Assert.isTrue(StringUtils.isNotEmpty(mailPwdEncrypted), "Settlement mail pwd not configured");
Key aesKey = AESCrypt.fromKeyString(Base64.decodeBase64(settleAESKey));
String mailPwd = new String(AESCrypt.decrypt(Base64.decodeBase64(mailPwdEncrypted), aesKey), StandardCharsets.UTF_8);
noticeBean.setPassword(mailPwd);
noticeBean.setAttachFiles(attachFiles); noticeBean.setAttachFiles(attachFiles);
String postUrl = mailHost + "/mail/single?" + generateMailSignParam(); String postUrl = mailHost + "/mail/single?" + generateMailSignParam();
HttpRequestResult result = null; HttpRequestResult result = null;

@ -115,7 +115,7 @@ royalpay.sms.appkey=43390d81e20c5191c278fbf4cd275be2
im.openim.appkey=24986533 im.openim.appkey=24986533
im.openim.secret=96e28e7be21a874177211c31834b5174 im.openim.secret=96e28e7be21a874177211c31834b5174
app.settle.aes-key=EPrfsM2JE69ZPR7BhXn34g==
#清算银行配置 #清算银行配置
settle.abafile.default-bank=CBA settle.abafile.default-bank=CBA
settle.abafile.remains-to=ANZ settle.abafile.remains-to=ANZ

@ -0,0 +1,29 @@
package au.com.royalpay.payment.manage.process.aes;
import au.com.royalpay.payment.tools.codec.AESCrypt;
import org.apache.commons.net.util.Base64;
import org.junit.Test;
import java.nio.charset.StandardCharsets;
import java.security.Key;
/**
* Create by yixian at 2018-09-17 12:55
*/
public class AESTest {
@Test
public void initAESKey() {
System.out.println(Base64.encodeBase64String(AESCrypt.randomKey().getEncoded()));
}
@Test
public void testEncrypt() {
String keyStr = "EPrfsM2JE69ZPR7BhXn34g==";
String source = "123456";
Key key = AESCrypt.fromKeyString(Base64.decodeBase64(keyStr));
byte[] encrypted = AESCrypt.encrypt(source.getBytes(StandardCharsets.UTF_8), key);
System.out.println("encrypted: " + Base64.encodeBase64String(encrypted));
System.out.println("validate: " + new String(AESCrypt.decrypt(encrypted, key), StandardCharsets.UTF_8));
}
}
Loading…
Cancel
Save