| | |
| | | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.pollex.pam.config.ApplicationProperties; |
| | | import com.pollex.pam.config.ApplicationProperties.Email; |
| | | import com.pollex.pam.config.ApplicationProperties.SMS; |
| | | import com.pollex.pam.config.Constants; |
| | | import com.pollex.pam.enums.SendEmailMsgMethod; |
| | | import com.pollex.pam.repository.ConsultantRepository; |
| | | import com.pollex.pam.service.dto.*; |
| | | import com.pollex.pam.service.util.HttpRequestUtil; |
| | |
| | | MailService mailService; |
| | | |
| | | public SendSMSResponse sendMsgBySMS(String toMobile, String content) throws SendSMSFailException { |
| | | if(!applicationProperties.isSendNotifyMsg()) { |
| | | |
| | | SMS smsProperties = applicationProperties.getSms(); |
| | | if(!smsProperties.isSendNotifyMsg()) { |
| | | // return getMockSMSResponse(); |
| | | return null; |
| | | } |
| | | |
| | | SMS smsProperties = applicationProperties.getSms(); |
| | | |
| | | SendSMSRequest sendSMSRequest = new SendSMSRequest(); |
| | | sendSMSRequest.setpKey(UUID.randomUUID().toString()); |
| | |
| | | } |
| | | |
| | | public String sendMsgByEmail(SendMailRequest sendMailRequest) throws SendEmailFailException{ |
| | | if(!applicationProperties.isSendNotifyMsg()) { |
| | | if(environment.acceptsProfiles(Profiles.of(Constants.SPRING_PROFILE_POLLEX_DEVELOPMENT))) { |
| | | String subject = sendMailRequest.getSubject(); |
| | | String content = sendMailRequest.getContent(); |
| | | boolean isHtml = sendMailRequest.isHtmlFormat(); |
| | | final Email emailProperties = applicationProperties.getEmail(); |
| | | |
| | | sendMailRequest.getSendMailAddresses().forEach(receiver -> mailService.sendEmail(receiver, subject, content, false, isHtml)); |
| | | if(!emailProperties.isSendNotifyMsg()) { |
| | | return null; |
| | | } |
| | | |
| | | if(emailProperties.getMethod() == SendEmailMsgMethod.POLLEX_GMAIL) { |
| | | return sendMsgByPollexGmail(sendMailRequest); |
| | | } |
| | | else if(emailProperties.getMethod() == SendEmailMsgMethod.PAM_EMAIL_SERVICE) { |
| | | return sendMsgByPamEmailService(sendMailRequest); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | private String sendMsgByPollexGmail(SendMailRequest sendMailRequest) { |
| | | String subject = sendMailRequest.getSubject(); |
| | | String content = sendMailRequest.getContent(); |
| | | boolean isHtml = sendMailRequest.isHtmlFormat(); |
| | | sendMailRequest.getSendMailAddresses().forEach(receiver -> mailService.sendEmail(receiver, subject, content, false, isHtml)); |
| | | |
| | | return null; |
| | | } |
| | | |
| | | private String sendMsgByPamEmailService(SendMailRequest sendMailRequest) { |
| | | final Email emailProperties = applicationProperties.getEmail(); |
| | | try { |
| | | ResponseEntity<String> responseEntity = |
| | | HttpRequestUtil.postWithJson( applicationProperties.getEmail().getUrl(), sendMailRequest, String.class); |
| | | HttpRequestUtil.postWithJson(emailProperties.getUrl(), sendMailRequest, String.class); |
| | | log.debug("responseEntity = {}", responseEntity); |
| | | |
| | | String rawResponseString = responseEntity.getBody(); |
| | |
| | | } |
| | | |
| | | return responseEntity.getBody(); |
| | | } |
| | | catch (SendEmailFailException e) { |
| | | } catch (SendEmailFailException e) { |
| | | throw e; |
| | | } catch (Exception e) { |
| | | log.warn("send email fail by other reason", e); |