开票邮箱发送发票修改

master
pangyang 2 years ago
parent 9142c713f5
commit 7313116a16

@ -6,7 +6,6 @@ import com.djy.invoice.dto.SendEmail;
import com.djy.invoice.dto.SendEmailParams; import com.djy.invoice.dto.SendEmailParams;
import com.djy.invoice.model.InvLinkInfo; import com.djy.invoice.model.InvLinkInfo;
import com.djy.invoice.service.InvLinkInfoService; 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.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -27,7 +26,7 @@ public class InvLinkInfoController {
@Operation(description = "外部调用接口") @Operation(description = "外部调用接口")
@PostMapping("getlink") @PostMapping("getlink")
public HttpResult getlink(@RequestBody InvLinkInfo info) { public HttpResult getlink(InvLinkInfo info) {
return invLinkInfoService.getlink(info); return invLinkInfoService.getlink(info);
} }
@ -68,27 +67,27 @@ public class InvLinkInfoController {
} }
@Operation(description = "") // @Operation(description = "")
@PostMapping("sendEmail") // @PostMapping("sendEmail")
public HttpResult sendEmail() { // public HttpResult sendEmail() {
//
SendEmailParams param = new SendEmailParams(); // SendEmailParams param = new SendEmailParams();
//
List<SendEmail> list = new ArrayList<>(); // List<SendEmail> list = new ArrayList<>();
//
SendEmail email = new SendEmail(); // SendEmail email = new SendEmail();
email.setSendTo("475446853@qq.com"); // email.setSendTo("475446853@qq.com");
email.setTitle("发票发送"); // email.setTitle("发票发送");
email.setBody("测试正文"); // email.setBody("测试正文");
email.setSmtpConfig("INVOICE"); // email.setSmtpConfig("INVOICE");
list.add(email); // list.add(email);
param.setList(list); // param.setList(list);
//
String str = JSONObject.toJSONString(param.getList()); // String str = JSONObject.toJSONString(param.getList());
SendEmailUtil.sendEMail(str); // SendEmailUtil.sendEMail(str);
//
return HttpResult.ok("邮件发送成功"); // return HttpResult.ok("邮件发送成功");
} // }

@ -10,14 +10,15 @@ import com.djy.invoice.model.*;
import com.djy.invoice.model.mapper.*; import com.djy.invoice.model.mapper.*;
import com.djy.invoice.service.InvLinkInfoService; import com.djy.invoice.service.InvLinkInfoService;
import com.djy.invoice.service.UploadData; import com.djy.invoice.service.UploadData;
import com.djy.invoice.util.SendEmailUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
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.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.ParseException; import java.text.ParseException;
@ -52,6 +53,8 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
private static String subject; private static String subject;
private static String urlPath;
public static BigDecimal invoiceAmount; public static BigDecimal invoiceAmount;
private static final String dateFormat = "yyyy-MM-dd HH:mm:ss"; private static final String dateFormat = "yyyy-MM-dd HH:mm:ss";
private static final DateFormat df = new SimpleDateFormat(dateFormat); private static final DateFormat df = new SimpleDateFormat(dateFormat);
@ -1187,7 +1190,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
param.setList(listEmail); param.setList(listEmail);
String str = JSONObject.toJSONString(param.getList()); String str = JSONObject.toJSONString(param.getList());
SendEmailUtil.sendEMail(str); sendEMail(str);
}else{ }else{
@ -1216,28 +1219,25 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
cxParams.setCriteria(criteria); cxParams.setCriteria(criteria);
return cxParams; 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<String, String> vars = new HashMap<String, String>();
// 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() { public static String getCmdName() {
return cmdName; return cmdName;
} }
@ -1290,4 +1290,10 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
public void setSubject(String subject) { public void setSubject(String subject) {
InvLinkInfoServiceImpl.subject = subject; InvLinkInfoServiceImpl.subject = subject;
} }
@Value("${spring.mail.url}")
public void setUrlPath(String urlPath) {
InvLinkInfoServiceImpl.urlPath = urlPath;
}
} }

@ -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();
}
}
}

@ -22,6 +22,7 @@ spring:
SendTo: 475446853@qq.com SendTo: 475446853@qq.com
SmtpConfig: INVOICE SmtpConfig: INVOICE
subject: 发票信息 subject: 发票信息
url: http://47.104.73.97:8801/mail/send
logging: logging:
level: level:
root: info root: info

Loading…
Cancel
Save