mirror of
https://github.com/Weasley-J/chinaport-data-signature.git
synced 2026-10-19 16:15:47 +00:00
Merge branch 'feature_探索'
* feature_探索: - 优化获取抄送邮箱列表 - 优化加签失败邮件通知逻辑 - 优化配置 WebFlux 调用客户端的代码 - update system line separator [feature] rename package
This commit is contained in:
+28
-2
@@ -3,11 +3,15 @@ package cn.alphahub.eport.signature.config;
|
||||
import cn.alphahub.multiple.email.config.EmailConfig;
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import java.util.List;
|
||||
import static cn.alphahub.dtt.plus.util.StringUtils.isBlank;
|
||||
|
||||
/**
|
||||
* email config properties
|
||||
@@ -17,9 +21,11 @@ import java.util.List;
|
||||
* @date 2022/7/15
|
||||
*/
|
||||
@Data
|
||||
@Slf4j
|
||||
@ConditionalOnProperty(prefix = "spring.mail", name = {"enable"}, havingValue = "true")
|
||||
@ConfigurationProperties(prefix = "spring.mail")
|
||||
public class EmailProperties {
|
||||
private static final String REGEXP = "^([A-Za-z0-9_\\-\\.])+\\@([A-Za-z0-9_\\-\\.])+\\.([A-Za-z]{2,4})$";
|
||||
/**
|
||||
* 是否启用邮件通知功能
|
||||
*/
|
||||
@@ -27,7 +33,7 @@ public class EmailProperties {
|
||||
/**
|
||||
* 主收件人的邮箱
|
||||
*/
|
||||
@Email(regexp = "^([A-Za-z0-9_\\-\\.])+\\@([A-Za-z0-9_\\-\\.])+\\.([A-Za-z]{2,4})$", message = "收件人邮箱格式不正确")
|
||||
@Email(regexp = REGEXP, message = "收件人邮箱格式不正确")
|
||||
@NotBlank(message = "主收件人邮箱不能为空")
|
||||
private String to;
|
||||
/**
|
||||
@@ -38,4 +44,24 @@ public class EmailProperties {
|
||||
* 多邮件模板配置列表
|
||||
*/
|
||||
private List<EmailConfig.EmailProperties> emailTemplates;
|
||||
|
||||
/**
|
||||
* 获取抄送邮箱列表
|
||||
*/
|
||||
public String[] getCcEmails() {
|
||||
if (isBlank(cc)) {
|
||||
return new String[0];
|
||||
}
|
||||
String[] ccEmails = cc.split(",");
|
||||
Set<String> emails = new LinkedHashSet<>();
|
||||
for (String ccEmail : ccEmails) {
|
||||
String trimmed = ccEmail.trim();
|
||||
if (!trimmed.matches(REGEXP)) {
|
||||
log.error("The format of the CC email is incorrect: {}", trimmed);
|
||||
} else {
|
||||
emails.add(trimmed);
|
||||
}
|
||||
}
|
||||
return emails.toArray(new String[0]);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-7
@@ -7,6 +7,8 @@ import cn.alphahub.eport.signature.core.web.EportReportResultHttpClient;
|
||||
import cn.alphahub.eport.signature.core.web.WebfluxDemoHttpClient;
|
||||
import cn.alphahub.eport.signature.support.OriginalPropertyNamingStrategy;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.tomcat.util.codec.binary.Base64;
|
||||
@@ -25,9 +27,6 @@ import org.springframework.web.reactive.function.client.support.WebClientAdapter
|
||||
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static cn.alphahub.eport.signature.core.ChinaEportReportClient.EPORT_CEBMESSAGE_SERVER_ENCODE;
|
||||
import static cn.alphahub.eport.signature.core.ChinaEportReportClient.REPORT_PROD_ENV_179_URL_ENCODE;
|
||||
|
||||
@@ -170,11 +169,11 @@ public class WebClientConfiguration {
|
||||
private ExchangeFilterFunction logRequest() {
|
||||
return ExchangeFilterFunction.ofRequestProcessor(clientRequest -> {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("Request URL: " + clientRequest.url());
|
||||
log.info("Request Method: " + clientRequest.method());
|
||||
log.info("Request Headers: " + clientRequest.headers());
|
||||
log.info("Request URL: {}", clientRequest.url());
|
||||
log.info("Request Method: {}", clientRequest.method());
|
||||
log.info("Request Headers: {}", clientRequest.headers());
|
||||
if (clientRequest.method() == HttpMethod.POST || clientRequest.method() == HttpMethod.PUT) {
|
||||
log.info("Request Body: " + clientRequest.body());
|
||||
log.info("Request Body: {}", clientRequest.body());
|
||||
}
|
||||
}
|
||||
return Mono.just(clientRequest);
|
||||
|
||||
+5
-5
@@ -13,6 +13,9 @@ import cn.alphahub.multiple.email.EmailTemplate.SimpleMailMessageDomain;
|
||||
import cn.alphahub.multiple.email.annotation.Email;
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
@@ -25,10 +28,6 @@ import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
/**
|
||||
* 加签websocket客户端基类
|
||||
* <ul><li>全参数构造函数注入IOC</li></ul>
|
||||
@@ -133,6 +132,7 @@ public class WebSocketClientHandler extends TextWebSocketHandler {
|
||||
* @since 2023-06-10
|
||||
*/
|
||||
@Email
|
||||
@SuppressWarnings({"all"})
|
||||
public void sendAlertSignFailure(UkeyResponse ukeyResponse, String messagePayload) {
|
||||
String errorMessage = JacksonUtil.toPrettyJson(ukeyResponse);
|
||||
String subject = "电子口岸 u-key 加签失败提醒";
|
||||
@@ -141,7 +141,7 @@ public class WebSocketClientHandler extends TextWebSocketHandler {
|
||||
log.warn("电子口岸u-key加签数据失败:{}", errorMessage);
|
||||
SimpleMailMessageDomain message = new SimpleMailMessageDomain();
|
||||
message.setTo(emailProperties.getTo());
|
||||
message.setCc(StringUtils.split(emailProperties.getCc(), ","));
|
||||
message.setCc(emailProperties.getCcEmails());
|
||||
message.setSentDate(LocalDateTime.now());
|
||||
message.setSubject(subject);
|
||||
message.setText("");
|
||||
|
||||
+3
-4
@@ -1,8 +1,5 @@
|
||||
package cn.alphahub.eport.signature.support;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -11,6 +8,8 @@ import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 命令行客户端工具类
|
||||
@@ -209,7 +208,7 @@ class RedirectOutputStreamWrapper implements Runnable {
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
if ((line = br.readLine()) != null) {
|
||||
do {
|
||||
outputStream.write(line.concat(System.getProperty("line.separator")).getBytes(StandardCharsets.UTF_8));
|
||||
outputStream.write(line.concat(System.lineSeparator()).getBytes(StandardCharsets.UTF_8));
|
||||
outputStream.flush();
|
||||
} while ((line = br.readLine()) != null);
|
||||
}
|
||||
|
||||
+2
-4
@@ -1,9 +1,7 @@
|
||||
package cn.alphahub.eport.signature.c14;
|
||||
|
||||
package cn.alphahub.eport.signature.c14n;
|
||||
|
||||
import cn.alphahub.eport.signature.core.SignatureHandler;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
/**
|
||||
* Sign CEB311Message With C14n
|
||||
@@ -13,7 +11,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
* @version 1.0
|
||||
* @date 2022-01-11 14:23
|
||||
*/
|
||||
@SpringBootTest
|
||||
|
||||
class C14nEncodeTests {
|
||||
|
||||
@Test
|
||||
+11
@@ -1,5 +1,6 @@
|
||||
package cn.alphahub.eport.signature.config;
|
||||
|
||||
import cn.alphahub.dtt.plus.util.JacksonUtil;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -7,6 +8,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.mail.MailProperties;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
/**
|
||||
* email config 测试类
|
||||
*/
|
||||
@SpringBootTest
|
||||
class EmailPropertiesTest {
|
||||
|
||||
@@ -18,6 +22,7 @@ class EmailPropertiesTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@@ -29,4 +34,10 @@ class EmailPropertiesTest {
|
||||
Boolean enable = emailProperties.getEnable();
|
||||
System.out.println("enable = " + enable);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getCcEmails() {
|
||||
System.out.println(emailProperties.getCc());
|
||||
System.out.println(JacksonUtil.toPrettyJson(emailProperties.getCcEmails()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user