|
@@ -1,8 +1,11 @@
|
|
|
package com.malk.boyang;
|
|
package com.malk.boyang;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import com.malk.boyang.service.BoyangService;
|
|
import com.malk.boyang.service.BoyangService;
|
|
|
import com.malk.server.dingtalk.DDR_New;
|
|
import com.malk.server.dingtalk.DDR_New;
|
|
|
import com.malk.service.dingtalk.DDClient;
|
|
import com.malk.service.dingtalk.DDClient;
|
|
|
|
|
+import com.malk.service.dingtalk.DDClient_Contacts;
|
|
|
|
|
+import com.malk.service.dingtalk.DDClient_Workflow;
|
|
|
import com.malk.utils.UtilHttp;
|
|
import com.malk.utils.UtilHttp;
|
|
|
import com.malk.utils.UtilMap;
|
|
import com.malk.utils.UtilMap;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -16,12 +19,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
|
-import java.io.FileOutputStream;
|
|
|
|
|
-import java.io.IOException;
|
|
|
|
|
-import java.io.InputStream;
|
|
|
|
|
|
|
+import java.io.*;
|
|
|
import java.net.HttpURLConnection;
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -36,6 +37,12 @@ public class DdTest {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private BoyangService boyangService;
|
|
private BoyangService boyangService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DDClient_Contacts ddClient_contacts;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DDClient_Workflow ddClient_workflow;
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
public void test(){
|
|
public void test(){
|
|
|
try {
|
|
try {
|
|
@@ -88,5 +95,99 @@ public class DdTest {
|
|
|
public void test2(){
|
|
public void test2(){
|
|
|
boyangService.eSignSubmit(UtilMap.map("processInstanceId","9L_PKi71S8W3kL_nftFpXw01161764152519"));
|
|
boyangService.eSignSubmit(UtilMap.map("processInstanceId","9L_PKi71S8W3kL_nftFpXw01161764152519"));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ //上传钉盘附件
|
|
|
|
|
+ public void testUpload() {
|
|
|
|
|
+ //获取当前时间戳
|
|
|
|
|
+ long beginTimestamp = System.currentTimeMillis();
|
|
|
|
|
+ System.out.println("开始上传附件:" + DateUtil.format(new Date(beginTimestamp), "yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
+
|
|
|
|
|
+ //文件
|
|
|
|
|
+ File file = new File("C:\\Users\\EDY\\Pictures\\2.png");
|
|
|
|
|
+
|
|
|
|
|
+ //获取文件上传信息
|
|
|
|
|
+ Map param = new HashMap();
|
|
|
|
|
+ param.put("unionId","5PK3cMYhiStn7HDoNabweEgiEiE");//wzy
|
|
|
|
|
+ Map body = new HashMap();
|
|
|
|
|
+ body.put("protocol","HEADER_SIGNATURE");
|
|
|
|
|
+ body.put("multipart",false);
|
|
|
|
|
+
|
|
|
|
|
+ Map header = UtilMap.map("x-acs-dingtalk-access-token","5747a3e5c3823be0bd982dccdf78289e");
|
|
|
|
|
+
|
|
|
|
|
+ DDR_New ddr = (DDR_New) UtilHttp.doPost("https://api.dingtalk.com/v1.0/storage/spaces/" + "27105381865" + "/files/uploadInfos/query", header, param, body, DDR_New.class);
|
|
|
|
|
+ String uploadKey = ddr.getUploadKey();
|
|
|
|
|
+ Map headerSignatureInfo = ddr.getHeaderSignatureInfo();
|
|
|
|
|
+ Map<String,String> headers = (Map<String,String>) headerSignatureInfo.get("headers");
|
|
|
|
|
+ List<String> resourceUrls = (List<String>) headerSignatureInfo.get("resourceUrls");
|
|
|
|
|
+ String resourceUrl = resourceUrls.get(0);
|
|
|
|
|
+
|
|
|
|
|
+ Map dentry = new HashMap();
|
|
|
|
|
+ //使用OSS的header加签方式上传文件
|
|
|
|
|
+ try {
|
|
|
|
|
+ URL url = new URL(resourceUrl);
|
|
|
|
|
+ HttpURLConnection connection = (HttpURLConnection)url.openConnection();
|
|
|
|
|
+ if (headers != null) {
|
|
|
|
|
+ for (Map.Entry<String, String> entry : headers.entrySet()) {
|
|
|
|
|
+ connection.setRequestProperty(entry.getKey(), entry.getValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ connection.setDoOutput(true);
|
|
|
|
|
+ connection.setRequestMethod("PUT");
|
|
|
|
|
+ connection.setUseCaches(false);
|
|
|
|
|
+ connection.setReadTimeout(10000);
|
|
|
|
|
+ connection.setConnectTimeout(10000);
|
|
|
|
|
+ connection.connect();
|
|
|
|
|
+ OutputStream out = connection.getOutputStream();
|
|
|
|
|
+ InputStream is = new FileInputStream(file);
|
|
|
|
|
+ byte[] b =new byte[1024];
|
|
|
|
|
+ int temp;
|
|
|
|
|
+ while ((temp=is.read(b))!=-1){
|
|
|
|
|
+ out.write(b,0,temp);
|
|
|
|
|
+ }
|
|
|
|
|
+ out.flush();
|
|
|
|
|
+ out.close();
|
|
|
|
|
+ int responseCode = connection.getResponseCode();
|
|
|
|
|
+ connection.disconnect();
|
|
|
|
|
+ if (responseCode == 200) {
|
|
|
|
|
+ System.out.println("上传成功");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.out.println("上传失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ //提交文件
|
|
|
|
|
+ Map body2 = new HashMap();
|
|
|
|
|
+ Map option = new HashMap();
|
|
|
|
|
+ option.put("conflictStrategy","OVERWRITE");
|
|
|
|
|
+ body2.put("uploadKey",uploadKey);
|
|
|
|
|
+ body2.put("name",file.getName());
|
|
|
|
|
+ body2.put("option",option);
|
|
|
|
|
+
|
|
|
|
|
+// param.put("unionId","58FDG7fqGyXrGziPavPO4kQiEiE");//lqy
|
|
|
|
|
+
|
|
|
|
|
+ DDR_New ddrNew = (DDR_New) UtilHttp.doPost("https://api.dingtalk.com/v2.0/storage/spaces/files/"+ "DEN7dx2rn0JbYn37a7acrVMGjLRb3o1v" +"/commit", header, param, body2, DDR_New.class);
|
|
|
|
|
+ dentry = ddrNew.getDentry();
|
|
|
|
|
+
|
|
|
|
|
+ }catch (IOException e){
|
|
|
|
|
+ log.info("上传文件异常:{}",e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ long endTimestamp = System.currentTimeMillis();
|
|
|
|
|
+ System.out.println("上传文件结束:" + DateUtil.format(new Date(endTimestamp), "yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
+ System.out.println("上传文件耗时:" + (endTimestamp - beginTimestamp)/1000.0 + "s");
|
|
|
|
|
+ System.out.println(dentry);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void test3() {
|
|
|
|
|
+ Map result = ddClient_workflow.getProcessInstanceId(ddClient.getAccessToken(), "yY-nxf1UTUWxEUXnjDv7Yg01161768554568");
|
|
|
|
|
+ String originatorUserId = UtilMap.getString(result, "originatorUserId");
|
|
|
|
|
+
|
|
|
|
|
+ Map userInfo = ddClient_contacts.getUserInfoById(ddClient.getAccessToken(), originatorUserId);
|
|
|
|
|
+
|
|
|
|
|
+ String originatorUserIdUnionid = UtilMap.getString(userInfo, "unionid");
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println(originatorUserIdUnionid);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|