|
|
@@ -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; |
|
|
|
} |
|
|
|
} |