From 4400820b75440188f463f87e0b91564b88b512b4 Mon Sep 17 00:00:00 2001 From: wayne <wayne8692wayne8692@gmail.com> Date: 星期五, 17 十二月 2021 16:13:36 +0800 Subject: [PATCH] Merge branch '簡訊與信箱' --- pamapi/src/main/resources/config/application-dev.yml | 8 pamapi/src/main/java/com/pollex/pam/service/dto/SMSDetail.java | 26 ++ pamapi/src/main/java/com/pollex/pam/web/rest/TestSendMsgResource.java | 33 ++ pamapi/src/main/java/com/pollex/pam/web/rest/errors/SendEmailFailException.java | 12 + pamapi/src/main/java/com/pollex/pam/service/util/HttpRequestUtil.java | 114 +++++++++ pamapi/src/main/java/com/pollex/pam/config/SecurityConfiguration.java | 1 pamapi/src/main/resources/config/application-sit.yml | 8 pamapi/src/main/java/com/pollex/pam/service/SendMsgService.java | 107 ++++++++ pamapi/src/main/java/com/pollex/pam/service/dto/SendMailRequest.java | 103 ++++++++ pamapi/src/main/java/com/pollex/pam/web/rest/errors/SendSMSFailException.java | 12 + pamapi/src/main/resources/config/application-uat.yml | 8 pamapi/src/main/java/com/pollex/pam/config/ApplicationProperties.java | 78 ++++++ pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java | 6 pamapi/src/main/java/com/pollex/pam/service/dto/SendSMSRequest.java | 99 ++++++++ pamapi/src/main/java/com/pollex/pam/service/dto/SendMailResponse.java | 39 +++ pamapi/src/main/java/com/pollex/pam/service/dto/SendSMSResponse.java | 60 +++++ 16 files changed, 711 insertions(+), 3 deletions(-) diff --git a/pamapi/src/main/java/com/pollex/pam/config/ApplicationProperties.java b/pamapi/src/main/java/com/pollex/pam/config/ApplicationProperties.java index 6f79c28..3841d13 100644 --- a/pamapi/src/main/java/com/pollex/pam/config/ApplicationProperties.java +++ b/pamapi/src/main/java/com/pollex/pam/config/ApplicationProperties.java @@ -18,6 +18,8 @@ private String eServiceLoginUrl; private String eServiceLoginFunc; private String eServiceLoginSys; + private SMS sms; + private Email email; public boolean isMockLogin() { return mockLogin; @@ -74,4 +76,80 @@ public void seteServiceLoginSys(String eServiceLoginSys) { this.eServiceLoginSys = eServiceLoginSys; } + + public SMS getSms() { + return sms; + } + + public void setSms(SMS sms) { + this.sms = sms; + } + + public Email getEmail() { + return email; + } + + public void setEmail(Email email) { + this.email = email; + } + + public static class SMS { + private String url; + private String sourceCode; + private String sender; + private String smsType; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getSourceCode() { + return sourceCode; + } + + public void setSourceCode(String sourceCode) { + this.sourceCode = sourceCode; + } + + public String getSender() { + return sender; + } + + public void setSender(String sender) { + this.sender = sender; + } + + public String getSmsType() { + return smsType; + } + + public void setSmsType(String smsType) { + this.smsType = smsType; + } + } + + public static class Email { + private String url; + private String functionId; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getFunctionId() { + return functionId; + } + + public void setFunctionId(String functionId) { + this.functionId = functionId; + } + } } diff --git a/pamapi/src/main/java/com/pollex/pam/config/SecurityConfiguration.java b/pamapi/src/main/java/com/pollex/pam/config/SecurityConfiguration.java index 6fca6d3..45c2e6d 100644 --- a/pamapi/src/main/java/com/pollex/pam/config/SecurityConfiguration.java +++ b/pamapi/src/main/java/com/pollex/pam/config/SecurityConfiguration.java @@ -82,6 +82,7 @@ .antMatchers("/api/register").permitAll() .antMatchers("/api/activate").permitAll() .antMatchers("/api/testLogin/**").permitAll() + .antMatchers("/api/test/sendMsg/**").permitAll() .antMatchers("/api/otp/**").permitAll() .antMatchers("/api/login/validate/**").permitAll() .antMatchers("/api/eService/authenticate").permitAll() diff --git a/pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java b/pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java index 9a90c5e..06c3fe0 100644 --- a/pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java +++ b/pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java @@ -8,6 +8,7 @@ import com.pollex.pam.security.token.EServiceAuthenticationToken; import com.pollex.pam.service.LoginRecordService; import com.pollex.pam.service.dto.EServiceResponse; +import com.pollex.pam.service.util.HttpRequestUtil; import com.pollex.pam.web.rest.errors.EServiceErrorException; import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; @@ -21,7 +22,6 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.security.authentication.AuthenticationServiceException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; @@ -105,7 +105,7 @@ private ResponseEntity<EServiceResponse> loginByEService(String account, String paxxword) throws JsonProcessingException, GeneralSecurityException { RestTemplate restTemplate = getTrustAllRestTemplate(); - settingMessageConvertesToSpecifyType(restTemplate, MediaType.ALL); + settingMessageConvertersToSpecifyType(restTemplate, MediaType.ALL); String urlTemplate = UriComponentsBuilder.fromHttpUrl(applicationProperty.geteServiceLoginUrl()) .queryParam("func", applicationProperty.geteServiceLoginFunc()) @@ -140,7 +140,7 @@ return new RestTemplate(requestFactory); } - private void settingMessageConvertesToSpecifyType(RestTemplate restTemplate, MediaType mediaType) { + private void settingMessageConvertersToSpecifyType(RestTemplate restTemplate, MediaType mediaType) { List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); converter.setSupportedMediaTypes(Collections.singletonList(mediaType)); diff --git a/pamapi/src/main/java/com/pollex/pam/service/SendMsgService.java b/pamapi/src/main/java/com/pollex/pam/service/SendMsgService.java new file mode 100644 index 0000000..650fbac --- /dev/null +++ b/pamapi/src/main/java/com/pollex/pam/service/SendMsgService.java @@ -0,0 +1,107 @@ +package com.pollex.pam.service; + +import com.pollex.pam.config.ApplicationProperties; +import com.pollex.pam.config.ApplicationProperties.SMS; +import com.pollex.pam.service.dto.*; +import com.pollex.pam.service.util.HttpRequestUtil; +import com.pollex.pam.web.rest.errors.SendEmailFailException; +import com.pollex.pam.web.rest.errors.SendSMSFailException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; + +import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Base64; +import java.util.Base64.Encoder; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +@Service +public class SendMsgService { + + private static final Logger log = LoggerFactory.getLogger(SendMsgService.class); + private final Encoder encoder = Base64.getEncoder(); + + @Autowired + ApplicationProperties applicationProperties; + + public void sendMsgBySMS(String toMobile, String content) throws SendSMSFailException{ + SMS smsProperties = applicationProperties.getSms(); + + SendSMSRequest sendSMSRequest = new SendSMSRequest(); + sendSMSRequest.setpKey(UUID.randomUUID().toString()); + sendSMSRequest.setSourceCode(smsProperties.getSourceCode()); + sendSMSRequest.setSender(smsProperties.getSender()); + sendSMSRequest.setMsgTypeSet(smsProperties.getSmsType()); + sendSMSRequest.setSendTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:00"))); + sendSMSRequest.setSubject(""); + sendSMSRequest.setActivityId(""); + + SMSDetail smsDetail = new SMSDetail(); + smsDetail.setMobile(toMobile); + smsDetail.setContent(encoder.encodeToString(content.getBytes(StandardCharsets.UTF_8))); + + sendSMSRequest.setDetail(Collections.singletonList(smsDetail)); + + try { + ResponseEntity<SendSMSResponse> responseEntity = HttpRequestUtil.postWithJson(smsProperties.getUrl(), sendSMSRequest, SendSMSResponse.class); + + log.debug("response status code = {}", responseEntity.getStatusCode()); + log.debug("smsResponse = {}", responseEntity.getBody()); + + // todo ����閬�����隤方������葫�� + } + catch (Exception e) { + log.debug("send sms failed!", e); + throw new SendSMSFailException(); + } + } + + public void sendMsgByEmail(String from, String to, String subject, String content, boolean htmlFormat) throws SendEmailFailException{ + sendMsgByEmail(from, to, subject, content, htmlFormat, Collections.emptyList(), Collections.emptyList()); + } + + public void sendMsgByEmail( + String fromAddress, String toAddress, String subject, String content, boolean htmlFormat, List<String> toCCAddress, + List<String> attachments) throws SendEmailFailException + { + SendMailRequest sendMailRequest = new SendMailRequest(); + sendMailRequest.setSendMailAddresses(Collections.singletonList(toAddress)); + sendMailRequest.setFrom(fromAddress); + sendMailRequest.setContent(content); + sendMailRequest.setSubject(subject); + sendMailRequest.setSendCCMailAddresses(toCCAddress); + sendMailRequest.setAttachments(attachments); + sendMailRequest.setHtmlFormat(htmlFormat); + sendMailRequest.setFunctionId(applicationProperties.getEmail().getFunctionId()); + + sendMsgByEmail(sendMailRequest); + } + + public void sendMsgByEmail(SendMailRequest sendMailRequest) throws SendEmailFailException{ + try { + ResponseEntity<SendMailResponse> responseEntity = + HttpRequestUtil.postWithJson( applicationProperties.getEmail().getUrl(), sendMailRequest, SendMailResponse.class); + + SendMailResponse sendMailResponse = responseEntity.getBody(); + log.debug("response status code = {}", responseEntity.getStatusCode()); + log.debug("emailResponse = {}", responseEntity.getBody()); + + if(sendMailResponse == null || sendMailResponse.getData() == null || "ADDED".equalsIgnoreCase(sendMailResponse.getData().getMessageStatus())) { + throw new SendEmailFailException(); + } + } + catch (SendEmailFailException e) { + throw e; + } + catch (Exception e) { + log.debug("send email failed!", e); + throw new SendEmailFailException(); + } + } +} diff --git a/pamapi/src/main/java/com/pollex/pam/service/dto/SMSDetail.java b/pamapi/src/main/java/com/pollex/pam/service/dto/SMSDetail.java new file mode 100644 index 0000000..8cbc3da --- /dev/null +++ b/pamapi/src/main/java/com/pollex/pam/service/dto/SMSDetail.java @@ -0,0 +1,26 @@ +package com.pollex.pam.service.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class SMSDetail { + private String mobile; + private String content; + + @JsonProperty("mobile") + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile; + } + + @JsonProperty("content") + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } +} diff --git a/pamapi/src/main/java/com/pollex/pam/service/dto/SendMailRequest.java b/pamapi/src/main/java/com/pollex/pam/service/dto/SendMailRequest.java new file mode 100644 index 0000000..2470a67 --- /dev/null +++ b/pamapi/src/main/java/com/pollex/pam/service/dto/SendMailRequest.java @@ -0,0 +1,103 @@ +package com.pollex.pam.service.dto; + +import java.util.List; + +public class SendMailRequest { + + /** + * �隞嗉�� + */ + private List<String> sendMailAddresses; + /** + * �� + */ + private List<String> sendCCMailAddresses; + /** + * 銝駁�� + */ + private String subject; + /** + * ���� + */ + private String content; + /** + * 撖辣�� + */ + private String from; + /** + * ��辣頝臬�� + */ + private List<String> attachments; + /** + * �� html format + */ + private boolean htmlFormat; + /** + * �摰儔閮���� (������������神甇餃�pos) + */ + private String functionId; + + public List<String> getSendMailAddresses() { + return sendMailAddresses; + } + + public void setSendMailAddresses(List<String> sendMailAddresses) { + this.sendMailAddresses = sendMailAddresses; + } + + public List<String> getSendCCMailAddresses() { + return sendCCMailAddresses; + } + + public void setSendCCMailAddresses(List<String> sendCCMailAddresses) { + this.sendCCMailAddresses = sendCCMailAddresses; + } + + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public List<String> getAttachments() { + return attachments; + } + + public void setAttachments(List<String> attachments) { + this.attachments = attachments; + } + + public boolean isHtmlFormat() { + return htmlFormat; + } + + public void setHtmlFormat(boolean htmlFormat) { + this.htmlFormat = htmlFormat; + } + + public String getFunctionId() { + return functionId; + } + + public void setFunctionId(String functionId) { + this.functionId = functionId; + } +} diff --git a/pamapi/src/main/java/com/pollex/pam/service/dto/SendMailResponse.java b/pamapi/src/main/java/com/pollex/pam/service/dto/SendMailResponse.java new file mode 100644 index 0000000..808dcf6 --- /dev/null +++ b/pamapi/src/main/java/com/pollex/pam/service/dto/SendMailResponse.java @@ -0,0 +1,39 @@ +package com.pollex.pam.service.dto; + +public class SendMailResponse { + private Data data; + + public Data getData() { + return data; + } + + public void setData(Data data) { + this.data = data; + } + + public static class Data { + private String messageStatus; + + public String getMessageStatus() { + return messageStatus; + } + + public void setMessageStatus(String messageStatus) { + this.messageStatus = messageStatus; + } + + @Override + public String toString() { + return "Data{" + + "messageStatus='" + messageStatus + '\'' + + '}'; + } + } + + @Override + public String toString() { + return "SendMailResponse{" + + "data=" + data + + '}'; + } +} diff --git a/pamapi/src/main/java/com/pollex/pam/service/dto/SendSMSRequest.java b/pamapi/src/main/java/com/pollex/pam/service/dto/SendSMSRequest.java new file mode 100644 index 0000000..de3aa42 --- /dev/null +++ b/pamapi/src/main/java/com/pollex/pam/service/dto/SendSMSRequest.java @@ -0,0 +1,99 @@ +package com.pollex.pam.service.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +public class SendSMSRequest { + + private String pKey; + private String sourceCode; + private String sender; + private String sendTime; + private String subject; + private String activityId; + private String mmsPath; + private String msgTypeSet; + private List<SMSDetail> detail; + + @JsonProperty("p_key") + public String getpKey() { + return pKey; + } + + public void setpKey(String pKey) { + this.pKey = pKey; + } + + @JsonProperty("source_code") + public String getSourceCode() { + return sourceCode; + } + + public void setSourceCode(String sourceCode) { + this.sourceCode = sourceCode; + } + + @JsonProperty("sender") + public String getSender() { + return sender; + } + + public void setSender(String sender) { + this.sender = sender; + } + + @JsonProperty("send_time") + public String getSendTime() { + return sendTime; + } + + public void setSendTime(String sendTime) { + this.sendTime = sendTime; + } + + @JsonProperty("subject") + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + @JsonProperty("activity_id") + public String getActivityId() { + return activityId; + } + + public void setActivityId(String activityId) { + this.activityId = activityId; + } + + @JsonProperty("mms_path") + public String getMmsPath() { + return mmsPath; + } + + public void setMmsPath(String mmsPath) { + this.mmsPath = mmsPath; + } + + @JsonProperty("msg_type_set") + public String getMsgTypeSet() { + return msgTypeSet; + } + + public void setMsgTypeSet(String msgTypeSet) { + this.msgTypeSet = msgTypeSet; + } + + @JsonProperty("detail") + public List<SMSDetail> getDetail() { + return detail; + } + + public void setDetail(List<SMSDetail> detail) { + this.detail = detail; + } +} diff --git a/pamapi/src/main/java/com/pollex/pam/service/dto/SendSMSResponse.java b/pamapi/src/main/java/com/pollex/pam/service/dto/SendSMSResponse.java new file mode 100644 index 0000000..9073766 --- /dev/null +++ b/pamapi/src/main/java/com/pollex/pam/service/dto/SendSMSResponse.java @@ -0,0 +1,60 @@ +package com.pollex.pam.service.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class SendSMSResponse { + + @JsonProperty("p_key") + private String pKey; + + @JsonProperty("return_code") + private String returnCode; + + @JsonProperty("msg_batchNo") + private String msgBatchNo; + + @JsonProperty("error_msg") + private String errorMsg; + + public String getpKey() { + return pKey; + } + + public void setpKey(String pKey) { + this.pKey = pKey; + } + + public String getReturnCode() { + return returnCode; + } + + public void setReturnCode(String returnCode) { + this.returnCode = returnCode; + } + + public String getMsgBatchNo() { + return msgBatchNo; + } + + public void setMsgBatchNo(String msgBatchNo) { + this.msgBatchNo = msgBatchNo; + } + + public String getErrorMsg() { + return errorMsg; + } + + public void setErrorMsg(String errorMsg) { + this.errorMsg = errorMsg; + } + + @Override + public String toString() { + return "SendSMSResponse{" + + "pKey='" + pKey + '\'' + + ", returnCode='" + returnCode + '\'' + + ", msgBatchNo='" + msgBatchNo + '\'' + + ", errorMsg='" + errorMsg + '\'' + + '}'; + } +} diff --git a/pamapi/src/main/java/com/pollex/pam/service/util/HttpRequestUtil.java b/pamapi/src/main/java/com/pollex/pam/service/util/HttpRequestUtil.java new file mode 100644 index 0000000..48cc43b --- /dev/null +++ b/pamapi/src/main/java/com/pollex/pam/service/util/HttpRequestUtil.java @@ -0,0 +1,114 @@ +package com.pollex.pam.service.util; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContexts; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.*; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +import javax.net.ssl.SSLContext; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; +import java.util.Map; +import java.util.Set; + +public final class HttpRequestUtil { + private static final Logger log = LoggerFactory.getLogger(HttpRequestUtil.class); + + private HttpRequestUtil() {} + + public static <T> ResponseEntity<T> getWithJson(String url, Class<T> responseType) + throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException + { + return getWithJson(url, responseType, null); + } + + public static <T> ResponseEntity<T> getWithJson(String url, Class<T> responseType, Map<String, String> addedHeaders) + throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException + { + RestTemplate restTemplate = getTrustAllRestTemplate(); + HttpHeaders headers = new HttpHeaders(); + setHeaders(headers, addedHeaders); + + HttpEntity<String> httpEntity = new HttpEntity<>(headers); + + log.debug("HttpRequestUtil get url: {}", url); + log.debug("httpEntity = {}", httpEntity); + return restTemplate.exchange(url, HttpMethod.GET, httpEntity, responseType); + } + + public static ResponseEntity<String> postWithJson(String url, Object jsonData, Map<String, String> headers) + throws KeyStoreException, NoSuchAlgorithmException, JsonProcessingException, KeyManagementException + { + return postWithJson(url, jsonData, String.class, headers); + } + + public static ResponseEntity<String> postWithJson(String url, Object jsonData) + throws KeyStoreException, NoSuchAlgorithmException, JsonProcessingException, KeyManagementException + { + return postWithJson(url, jsonData, String.class, null); + } + + public static <T> ResponseEntity<T> postWithJson(String url, Object jsonData, Class<T> responseType) + throws KeyStoreException, NoSuchAlgorithmException, JsonProcessingException, KeyManagementException + { + return postWithJson(url, jsonData, responseType, null); + } + + public static <T> ResponseEntity<T> postWithJson(String url, Object jsonData, Class<T> responseType, Map<String, String> addedHeaders) + throws JsonProcessingException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException { + + String parameters = new ObjectMapper().writeValueAsString(jsonData); + // ���摨阡��脰��log���� + if(parameters.length() < 1000){ + log.debug("parameters : {}",parameters); + } + + RestTemplate restTemplate = getTrustAllRestTemplate(); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + setHeaders(headers, addedHeaders); + + HttpEntity<String> entity = new HttpEntity<>(parameters, headers); + + log.debug("rest post with json, url = {}", url); + return restTemplate.exchange(url, HttpMethod.POST, entity, responseType); + } + + private static void setHeaders(HttpHeaders headers, Map<String, String> addedHeaders) { + if(addedHeaders != null && addedHeaders.size() > 0) { + Set<String> keys = addedHeaders.keySet(); + for (String key : keys) { + String headerValue = addedHeaders.get(key); + headers.set(key, headerValue); + log.info("http cust header key: {}", key); + log.info("http cust header headerValue: {}", headerValue); + } + } + } + + private static RestTemplate getTrustAllRestTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { + SSLContext sslContext = SSLContexts.custom() + .loadTrustMaterial(null, (X509Certificate[] x509Certs, String s) -> true) + .build(); + SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier()); + CloseableHttpClient httpClient = HttpClients.custom() + .setSSLSocketFactory(csf) + .build(); + HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); + requestFactory.setHttpClient(httpClient); + requestFactory.setConnectTimeout(300000); + requestFactory.setReadTimeout(300000); + return new RestTemplate(requestFactory); + } +} diff --git a/pamapi/src/main/java/com/pollex/pam/web/rest/TestSendMsgResource.java b/pamapi/src/main/java/com/pollex/pam/web/rest/TestSendMsgResource.java new file mode 100644 index 0000000..c9ff370 --- /dev/null +++ b/pamapi/src/main/java/com/pollex/pam/web/rest/TestSendMsgResource.java @@ -0,0 +1,33 @@ +package com.pollex.pam.web.rest; + +import com.pollex.pam.service.SendMsgService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@Deprecated +@RestController +@RequestMapping("/api/test/sendMsg") +public class TestSendMsgResource { + + @Autowired + SendMsgService sendMsgService; + + @GetMapping("/bySMS") + public ResponseEntity<Void> bySMS(@RequestParam String toMobile, @RequestParam String content) { + sendMsgService.sendMsgBySMS(toMobile, content); + return ResponseEntity.noContent().build(); + } + + @GetMapping("/byEmail") + public ResponseEntity<Void> byEmail( + @RequestParam String from, + @RequestParam String to, + @RequestParam String subject, + @RequestParam String content, + @RequestParam boolean htmlFormat + ) { + sendMsgService.sendMsgByEmail(from, to, subject, content, htmlFormat); + return ResponseEntity.noContent().build(); + } +} diff --git a/pamapi/src/main/java/com/pollex/pam/web/rest/errors/SendEmailFailException.java b/pamapi/src/main/java/com/pollex/pam/web/rest/errors/SendEmailFailException.java new file mode 100644 index 0000000..b43324b --- /dev/null +++ b/pamapi/src/main/java/com/pollex/pam/web/rest/errors/SendEmailFailException.java @@ -0,0 +1,12 @@ +package com.pollex.pam.web.rest.errors; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR, reason = "send email failed") +public class SendEmailFailException extends RuntimeException { + public SendEmailFailException() {} + public SendEmailFailException(String message) { + super(message); + } +} diff --git a/pamapi/src/main/java/com/pollex/pam/web/rest/errors/SendSMSFailException.java b/pamapi/src/main/java/com/pollex/pam/web/rest/errors/SendSMSFailException.java new file mode 100644 index 0000000..acfeda4 --- /dev/null +++ b/pamapi/src/main/java/com/pollex/pam/web/rest/errors/SendSMSFailException.java @@ -0,0 +1,12 @@ +package com.pollex.pam.web.rest.errors; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR, reason = "send email failed") +public class SendSMSFailException extends RuntimeException{ + public SendSMSFailException(){} + public SendSMSFailException(String message) { + super(message); + } +} diff --git a/pamapi/src/main/resources/config/application-dev.yml b/pamapi/src/main/resources/config/application-dev.yml index f81590c..ddf5c77 100644 --- a/pamapi/src/main/resources/config/application-dev.yml +++ b/pamapi/src/main/resources/config/application-dev.yml @@ -119,3 +119,11 @@ e-service-login-url: https://eserviceuat.pcalife.com.tw/sso/chatbotValidate e-service-login-func: ValidateUsrLogin e-service-login-sys: epos + sms: + url: https://localhost:8081/testSMS + source-code: ePos + sender: POS + sms-type: '0017' + email: + url: https://localhost:8081/testEmail + function-id: epos diff --git a/pamapi/src/main/resources/config/application-sit.yml b/pamapi/src/main/resources/config/application-sit.yml index f2bfc56..26a2198 100644 --- a/pamapi/src/main/resources/config/application-sit.yml +++ b/pamapi/src/main/resources/config/application-sit.yml @@ -117,3 +117,11 @@ e-service-login-url: https://eserviceuat.pcalife.com.tw/sso/chatbotValidate e-service-login-func: ValidateUsrLogin e-service-login-sys: epos + sms: + url: https://vtwlifewinbo66.pru.intranet.asia/MesgQueueMgmnt/rest/smsSendMsgResource + source-code: ePos + sender: POS + sms-type: '0017' + email: + url: https://vtwlifeopensysuat.pru.intranet.asia/tsgw/mq/mqSendMail + function-id: epos diff --git a/pamapi/src/main/resources/config/application-uat.yml b/pamapi/src/main/resources/config/application-uat.yml index 58ac9bb..e23f9ac 100644 --- a/pamapi/src/main/resources/config/application-uat.yml +++ b/pamapi/src/main/resources/config/application-uat.yml @@ -117,3 +117,11 @@ e-service-login-url: https://eserviceuat.pcalife.com.tw/sso/chatbotValidate e-service-login-func: ValidateUsrLogin e-service-login-sys: epos + sms: + url: https://vtwlifewinbo66.pru.intranet.asia/MesgQueueMgmnt/rest/smsSendMsgResource + source-code: ePos + sender: POS + sms-type: '0017' + email: + url: https://vtwlifeopensysuat.pru.intranet.asia/tsgw/mq/mqSendMail + function-id: epos -- Gitblit v1.8.0