瀏覽代碼

Merge branch 'feature-2022.07.29' of https://git.flowbb.cn/RK-Dev/fqgz-server into feature-2022.07.29

humuyu 3 年之前
父節點
當前提交
aa239f9d43

+ 18 - 0
eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java

@@ -20,11 +20,13 @@ import cn.hutool.core.util.IdUtil;
 import cn.hutool.poi.excel.BigExcelWriter;
 import cn.hutool.poi.excel.ExcelUtil;
 import me.zhengjie.exception.BadRequestException;
+import org.apache.commons.codec.binary.Base64;
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.xssf.streaming.SXSSFSheet;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.web.multipart.MultipartFile;
+
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -353,4 +355,20 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
     public static String getMd5(File file) {
         return getMd5(getByte(file));
     }
+
+    /**
+     * 将文件内容转换成Base64编码
+     *
+     * @param path
+     * @return
+     * @throws Exception
+     */
+    public static String encodeBase64File(String path) throws Exception {
+        File file = new File(path);
+        FileInputStream inputFile = new FileInputStream(file);
+        byte[] buffer = new byte[(int) file.length()];
+        inputFile.read(buffer);
+        inputFile.close();
+        return Base64.encodeBase64String(buffer);
+    }
 }

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/NotaryOfficeServiceImpl.java

@@ -371,7 +371,7 @@ public class NotaryOfficeServiceImpl extends ServiceImpl<NotaryOfficeMapper, Not
 					saveEntity.setAxqSealId(sealId);
 				} else {
 					// 修改公证员签章
-					byte[] b = FileUploadUtil.getByte(entity.getSealImg());
+					byte[] b = FileUploadUtil.getByte(req.getImageId());
 					CFCACertUtil.updateSeal(entity.getAxqUserId(), entity.getAxqSealId(), b);
 				}
 				saveEntity.setId(req.getId());

+ 0 - 132
eladmin-system/src/main/java/me/zhengjie/base/util/A.java

@@ -1,132 +0,0 @@
-package me.zhengjie.base.util;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.UUID;
-import io.minio.MinioClient;
-import io.minio.PutObjectOptions;
-import io.minio.messages.Bucket;
-import net.coobird.thumbnailator.Thumbnails;
-
-public class A {
-//	public static void main(String[] args) throws IOException {
-//		// show();
-//		HashMap<String, String> map = new HashMap<>();
-//		map.put("aaa", "bbb");
-//		Thread.currentThread().sleep(millis);
-//	} 
-	private static void printWithThread(String content) {
-		System.out.println("[" + Thread.currentThread().getName() + "线程]: " + content);
-	}
-
-	public static void main(String[] args) {
-		// show();
-		String str = "https://124.222.192.60:9000/mytest/no10020220609164946793/APP387702301847479292.mp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20220614%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220614T060036Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=a04e0d1ad2241753ba4007a3b292f3acb767143de99c4705e043c7c1a2de01c7";
-		int index = str.indexOf( "/",8);
-		System.out.println(str.substring(index));;
-//		printWithThread("开始执行main方法");
-//
-//		Thread myThread = new Thread(() -> {
-//			printWithThread("我在自定义的线程的run方法里");
-//			printWithThread("我马上要休息1秒钟, 并让出CPU给别的线程使用.");
-//			try {
-//				Thread.sleep(100000000l);
-//				printWithThread("已经休息了1秒, 又重新获得了CPU");
-//				printWithThread("我休息好了, 马上就退出了");
-//			} catch (InterruptedException e) {
-//				e.printStackTrace();
-//			}
-//
-//		});
-//		try {
-//			myThread.start();
-//			printWithThread("我在main方法里面, 我要等下面这个线程执行完了才能继续往下执行.");
-//			synchronized (myThread) {
-//				myThread.wait(0);
-//			}
-//			printWithThread("我在main方法里面, 马上就要退出了.");
-//		} catch (Exception e) {
-//			e.printStackTrace();
-//		}
-	}
-
-	public static void compress() throws IOException {
-		String str = "E:\\SmartAdmin\\companyframework\\eladmin-master\\eladmin-system\\target\\d55b912d019f48d881847fddf722c3e7_6.jpeg";
-		File file = new File(str);
-
-		/**
-		 * 判断是否是图片 判断是否超过了 100K
-		 */
-		if ((1024 * 1024 * 0.1) <= file.length()) {
-			FileInputStream input = new FileInputStream(file);
-			// 在项目根目录下的 upload 目录中生成临时文件
-			File newFile = new File("E:\\image\\aaa.jpeg");
-			// 小于 1M 的
-			if ((1024 * 1024 * 0.1) <= file.length() && file.length() <= (1024 * 1024)) {
-				Thumbnails.of(input).scale(0.3f).outputQuality(0.3f).toFile(newFile);
-			}
-			// 1 - 2M 的
-			else if ((1024 * 1024) < file.length() && file.length() <= (1024 * 1024 * 2)) {
-				Thumbnails.of(input).scale(0.2f).outputQuality(0.2f).toFile(newFile);
-			}
-			// 2M 以上的
-
-			else if ((1024 * 1024 * 2) < file.length()) {
-				ByteArrayOutputStream bos = new ByteArrayOutputStream();
-				// bos.in
-				Thumbnails.of(input).scale(0.1f).toOutputStream(bos);
-
-			}
-			// 获取输入流
-
-		}
-
-	}
-
-	public static void show() {
-
-		try {
-
-			String bucketName = "mytest";
-			MinioClient minioClient = new MinioClient("http://124.222.192.60:9000", "minioadmin", "minioadmin");
-			boolean flag = minioClient.bucketExists("mytest");
-			System.out.println("是否存在此桶:" + flag);
-			SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd/");
-			String date = sdf.format(new Date());
-			// 找一个你电脑上图片的绝对路径,最好是PNG图片
-			File file = new File("E:\\demo\\image\\2022\\03\\18\\1f7c69d855814f829c158ded51642168.png");
-			long size = file.length();
-			String fileName = file.getName();
-			InputStream is = new FileInputStream(file);
-			// 将待上传的文件的路径设置成 年/月/日/uuid+file01.png
-			// 你也可以自定义上传文件的路径,这样设置是为了更好的管理
-			String uuid = UUID.randomUUID().toString().replace("-", "").substring(0, 6);
-			String fileUploadPath = date + uuid + "file01" + fileName.substring(fileName.lastIndexOf("."));
-
-			PutObjectOptions options = new PutObjectOptions(size, -1);
-			// 设置图片的contentType,如果不是PNG图片就自行修改对应的contentType,这样做的目的是为了上传之后访问图片时可以在浏览器预览而不用下载,当然也可以注释这行代码
-			options.setContentType("image/png");
-//
- 			minioClient.putObject(bucketName, fileUploadPath, is, options);
-//
-//			System.out.println(file.getAbsolutePath() + "is successfully uploaded as 【" + fileUploadPath + "】 to 【"
-//					+ bucketName + "】bucket.");
-			String aa = minioClient.presignedGetObject("mytest", "no10020220609164946793/APP387702301847479292.mp4",
-					604800);
-			System.out.println(aa);
-
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-
-	}
-}

+ 0 - 48
eladmin-system/src/main/java/me/zhengjie/base/util/AliSms.java

@@ -1,48 +0,0 @@
-package me.zhengjie.base.util;
-
-import com.aliyuncs.CommonRequest;
-import com.aliyuncs.CommonResponse;
-import com.aliyuncs.DefaultAcsClient;
-import com.aliyuncs.IAcsClient;
-import com.aliyuncs.exceptions.ClientException;
-import com.aliyuncs.exceptions.ServerException;
-import com.aliyuncs.http.MethodType;
-import com.aliyuncs.profile.DefaultProfile;
-import me.zhengjie.application.user.vo.SmsVo;
-
-public class AliSms {
-
-	private static String accessKeyId = "LTAI4GFuVRN6xY6nTATRYRJz";
-	private static String accessKeySecret = "yQkxup3VDwfbcXdXDtdUnGmKE0VIeh";
-
-	public static String sendSms(SmsVo smsVO) {
-		String content = "";
-		DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
-		IAcsClient client = new DefaultAcsClient(profile);
-
-		CommonRequest request = new CommonRequest();
-		request.setSysMethod(MethodType.POST);
-		request.setSysDomain("dysmsapi.aliyuncs.com");
-		request.setSysVersion("2017-05-25");
-		request.setSysAction("SendSms");
-		request.putQueryParameter("RegionId", "cn-hangzhou");
-
-		request.putQueryParameter("SignName", "牛拍拍");
-		request.putQueryParameter("PhoneNumbers", smsVO.getPhone());
-		request.putQueryParameter("TemplateCode", smsVO.getTemplate());
-		request.putQueryParameter("TemplateParam", smsVO.getParam());
-
-		System.out.println("Phone:" + smsVO.getPhone());
-
-		try {
-			CommonResponse response = client.getCommonResponse(request);
-			content = response.getData().toString();
-		} catch (ServerException e) {
-			e.printStackTrace();
-		} catch (ClientException e) {
-			e.printStackTrace();
-		}
-		return content;
-	}
-
-}

+ 0 - 80
eladmin-system/src/main/java/me/zhengjie/base/util/ApiResult.java

@@ -1,80 +0,0 @@
-package me.zhengjie.base.util;
-
-
-import com.alibaba.fastjson.JSONObject;
-import com.alibaba.fastjson.annotation.JSONField;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.experimental.Accessors;
-
-/**
- * @author Administrator
- */
-@Accessors(chain = true)
-@Getter
-@Setter
-public class ApiResult<T> {
-
-    @JSONField(serialize = false)
-    private final static String SUCCESS = "0";
-    @JSONField(serialize = false)
-    private final static String SUCCESS_MSG = "ok";
-    @JSONField(serialize = false)
-    private final static String FAIL = "1000";
-    @JSONField(serialize = false)
-    private final static String FAIL_MSG = "fail";
-
-    /**
-     * 返回code
-     */
-    private String returnCode;
-    /**
-     * 返回信息
-     */
-    private String returnMsg;
-
-    /**
-     * 返回数据
-     */
-    private T returnData;
-
-    public ApiResult() {
-    }
-
-    public static ApiResult success(Object returnData) {
-        return build(SUCCESS, SUCCESS_MSG, returnData);
-    }
-
-    public static ApiResult success() {
-        return build(SUCCESS, SUCCESS_MSG, null);
-    }
-
-    public static ApiResult fail(String message) {
-        ApiResult fail = build(FAIL, message, null);
-        return fail;
-    }
-
-    public static ApiResult fail(String message, Object returnData) {
-        ApiResult fail = build(FAIL, message, returnData);
-        return fail;
-    }
-
-    public static ApiResult fail(String code, String message, Object returnData) {
-        ApiResult fail = build(code, message, returnData);
-        return fail;
-    }
-
-    private static ApiResult build(String code, String message, Object returnData) {
-        return new ApiResult().setReturnCode(code).setReturnMsg(message).setReturnData(returnData);
-    }
-
-
-    public boolean isSuccess() {
-        return "0".equals(returnCode);
-    }
-
-    @Override
-    public String toString() {
-        return JSONObject.toJSONString(this);
-    }
-}

文件差異過大導致無法顯示
+ 603 - 0
eladmin-system/src/main/java/me/zhengjie/base/util/EQBServiceUtil.java


+ 215 - 23
eladmin-system/src/main/java/me/zhengjie/base/util/HttpUtil.java

@@ -1,19 +1,10 @@
 package me.zhengjie.base.util;
 
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-import java.io.PrintWriter;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.io.*;
+
+import java.net.*;
+import java.text.MessageFormat;
+import java.util.*;
 
 import com.alibaba.fastjson.JSONObject;
 
@@ -27,15 +18,11 @@ public class HttpUtil {
 	 */
 	private static int DEFAULT_TIME_OUT = 1800000000;
 
-	//
-
 	/**
 	 * jdk 原生 http post 请求,默认超时时间为30秒
 	 *
 	 * @param url         请求地址
-	 * @param body        入参String
-	 * @param contentType 内容类型
-	 * @param charSet     编码格式
+	 * @param json        入参String
 	 * @return respone的body
 	 */
 	public static String sendPost(String url, String json) {
@@ -47,8 +34,6 @@ public class HttpUtil {
 	 *
 	 * @param url         访问地址
 	 * @param body        request请求体
-	 * @param contentType 请求类型
-	 * @param charSet     编码格式
 	 * @param timeOut     超时时间,单位毫秒
 	 * @return 响应体string
 	 */
@@ -66,8 +51,6 @@ public class HttpUtil {
 			conn.setRequestProperty("charsert", "utf-8");
 			conn.setConnectTimeout(timeOut);
 			conn.setReadTimeout(timeOut);
-			//
-
 			// 发送POST请求必须设置如下两行
 			conn.setDoOutput(true);
 			conn.setDoInput(true);
@@ -121,6 +104,215 @@ public class HttpUtil {
 		return stringBuilder.toString();
 	}
 
+	/***
+	 * 向指定URL发送POST方法的请求
+	 *
+	 * @param apiUrl
+	 * @param data
+	 * @param headers
+	 * @param encoding
+	 * @return
+	 * @throws Exception
+	 */
+	public static String sendPOST(String apiUrl, String data, LinkedHashMap<String, String> headers, String encoding) throws Exception {
+		// 获得响应内容
+		String http_RespContent = null;
+		HttpURLConnection httpURLConnection = null;
+		int http_StatusCode = 0;
+		String http_RespMessage = null;
+		try {
+			// 建立连接
+			URL url = new URL(apiUrl);
+			httpURLConnection = (HttpURLConnection) url.openConnection();
+			// 需要输出
+			httpURLConnection.setDoOutput(true);
+			// 需要输入
+			httpURLConnection.setDoInput(true);
+			// 不允许缓存
+			httpURLConnection.setUseCaches(false);
+			// HTTP请求方式
+			httpURLConnection.setRequestMethod("POST");
+			// 设置Headers
+			if (null != headers) {
+				for (String key : headers.keySet()) {
+					httpURLConnection.setRequestProperty(key, headers.get(key));
+				}
+			}
+			// 连接会话
+			httpURLConnection.connect();
+			if (data != null) {
+				// 建立输入流,向指向的URL传入参数
+				DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream());
+				// 设置请求参数
+				dos.write(data.getBytes(encoding));
+				dos.flush();
+				dos.close();
+			}
+			// 获得响应状态(HTTP状态码)
+			http_StatusCode = httpURLConnection.getResponseCode();
+			// 获得响应消息(HTTP状态码描述)
+			http_RespMessage = httpURLConnection.getResponseMessage();
+			// 获得响应内容
+			if (HttpURLConnection.HTTP_OK == http_StatusCode) {
+				// 返回响应结果
+				http_RespContent = getResponseContent(httpURLConnection);
+			} else {
+				// 返回非200状态时响应结果
+				http_RespContent = getErrorResponseContent(httpURLConnection);
+				String msg =
+						MessageFormat.format("请求失败: Http状态码 = {0} , {1}", http_StatusCode, http_RespMessage);
+				System.out.println(msg);
+			}
+		} catch (UnknownHostException e) {
+			String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+			Exception ex = new Exception(message);
+			ex.initCause(e);
+			throw ex;
+		} catch (MalformedURLException e) {
+			String message = MessageFormat.format("格式错误的URL: {0}", e.getMessage());
+			Exception ex = new Exception(message);
+			ex.initCause(e);
+			throw ex;
+		} catch (IOException e) {
+			String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+			Exception ex = new Exception(message);
+			ex.initCause(e);
+			throw ex;
+		} catch (Exception e) {
+			String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+			Exception ex = new Exception(message);
+			ex.initCause(e);
+			throw ex;
+		} finally {
+			if (null != httpURLConnection) {
+				httpURLConnection.disconnect();
+			}
+		}
+		return http_RespContent;
+	}
+
+	/***
+	 * 读取HttpResponse响应内容
+	 *
+	 * @param httpURLConnection
+	 * @return
+	 * @throws UnsupportedEncodingException
+	 * @throws IOException
+	 */
+	private static String getErrorResponseContent(HttpURLConnection httpURLConnection)
+			throws UnsupportedEncodingException, IOException {
+		StringBuffer contentBuffer = null;
+		BufferedReader responseReader = null;
+		try {
+			contentBuffer = new StringBuffer();
+			String readLine = null;
+			responseReader =
+					new BufferedReader(new InputStreamReader(httpURLConnection.getErrorStream(), "UTF-8"));
+			while ((readLine = responseReader.readLine()) != null) {
+				contentBuffer.append(readLine);
+			}
+		} finally {
+			if (null != responseReader) {
+				responseReader.close();
+			}
+		}
+		return contentBuffer.toString();
+	}
+
+	/***
+	 * 读取HttpResponse响应内容
+	 *
+	 * @param httpURLConnection
+	 * @return
+	 * @throws UnsupportedEncodingException
+	 * @throws IOException
+	 */
+	private static String getResponseContent(HttpURLConnection httpURLConnection)
+			throws UnsupportedEncodingException, IOException {
+		StringBuffer contentBuffer = null;
+		BufferedReader responseReader = null;
+		try {
+			contentBuffer = new StringBuffer();
+			String readLine = null;
+			responseReader =
+					new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream(), "UTF-8"));
+			while ((readLine = responseReader.readLine()) != null) {
+				contentBuffer.append(readLine);
+			}
+		} finally {
+			if (null != responseReader) {
+				responseReader.close();
+			}
+		}
+		return contentBuffer.toString();
+	}
+
+	/**
+	 * 上传文件
+	 *
+	 * @param url
+	 * @param header
+	 * @param filePath
+	 * @return
+	 */
+	public static String postFile(String url, Map<String, String> header, String filePath) {
+		HttpURLConnection conn = null;
+		OutputStream out = null;
+		String respContent = "";
+		try {
+			URL realUrl = new URL(url);
+			// 打开和URL之间的连接
+			conn = (HttpURLConnection) realUrl.openConnection();
+			// 设置通用的请求头属性
+			conn.setRequestProperty("Content-Type", header.get("contentType"));
+			conn.setRequestProperty("Content-MD5", header.get("contentMD5"));
+			// 发送POST请求必须设置如下两行
+			conn.setDoOutput(true);
+			conn.setDoInput(true);
+			conn.setRequestMethod("PUT");
+			conn.connect();
+			// 上传文件内容
+			out = new DataOutputStream(conn.getOutputStream());
+			File file = new File(filePath);
+			DataInputStream fileIS = new DataInputStream(new FileInputStream(file));
+			int bytes = 0;
+			byte[] bufferOut = new byte[1024];
+			while ((bytes = fileIS.read(bufferOut)) != -1) {
+				out.write(bufferOut, 0, bytes);
+			}
+			fileIS.close();
+			out.flush();
+			out.close();
+			// 获取返回信息
+			int statusCode = conn.getResponseCode();
+			String respMessage = conn.getResponseMessage();
+			// 获得响应内容
+			if (HttpURLConnection.HTTP_OK == statusCode) {
+				// 返回响应结果
+				respContent = getResponseContent(conn);
+			} else {
+				// 返回非200状态时响应结果
+				respContent = getErrorResponseContent(conn);
+				String msg = MessageFormat.format("请求失败: Http状态码 = {0} , {1}", statusCode, respMessage);
+				System.out.println(msg);
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+		} finally {
+			try {
+				if (out != null) {
+					out.close();
+				}
+				if (conn != null) {
+					conn.disconnect();
+				}
+			} catch (Exception ex) {
+				ex.printStackTrace();
+			}
+		}
+		return respContent;
+	}
+
 	public static void main(String[] args) throws Exception {
 
 		int i = 0;

+ 2 - 16
eladmin-system/src/main/java/me/zhengjie/base/util/TencentServiceUtil.java

@@ -17,6 +17,7 @@ import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
 import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
 import lombok.extern.slf4j.Slf4j;
 import me.zhengjie.base.config.AppConfigInfo;
+import me.zhengjie.utils.FileUtil;
 import org.springframework.web.multipart.MultipartFile;
 import sun.misc.BASE64Encoder;
 
@@ -141,7 +142,7 @@ public class TencentServiceUtil {
         try {
             String filePath = saveFile(file, UUIDGenerator.uuid() + file.getOriginalFilename());
             String compressFilePath = compressImage(filePath);
-            String content = encodeBase64File(compressFilePath);
+            String content = FileUtil.encodeBase64File(compressFilePath);
 
             // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
             // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
@@ -465,21 +466,6 @@ public class TencentServiceUtil {
     }
 
     /**
-     * 将文件内容转换成Base64编码
-     * @param path
-     * @return
-     * @throws Exception
-     */
-    private static String encodeBase64File(String path) throws Exception {
-        File file = new File(path);
-        FileInputStream inputFile = new FileInputStream(file);
-        byte[] buffer = new byte[(int) file.length()];
-        inputFile.read(buffer);
-        inputFile.close();
-        return new BASE64Encoder().encode(buffer);
-    }
-
-    /**
      * 图片压缩
      * @throws Exception
      */

+ 3 - 3
eladmin-system/src/main/resources/config/application-nt.yml

@@ -156,11 +156,11 @@ app:
   background:
     picture: https://flowbb.show.xjrkj.com/image/logo/83d9449f4e02459da1661bafdf08b86a_8.png
   image:
-    url: https://fqgz.banknotary.cn:8000/image/
+    url: https://fqgz.ntgzc.com/image/
   upload:
     path: /data/fqgz/image/
   host:
-    domain: https://fqgz.banknotary.cn:8000
+    domain: https://fqgz.ntgzc.com
   push:
     port: 8089
   minio:
@@ -168,7 +168,7 @@ app:
     secretkey: ntgzc123@!p
     url: http://127.0.0.1:9000
     bucketName: fqgz
-    preview: https://fqgz.banknotary.cn:8000
+    preview: https://fqgz.ntgzc.com
 tencent:
   client:
     webankAppId: TIDAdW8e