diff --git a/invoice/src/main/java/com/djy/invoice/controller/InvLinkInfoController.java b/invoice/src/main/java/com/djy/invoice/controller/InvLinkInfoController.java index 7390183..011aaa1 100644 --- a/invoice/src/main/java/com/djy/invoice/controller/InvLinkInfoController.java +++ b/invoice/src/main/java/com/djy/invoice/controller/InvLinkInfoController.java @@ -6,7 +6,6 @@ import com.djy.invoice.dto.SendEmail; import com.djy.invoice.dto.SendEmailParams; import com.djy.invoice.model.InvLinkInfo; import com.djy.invoice.service.InvLinkInfoService; -import com.djy.invoice.util.SendEmailUtil; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; @@ -27,7 +26,7 @@ public class InvLinkInfoController { @Operation(description = "外部调用接口") @PostMapping("getlink") - public HttpResult getlink(@RequestBody InvLinkInfo info) { + public HttpResult getlink(InvLinkInfo info) { return invLinkInfoService.getlink(info); } @@ -68,27 +67,27 @@ public class InvLinkInfoController { } - @Operation(description = "") - @PostMapping("sendEmail") - public HttpResult sendEmail() { - - SendEmailParams param = new SendEmailParams(); - - List list = new ArrayList<>(); - - SendEmail email = new SendEmail(); - email.setSendTo("475446853@qq.com"); - email.setTitle("发票发送"); - email.setBody("测试正文"); - email.setSmtpConfig("INVOICE"); - list.add(email); - param.setList(list); - - String str = JSONObject.toJSONString(param.getList()); - SendEmailUtil.sendEMail(str); - - return HttpResult.ok("邮件发送成功"); - } +// @Operation(description = "") +// @PostMapping("sendEmail") +// public HttpResult sendEmail() { +// +// SendEmailParams param = new SendEmailParams(); +// +// List list = new ArrayList<>(); +// +// SendEmail email = new SendEmail(); +// email.setSendTo("475446853@qq.com"); +// email.setTitle("发票发送"); +// email.setBody("测试正文"); +// email.setSmtpConfig("INVOICE"); +// list.add(email); +// param.setList(list); +// +// String str = JSONObject.toJSONString(param.getList()); +// SendEmailUtil.sendEMail(str); +// +// return HttpResult.ok("邮件发送成功"); +// } diff --git a/invoice/src/main/java/com/djy/invoice/service/impl/InvLinkInfoServiceImpl.java b/invoice/src/main/java/com/djy/invoice/service/impl/InvLinkInfoServiceImpl.java index 4c53277..7625c34 100644 --- a/invoice/src/main/java/com/djy/invoice/service/impl/InvLinkInfoServiceImpl.java +++ b/invoice/src/main/java/com/djy/invoice/service/impl/InvLinkInfoServiceImpl.java @@ -10,14 +10,15 @@ import com.djy.invoice.model.*; import com.djy.invoice.model.mapper.*; import com.djy.invoice.service.InvLinkInfoService; import com.djy.invoice.service.UploadData; -import com.djy.invoice.util.SendEmailUtil; import lombok.extern.slf4j.Slf4j; +import okhttp3.*; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.io.IOException; import java.math.BigDecimal; import java.text.DateFormat; import java.text.ParseException; @@ -52,6 +53,8 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { private static String subject; + private static String urlPath; + public static BigDecimal invoiceAmount; private static final String dateFormat = "yyyy-MM-dd HH:mm:ss"; private static final DateFormat df = new SimpleDateFormat(dateFormat); @@ -1187,7 +1190,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { param.setList(listEmail); String str = JSONObject.toJSONString(param.getList()); - SendEmailUtil.sendEMail(str); + sendEMail(str); }else{ @@ -1216,28 +1219,25 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { cxParams.setCriteria(criteria); return cxParams; } + public void sendEMail(String json){ + + OkHttpClient client = new OkHttpClient().newBuilder() + .build(); + MediaType mediaType = MediaType.parse("application/json"); + RequestBody body = RequestBody.create(mediaType, json); + Request request = new Request.Builder() + .url(urlPath) + .method("POST", body) + .addHeader("Content-Type", "application/json") + .build(); + try { + Response response = client.newCall(request).execute(); + } catch (IOException e) { + e.printStackTrace(); + } - // 发起请求并显示响应报文 - public void doPost(String cmdName, RequestData requestData) throws Exception { - // 生成请求报文 -// String requestJson = JSON.toJSONStringWithDateFormat(requestData, dateFormat, SerializerFeature.NotWriteRootClassName); -// -// // 对请求报文签名,生成签名字符串 -// String sign = CertificateUtils.signToBase64(requestJson.getBytes(encode), keyStorePath, keyStoreAbner, keyStorePassWord); -// -// // 发起请求并显示响应报文 -// Map vars = new HashMap(); -// vars.put("appCode", URLEncoder.encode(appCode, encode)); -// vars.put("cmdName", URLEncoder.encode(cmdName, encode)); -// vars.put("sign", URLEncoder.encode(sign, encode)); -// String responseJson = HttpUtil.doPost(facadeUrl, vars, requestJson, 10000, 10000); -// System.out.println("响应报文:" + responseJson); -// ResponseData responseData = JSON.parseObject(responseJson, ResponseData.class); -// System.out.println("响应代码:" + responseData.getCode()); -// System.out.println("响应消息:" + responseData.getMessage()); } - public static String getCmdName() { return cmdName; } @@ -1290,4 +1290,10 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { public void setSubject(String subject) { InvLinkInfoServiceImpl.subject = subject; } + + + @Value("${spring.mail.url}") + public void setUrlPath(String urlPath) { + InvLinkInfoServiceImpl.urlPath = urlPath; + } } diff --git a/invoice/src/main/java/com/djy/invoice/util/SendEmailUtil.java b/invoice/src/main/java/com/djy/invoice/util/SendEmailUtil.java deleted file mode 100644 index 6b55e2e..0000000 --- a/invoice/src/main/java/com/djy/invoice/util/SendEmailUtil.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.djy.invoice.util; - -import okhttp3.*; - -import java.io.IOException; - -public class SendEmailUtil { - - public static void sendEMail(String json){ - - OkHttpClient client = new OkHttpClient().newBuilder() - .build(); - MediaType mediaType = MediaType.parse("application/json"); - RequestBody body = RequestBody.create(mediaType, json); - Request request = new Request.Builder() - .url("http://47.104.73.97:8801/mail/send") - .method("POST", body) - .addHeader("Content-Type", "application/json") - .build(); - try { - Response response = client.newCall(request).execute(); - } catch (IOException e) { - e.printStackTrace(); - } - - } -} diff --git a/invoice/src/main/resources/application-dev.yml b/invoice/src/main/resources/application-dev.yml index 4f00041..e00b057 100644 --- a/invoice/src/main/resources/application-dev.yml +++ b/invoice/src/main/resources/application-dev.yml @@ -22,6 +22,7 @@ spring: SendTo: 475446853@qq.com SmtpConfig: INVOICE subject: 发票信息 + url: http://47.104.73.97:8801/mail/send logging: level: root: info