Commit 37ccd284 authored by 华润's avatar 华润

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

parent 851dab55
...@@ -2,7 +2,9 @@ package net.cdkj.gjj.adapter.controller; ...@@ -2,7 +2,9 @@ package net.cdkj.gjj.adapter.controller;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import net.cdkj.gjj.adapter.domain.Json;
import net.cdkj.gjj.adapter.domain.TimeExpiredPoolCache; import net.cdkj.gjj.adapter.domain.TimeExpiredPoolCache;
import net.cdkj.gjj.adapter.domain.UnitAccountOpeningInformation;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
...@@ -11,6 +13,14 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -11,6 +13,14 @@ import org.springframework.web.bind.annotation.RestController;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import static net.cdkj.gjj.adapter.domain.GzipUtil.unzipString;
import static net.cdkj.gjj.adapter.domain.GzipUtil.zipString;
/** /**
* 公积金系统服务类 * 公积金系统服务类
...@@ -33,17 +43,21 @@ public class ProvidentFundServicesController { ...@@ -33,17 +43,21 @@ public class ProvidentFundServicesController {
if(!"".equals(token)&&token!=null){//若token未过期,则用内存中的token if(!"".equals(token)&&token!=null){//若token未过期,则用内存中的token
String resp = null; String resp = null;
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("app_id", "111"); jsonObject.put("startTime", currenttime(0));
jsonObject.put("app_secret", "222"); jsonObject.put("endTime", currenttime(24));
jsonObject.put("grant_type", "127.0.0.1"); jsonObject.put("app_id", "xxxxx");
jsonObject.put("app_secret", "xxxxx");
String str = jsonObject.toString(); String str = jsonObject.toString();
System.out.println("发送给第三方的报文:" + str); System.out.println("zip压缩处理之前要发送给第三方的报文:" + str);
String s = zipString(str);//进行zip压缩
System.out.println("zip压缩处理之后发送给第三方的报文:" + s);
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
HttpURLConnection conn = null; HttpURLConnection conn = null;
OutputStream out = null; OutputStream out = null;
try { try {
// 创建url 资源 // 创建url 资源
URL url = new URL("http://127.0.0.1:8080/FrontEndProcessor/FrontEndProcessor/ProvidentFundServices2");//测试第三方地址 // URL url = new URL("https://scjg.hubei.gov.cn/sjzt/api/dx/e39a08e0a52b413897f9d23359540b27/GJJ?access_token="+token);//正式第三方地址
URL url = new URL("http://127.0.0.1:8080/FrontEndProcessor/FrontEndProcessor/ProvidentFundServices2?access_token="+token);//测试第三方地址
// 创建http 连接 // 创建http 连接
conn = (HttpURLConnection) url.openConnection(); conn = (HttpURLConnection) url.openConnection();
// 设置允许输出 // 设置允许输出
...@@ -79,8 +93,10 @@ public class ProvidentFundServicesController { ...@@ -79,8 +93,10 @@ public class ProvidentFundServicesController {
sb.append(readLine); sb.append(readLine);
} }
responseReader.close(); responseReader.close();
System.out.println("第三方返回的报文:" + sb.toString()); System.out.println("第三方返回的zip压缩过的报文:" + sb.toString());
return sb.toString(); String s1 = unzipString(sb.toString());//将第三方返回的压缩过的json字符串解压缩
System.out.println("第三方返回的zip解压缩之后的报文:" + s1);
return s1;
} else { } else {
System.out.println("请求失败!!!"); System.out.println("请求失败!!!");
} }
...@@ -116,10 +132,48 @@ public class ProvidentFundServicesController { ...@@ -116,10 +132,48 @@ public class ProvidentFundServicesController {
public String ProvidentFundServices2() { public String ProvidentFundServices2() {
String resp = null; String resp = null;
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("expires_in", 60); jsonObject.put("code", 0);
jsonObject.put("access_token", "skdfhskjdfhskjdfhskdfjhk"); jsonObject.put("message", "数据交换成功");
List<UnitAccountOpeningInformation> data=new ArrayList<>();
UnitAccountOpeningInformation openingInformation=new UnitAccountOpeningInformation();
openingInformation.setBusId("332090874");
data.add(openingInformation);
jsonObject.put("data", data);
String str = jsonObject.toString(); String str = jsonObject.toString();
return jsonObject.toString(); return jsonObject.toString();
} }
/**
* 获取当天零点零分零秒的时间戳和当天24点的时间戳
* @return
*/
@ResponseBody
@PostMapping("currentime")
public static String currenttime(int type){
String time=null;
if(type==0){
// 获取当天零点零分零秒的时间戳
Calendar curentDay = Calendar.getInstance();
curentDay.setTime(new Date());
curentDay.set(Calendar.HOUR_OF_DAY, 0);
curentDay.set(Calendar.MINUTE, 0);
curentDay.set(Calendar.SECOND, 0);
SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
time=df2.format(curentDay.getTime().getTime());
System.out.println(time);
}else if(type==24){
// 获取当天24点零分零秒的时间戳,即第二天零点时间
Calendar curentDay = Calendar.getInstance();
curentDay.setTime(new Date());
curentDay.set(Calendar.HOUR_OF_DAY, 24);
curentDay.set(Calendar.MINUTE, 0);
curentDay.set(Calendar.SECOND, 0);
SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
time=df2.format(curentDay.getTime().getTime());
System.out.println(time);
}
return time;
}
} }
...@@ -40,6 +40,7 @@ public class TokenAcquisitionController { ...@@ -40,6 +40,7 @@ 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("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();
......
...@@ -8,7 +8,7 @@ import java.util.TimerTask; ...@@ -8,7 +8,7 @@ import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
* Cache缓存工具 * Cache缓存类
*/ */
public class TimeExpiredPoolCache { public class TimeExpiredPoolCache {
private static long defaultCachedMillis = 30 * 1000L;//过期时间默认10秒 private static long defaultCachedMillis = 30 * 1000L;//过期时间默认10秒
......
package net.cdkj.gjj.adapter.domain;
import java.util.Objects;
/**
* 单位开户信息对象
*/
public class UnitAccountOpeningInformation {
private String busId;
public String getBusId() {
return busId;
}
public void setBusId(String busId) {
this.busId = busId;
}
}
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