diff --git a/xhpc-modules/xhpc-invoice/pom.xml b/xhpc-modules/xhpc-invoice/pom.xml
index 0d54c218..2cae6d59 100644
--- a/xhpc-modules/xhpc-invoice/pom.xml
+++ b/xhpc-modules/xhpc-invoice/pom.xml
@@ -109,6 +109,12 @@
3.0.0
compile
+
+ com.aliyun.oss
+ aliyun-sdk-oss
+ 3.10.2
+ compile
+
diff --git a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/controller/XhpcInvoiceController.java b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/controller/XhpcInvoiceController.java
index 239dd00f..a480949f 100644
--- a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/controller/XhpcInvoiceController.java
+++ b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/controller/XhpcInvoiceController.java
@@ -1,5 +1,7 @@
package com.xhpc.invoice.controller;
+import com.aliyun.oss.OSSClient;
+import com.xhpc.common.core.utils.DateUtils;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.invoice.constant.InvoiceStatusConst;
@@ -8,12 +10,15 @@ import com.xhpc.invoice.domain.AllInvoiceOrdersResponse;
import com.xhpc.invoice.domain.InvoiceToUserRequest;
import com.xhpc.invoice.domain.SpecificInvoiceWrap;
import com.xhpc.invoice.service.XhpcInvoiceService;
+import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
+import java.io.IOException;
import java.util.Map;
/**
@@ -29,6 +34,32 @@ public class XhpcInvoiceController extends BaseController {
@Resource
XhpcInvoiceService xhpcInvoiceService;
+ @Resource
+ Environment environment;
+
+ /**
+ * 上传图片到阿里云接口
+ *
+ * @param invoicePdf 文件二进制对象
+ * @return 该文件在阿里云中的地址
+ * @author WH
+ * @date 2021/12/29 16:40
+ * @since version-1.0
+ */
+ @PostMapping("/pdf")
+ public AjaxResult uploadPdf(MultipartFile invoicePdf) throws IOException {
+
+ String filename = "electronicInvoice" + DateUtils.dateTimeNow() + ".pdf";
+ // 上传文件到阿里云
+ OSSClient ossClient = new OSSClient(environment.getProperty("oss.endpoint"), environment.getProperty("oss.access-key"), environment.getProperty("oss.secret-key"));
+ // 放置到哪个块中去,key为目录,file为文件
+ ossClient.putObject(environment.getProperty("oss.bucket-name"), environment.getProperty("file.aliyunPath") + filename, invoicePdf.getInputStream());
+ ossClient.shutdown();
+ // 返回上传到阿里云中的文件的uri地址
+ String fileAddress = "/" + environment.getProperty("file.aliyunPath") + filename;
+ return AjaxResult.success(fileAddress);
+ }
+
/**
* 给指定用户开发票,开票完成之后将开出的电子发票发送至用户的接收邮箱
diff --git a/xhpc-modules/xhpc-invoice/src/main/resources/bootstrap.yml b/xhpc-modules/xhpc-invoice/src/main/resources/bootstrap.yml
index bacdb6d8..c5679461 100644
--- a/xhpc-modules/xhpc-invoice/src/main/resources/bootstrap.yml
+++ b/xhpc-modules/xhpc-invoice/src/main/resources/bootstrap.yml
@@ -22,4 +22,18 @@ spring:
file-extension: yml
# 共享配置
shared-configs:
- - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
\ No newline at end of file
+ - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+
+#oss默认配置
+oss:
+ enabled: true
+ name: qiniu
+ tenant-mode: true
+ endpoint: oss-accelerate.aliyuncs.com
+ access-key: LTAI5tBWjnuQGxGicnThwMF1
+ secret-key: b0WNtFYtWyTEkZzcr2WOAPoZg6w2Xu
+ bucket-name: xhpc-bucket1
+
+#文件路径
+file:
+ aliyunPath: invoicePdf/
\ No newline at end of file