From 72460d9ce2a57a34543b7b9eb2c751cb7b213853 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Wed, 5 Jul 2023 10:36:42 +0800 Subject: [PATCH] =?UTF-8?q?debug=20=E4=B8=8B=E6=A0=87=E8=B6=8A=E7=95=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/todocenter/manage/HandlerManage.java | 2 +- .../java/com/ningdatech/pmapi/irs/IrsTest.java | 95 ++++++++++++++++++++-- 2 files changed, 88 insertions(+), 9 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/HandlerManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/HandlerManage.java index 0a159da..d9db30b 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/HandlerManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/HandlerManage.java @@ -124,7 +124,7 @@ public class HandlerManage { if (currentNode.getNodeType().name().equals(NodeTypeEnum.SUB.name())) { List children = currentNode.getChildren(); // 获取子流程当前审核人节点 - ProgressNode subCurrentNode = children.get(children.size() - 1); + ProgressNode subCurrentNode = CollUtil.isEmpty(children) ? new ProgressNode() : children.get(children.size() - 1); // 获取节点ID相同地审核节点 List nodeList = children.stream() .filter(c -> subCurrentNode.getNodeId().equals(c.getNodeId())) diff --git a/pmapi/src/test/java/com/ningdatech/pmapi/irs/IrsTest.java b/pmapi/src/test/java/com/ningdatech/pmapi/irs/IrsTest.java index 7843725..f778df2 100644 --- a/pmapi/src/test/java/com/ningdatech/pmapi/irs/IrsTest.java +++ b/pmapi/src/test/java/com/ningdatech/pmapi/irs/IrsTest.java @@ -1,24 +1,31 @@ package com.ningdatech.pmapi.irs; import com.alibaba.fastjson.JSON; -import com.google.common.collect.Maps; +import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient; +import com.alibaba.xxpt.gateway.shared.client.http.GetClient; +import com.ningdatech.pmapi.AppTests; import com.ningdatech.pmapi.common.util.CryptUtils; import com.ningdatech.pmapi.common.util.HmacAuthUtil; import com.ningdatech.pmapi.common.util.RefreshKeyUtil; +import com.ningdatech.zwdd.ZwddIntegrationProperties; +import com.ningdatech.zwdd.client.ZwddAuthClient; +import com.ningdatech.zwdd.client.ZwddClient; +import com.ningdatech.zwdd.client.provider.ZwddAuthClientProvider; +import org.apache.http.client.methods.CloseableHttpResponse; import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; -import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; - +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; import java.security.NoSuchAlgorithmException; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * @Classname IrsTest @@ -26,7 +33,13 @@ import java.util.Set; * @Date 2023/6/26 17:42 * @Author PoffyZhang */ -public class IrsTest { +public class IrsTest extends AppTests { + + @Autowired + private ZwddAuthClient zwddAuthClient; + + @Autowired + private ZwddClient zwddClient; @Test public void test1(){ @@ -78,4 +91,70 @@ public class IrsTest { String areaCode = "331121"; System.out.println(CryptUtils.MD5Encode(timestamp + areaCode)); } + + @Test + public void test4(){ + CloseableHttpResponse response = null; + try { + String api = "/media/download"; + GetClient getClient = getZwddExecutableClient().newGetClient(api); + //设置参数 + getClient.addParameter("access_token", zwddClient.getAccessToken().getData()); + getClient.addParameter("media_id", "$hQHNKaUCo2pwZwMGDAEN2gBAK2Z2YUVMb0xYZnFJSGRuZ1h3OVZGd3hadDNrTXlYNWlQOXF0OERrZTc0b2M5UU0xeExsUVFkalBQNFVJakZ0aA"); + //调用API + //String result = getClient.get(); + //System.err.println(result); + response = getClient.getB(); + org.apache.http.HttpEntity entity = response.getEntity(); + InputStream is = entity.getContent(); + System.out.println(is); + File voice = new File("C:\\Users\\PoffyZhang\\Desktop\\log1.jpg"); + OutputStream fos = new FileOutputStream(voice); + int cache = 10 * 1024; + byte[] buffer = new byte[cache]; + int ch = 0; + StringBuffer sb = new StringBuffer(); + while ((ch = is.read(buffer)) != -1) { + fos.write(buffer, 0, ch); + sb.append(buffer); + } + System.out.println(sb.toString()); + is.close(); + fos.flush(); + fos.close(); + } catch (Exception e) { + System.out.println(e); + }finally { + if (response != null) { + try { + //特别提醒:需要调用response的close方法关闭网络连接!!! + response.close(); + } catch (Exception e) { + System.out.println(e); + } + } + } + } + + private static ExecutableClient zwddExecutableClient; + @Autowired + private ZwddIntegrationProperties zwddProperties; + public ExecutableClient getZwddExecutableClient() { + if (Objects.isNull(zwddExecutableClient)) { + synchronized (ZwddAuthClientProvider.class) { + if (Objects.isNull(zwddExecutableClient)) { + zwddExecutableClient = ExecutableClient.getInstance(); + //DomainName不同环境对应不同域名,示例为sass域名 + zwddExecutableClient.setDomainName(zwddProperties.getDomain()); + zwddExecutableClient.setProtocal("https"); + //应用App Key + zwddExecutableClient.setAccessKey(zwddProperties.getAppKey()); + //应用App Secret + zwddExecutableClient.setSecretKey(zwddProperties.getAppSecret()); + zwddExecutableClient.init(); + } + } + } + return zwddExecutableClient; + } }