Commit c8c6ea27 authored by 华润's avatar 华润

跨省单位开户公积金服务接口

parent f3e26f73
...@@ -54,6 +54,26 @@ ...@@ -54,6 +54,26 @@
<artifactId>ojdbc7</artifactId> <artifactId>ojdbc7</artifactId>
<version>12.1.0.1.0</version> <version>12.1.0.1.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.13</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
</dependencies> </dependencies>
......
...@@ -16,6 +16,8 @@ import java.util.ArrayList; ...@@ -16,6 +16,8 @@ import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.zip.GZIPInputStream;
import static net.cdkj.gjj.adapter.domain.GzipUtil.unzipString; import static net.cdkj.gjj.adapter.domain.GzipUtil.unzipString;
import static net.cdkj.gjj.adapter.domain.GzipUtil.zipString; import static net.cdkj.gjj.adapter.domain.GzipUtil.zipString;
...@@ -53,6 +55,7 @@ public class ProvidentFundServicesController { ...@@ -53,6 +55,7 @@ public class ProvidentFundServicesController {
//----------------------------------------------------- //-----------------------------------------------------
String token = null; String token = null;
token = huoqutoken();//调用获取token的方法 token = huoqutoken();//调用获取token的方法
System.out.println(token);
// System.out.println("内置机传给前置机的json数据:"+str); // System.out.println("内置机传给前置机的json数据:"+str);
System.out.println("zip压缩处理之前要发送给第三方的公积金系统服务报文:" + str); System.out.println("zip压缩处理之前要发送给第三方的公积金系统服务报文:" + str);
// String s = zipString(str);//进行zip压缩 // String s = zipString(str);//进行zip压缩
...@@ -78,6 +81,8 @@ public class ProvidentFundServicesController { ...@@ -78,6 +81,8 @@ public class ProvidentFundServicesController {
conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Connection", "Keep-Alive");
// 设置文件类型: // 设置文件类型:
conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
// 设置文件字符集: // 设置文件字符集:
conn.setRequestProperty("Charset", "UTF-8"); conn.setRequestProperty("Charset", "UTF-8");
// 转换为字节数组 // 转换为字节数组
...@@ -99,10 +104,17 @@ public class ProvidentFundServicesController { ...@@ -99,10 +104,17 @@ public class ProvidentFundServicesController {
sb.append(readLine); sb.append(readLine);
} }
responseReader.close(); responseReader.close();
// GZIPInputStream gzis = new GZIPInputStream(is);
// InputStreamReader reader = new InputStreamReader(gzis);
// BufferedReader br = new BufferedReader(reader);
// String temp;
// while ((temp = br.readLine()) != null) {
// sb.append(temp);
// }
System.out.println("公积金服务第三方返回的zip压缩过的报文:" + sb.toString()); System.out.println("公积金服务第三方返回的zip压缩过的报文:" + sb.toString());
String s1 = unzipString(sb.toString());//将第三方返回的压缩过的json字符串解压缩 // String s1 = unzipString(sb.toString());//将第三方返回的压缩过的json字符串解压缩
System.out.println("公积金服务第三方返回的zip解压缩之后的报文:" + s1); System.out.println("公积金服务第三方返回的zip解压缩之后的报文:" + sb.toString());
return s1; return sb.toString();
} else { } else {
System.out.println("请求失败!!!"); System.out.println("请求失败!!!");
} }
...@@ -329,6 +341,7 @@ public class ProvidentFundServicesController { ...@@ -329,6 +341,7 @@ public class ProvidentFundServicesController {
@ResponseBody @ResponseBody
@PostMapping("BusinessProcessing") @PostMapping("BusinessProcessing")
public static String BusinessProcessing(HttpServletRequest request) { public static String BusinessProcessing(HttpServletRequest request) {
System.out.println("继续调前置机的进度第二个接口");
//----------------------------------------------------- //-----------------------------------------------------
StringBuffer json = new StringBuffer(); StringBuffer json = new StringBuffer();
String line = null; String line = null;
...@@ -371,6 +384,8 @@ public class ProvidentFundServicesController { ...@@ -371,6 +384,8 @@ public class ProvidentFundServicesController {
conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Connection", "Keep-Alive");
// 设置文件类型: // 设置文件类型:
conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
// 设置文件字符集: // 设置文件字符集:
conn.setRequestProperty("Charset", "UTF-8"); conn.setRequestProperty("Charset", "UTF-8");
// 转换为字节数组 // 转换为字节数组
...@@ -386,16 +401,23 @@ public class ProvidentFundServicesController { ...@@ -386,16 +401,23 @@ public class ProvidentFundServicesController {
if (HttpURLConnection.HTTP_OK == conn.getResponseCode()) { if (HttpURLConnection.HTTP_OK == conn.getResponseCode()) {
// 请求返回的数据 // 请求返回的数据
InputStream is = conn.getInputStream(); InputStream is = conn.getInputStream();
String readLine = new String(); // String readLine = new String();
BufferedReader responseReader = new BufferedReader(new InputStreamReader(is, "UTF-8")); // BufferedReader responseReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
while ((readLine = responseReader.readLine()) != null) { // while ((readLine = responseReader.readLine()) != null) {
sb.append(readLine); // sb.append(readLine);
// }
// responseReader.close();
GZIPInputStream gzis = new GZIPInputStream(is);
InputStreamReader reader = new InputStreamReader(gzis);
BufferedReader br = new BufferedReader(reader);
String temp;
while ((temp = br.readLine()) != null) {
sb.append(temp);
} }
responseReader.close();
System.out.println("第三方返回的zip压缩过的进度结果报文:" + sb.toString()); System.out.println("第三方返回的zip压缩过的进度结果报文:" + sb.toString());
String s1 = unzipString(sb.toString());//将第三方返回的压缩过的json字符串解压缩 // String s1 = unzipString(sb.toString());//将第三方返回的压缩过的json字符串解压缩
System.out.println("第三方返回的zip解压缩之后的进度结果报文:" + s1); System.out.println("第三方返回的zip解压缩之后的进度结果报文:" + sb.toString());
return s1; return sb.toString();
} else { } else {
System.out.println("请求失败!!!"); System.out.println("请求失败!!!");
} }
......
...@@ -6,8 +6,12 @@ import org.springframework.web.bind.annotation.*; ...@@ -6,8 +6,12 @@ import org.springframework.web.bind.annotation.*;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import static net.cdkj.gjj.adapter.domain.GzipUtil.zipString; import java.io.IOException;
import static net.cdkj.gjj.adapter.domain.GzipUtil.unzipString; import java.util.zip.GZIPInputStream;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import static net.cdkj.gjj.adapter.domain.GzipUtil.*;
/** /**
...@@ -40,8 +44,8 @@ public class TokenAcquisitionController { ...@@ -40,8 +44,8 @@ public class TokenAcquisitionController {
OutputStream out = null; OutputStream out = null;
try { try {
// 创建url 资源 // 创建url 资源
// URL url = new URL("https://scjg.hubei.gov.cn/sjzt/api/oauth2/token");//正式第三方地址 URL url = new URL("https://scjg.hubei.gov.cn/sjzt/api/oauth2/token");//正式第三方地址
URL url = new URL("http://127.0.0.1:8080/FrontEndProcessor/FrontEndProcessor/token2");//测试第三方地址 // URL url = new URL("http://127.0.0.1:8080/FrontEndProcessor/FrontEndProcessor/token2");//测试第三方地址
// 创建http 连接 // 创建http 连接
conn = (HttpURLConnection) url.openConnection(); conn = (HttpURLConnection) url.openConnection();
// 设置允许输出 // 设置允许输出
...@@ -54,6 +58,8 @@ public class TokenAcquisitionController { ...@@ -54,6 +58,8 @@ public class TokenAcquisitionController {
conn.setRequestMethod("POST"); conn.setRequestMethod("POST");
// 设置维持长连接 // 设置维持长连接
conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
// 设置文件类型: // 设置文件类型:
conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Content-Type", "application/json");
// 设置文件字符集: // 设置文件字符集:
...@@ -69,18 +75,24 @@ public class TokenAcquisitionController { ...@@ -69,18 +75,24 @@ public class TokenAcquisitionController {
out.write(data); out.write(data);
// 请求返回的状态 // 请求返回的状态
if (HttpURLConnection.HTTP_OK == conn.getResponseCode()) { if (HttpURLConnection.HTTP_OK == conn.getResponseCode()) {
// 请求返回的数据 // // 请求返回的数据
InputStream is = conn.getInputStream(); InputStream is = conn.getInputStream();
String readLine = new String(); // String readLine = new String();
BufferedReader responseReader = new BufferedReader(new InputStreamReader(is, "UTF-8")); // BufferedReader responseReader = new BufferedReader(new InputStreamReader(is,"UTF-8"));
while ((readLine = responseReader.readLine()) != null) { // while ((readLine = responseReader.readLine()) != null) {
sb.append(readLine); // sb.append(readLine);
// }
GZIPInputStream gzis = new GZIPInputStream(is);
InputStreamReader reader = new InputStreamReader(gzis);
BufferedReader br = new BufferedReader(reader);
String temp;
while ((temp = br.readLine()) != null) {
sb.append(temp);
} }
responseReader.close();
System.out.println("鉴权参数第三方返回的zip压缩过的报文:" + sb.toString()); System.out.println("鉴权参数第三方返回的zip压缩过的报文:" + sb.toString());
String s1 = unzipString(sb.toString());//将第三方返回的压缩过的json字符串解压缩 // String s1 = unzipString(sb.toString());//将第三方返回的压缩过的json字符串解压缩
System.out.println("鉴权参数第三方返回的zip解压缩之后的报文:" + s1); System.out.println("鉴权参数第三方返回的zip解压缩之后的报文:" + sb.toString());
return s1; return sb.toString();
} else { } else {
System.out.println("请求失败!!!"); System.out.println("请求失败!!!");
} }
...@@ -141,4 +153,16 @@ public class TokenAcquisitionController { ...@@ -141,4 +153,16 @@ public class TokenAcquisitionController {
String s1 = unzipString(s);//进行zip解压缩 String s1 = unzipString(s);//进行zip解压缩
System.out.println("解压缩处理之后的json字符串:"+s1); System.out.println("解压缩处理之后的json字符串:"+s1);
} }
/**
* 程序中访问http数据接口
*/
@ResponseBody
@PostMapping("testjson")
public static String getURLContent() {
return null;
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment