Explorar o código

测试附件加密接口

wangjun hai 3 semanas
pai
achega
49d941ae82

+ 84 - 0
code/base/nckd-jimin-base-helper/src/main/java/nckd/base/helper/FileSECUtils.java

@@ -0,0 +1,84 @@
+package nckd.base.helper;
+
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.fileservice.FileServiceFactory;
+import kd.bos.orm.query.QCP;
+import kd.bos.orm.query.QFilter;
+import kd.bos.sdk.util.KHttpClientUtils;
+import kd.bos.servicehelper.AttachmentDto;
+import kd.bos.servicehelper.AttachmentServiceHelper;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import okhttp3.*;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class FileSECUtils {
+
+    public static byte[] getFileTest() {
+
+        String entryEntityName = "nckd_filetest";
+
+        DynamicObject billByn = BusinessDataServiceHelper.loadSingle(entryEntityName,
+                new QFilter[]{new QFilter("billno", QCP.equals, "test0001")});
+
+        List<Map<String, Object>> sourceFileList = AttachmentServiceHelper.getAttachments(entryEntityName,billByn.getPkValue(), "attachmentpanel");
+        //Map<String, InputStream> files = new HashMap<>();
+
+        if(sourceFileList != null && sourceFileList.size()>0)
+        {
+            for(Map<String,Object> fileMap : sourceFileList){
+                AttachmentDto attachmentDto = AttachmentServiceHelper.getAttachmentInfoByAttPk(fileMap.get("attPkId"));
+                String fileUrl= attachmentDto.getResourcePath();
+                String fileName = attachmentDto.getFilename();
+                System.out.println("fileUrl:" + fileUrl+ ",fileName:"+fileName);
+                ByteArrayOutputStream out = new ByteArrayOutputStream();
+                FileServiceFactory.getAttachmentFileService().download(fileUrl, out, null);
+                System.out.println("file:" + out.toByteArray());
+                return out.toByteArray();
+                //InputStream in = new ByteArrayInputStream(out.toByteArray());
+                //files.put(fileUrl,in);
+            }
+        }
+        return null;
+    }
+
+    public static void postSECApi(){
+        String url = "https://ebis.jeyoupharma.com:8443";
+        Map<String, String> header = new HashMap<>();
+        header.put("method-name", "checkFileIsEncryptionRest");
+
+        OkHttpClient client = new OkHttpClient();
+
+        // 创建 byte[] 类型的数据
+        byte[] data  = getFileTest();
+
+        // 创建 RequestBody,设置媒体类型和 byte[] 数据
+        RequestBody requestBody = RequestBody.create(MediaType.get("application/octet-stream"), data);
+
+        // 创建 Request 对象,设置目标 URL 和请求体
+        Request request = new Request.Builder()
+                .url("https://your-api-url.com/api/endpoint")
+                .post(requestBody)
+                .build();
+
+        // 执行请求
+        try (Response response = client.newCall(request).execute()) {
+            // 获取响应状态码
+            System.out.println("Status code: " + response.code());
+
+            // 获取响应体并打印
+            if (response.body() != null) {
+                System.out.println("Response content: " + response.body().string());
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+}