Commit c8a7b25e authored by JiangSN's avatar JiangSN

重构省平台对接代码,增加社会保险证明接口、居民身份信息查询接口

parent d241eed1
**EL-ADMIN 后台管理系统**
- 一个基于 Spring Boot 2.1.0 、 Spring Boot Jpa、 JWT、Spring Security、Redis、Vue、Element-UI 的前后端分离的后台管理系统
...@@ -31,10 +31,24 @@ public class CEGNController { ...@@ -31,10 +31,24 @@ public class CEGNController {
@Autowired @Autowired
private ICEGNService ICEGNService; private ICEGNService ICEGNService;
@ApiOperation("查询公司注册信息") @ApiOperation("企业登记基本信息查询")
@AnonymousAccess @AnonymousAccess
@RequestMapping("/queryEBaseinfosController") @RequestMapping("/queryEBaseinfos")
public String Test(Map map1) { public String queryEBaseinfos(Map map1) {
return ICEGNService.queryEBaseinfos(map1); return ICEGNService.queryEBaseinfos(map1);
} }
@ApiOperation("社会保险证明查询")
@AnonymousAccess
@RequestMapping("/getSocialSecurityCertificateDetail")
public String getSocialSecurityCertificateDetail(Map map1) {
return ICEGNService.getSocialSecurityCertificateDetail(map1);
}
@ApiOperation("公安厅居民身份证信息查询")
@AnonymousAccess
@RequestMapping("/gatlicresidentidcardlistquery")
public String gatlicresidentidcardlistquery(Map map1) {
return ICEGNService.gatlicresidentidcardlistquery(map1);
}
} }
...@@ -6,4 +6,8 @@ public interface ICEGNService { ...@@ -6,4 +6,8 @@ public interface ICEGNService {
String queryEBaseinfos(Map map); String queryEBaseinfos(Map map);
String getSocialSecurityCertificateDetail(Map map);
String gatlicresidentidcardlistquery(Map map);
} }
package me.zhengjie.serviceimpl; package me.zhengjie.serviceimpl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.java.Log; import lombok.extern.java.Log;
import me.zhengjie.service.ICEGNService; import me.zhengjie.service.ICEGNService;
import me.zhengjie.util.shengneiUtil; import me.zhengjie.util.shengneiUtil;
import me.zhengjie.util.JSONUtil;
import me.zhengjie.utils.RedisUtils; import me.zhengjie.utils.RedisUtils;
import org.apache.http.impl.client.CloseableHttpClient;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map; import java.util.Map;
/** /**
* @author JiangHeJia * @author JiangHeJia
* @version V1.0 * @version V1.1
* @Title: IGatewayZsjJIServiceImpl * @Title: IGatewayZsjJIServiceImpl
* @Package el-admin * @Package el-admin
* @Description: TODO(调用政务外网接口实现类) * @Description: 调用政务外网接口实现类
* @date 2021/10/11 11:14 * @date 2021年10月13日16:12:48
*/ */
@Service @Service
@Log @Log
public class IGatewayZsjJIServiceImpl implements ICEGNService { public class CGENServiceImpl implements ICEGNService {
@Autowired @Autowired
RedisUtils redisUtils; RedisUtils redisUtils;
/** /**
* @Title: queryEBaseinfos * @Title: queryEBaseinfos
* @Description: TODO(企业登记信息查询实现) * @Description: 企业登记信息查询实现
* * @param: Map * * @param: Map
* * @return: String * * @return: String
* @date: 2021/10/11 13:56 * @date: 2021/10/11 13:56
...@@ -40,28 +35,47 @@ public class IGatewayZsjJIServiceImpl implements ICEGNService { ...@@ -40,28 +35,47 @@ public class IGatewayZsjJIServiceImpl implements ICEGNService {
@Override @Override
public String queryEBaseinfos(Map map1) { public String queryEBaseinfos(Map map1) {
log.info("企业登记信息查询"); log.info("企业登记信息查询");
CloseableHttpClient httpClinet = shengneiUtil.createSSLClientDefault();
Map map = (Map) map1.get("BODY"); Map map = (Map) map1.get("BODY");
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String da = sdf.format(date);
String url = "https://gateway.zsj.jl.cegn.cn/api/visual/queryEBaseinfos";
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
obj.put("appId", "9eb8158ca2654c149ed2e7ea6e5b6830");
obj.put("version", "1.0.0");
obj.put("charset", "2");
obj.put("format", "JSON");
obj.put("timestamp", da);
obj.put("uniscid", map.get("TYSHXYDM")); obj.put("uniscid", map.get("TYSHXYDM"));
obj.put("entName", map.get("DWMC")); obj.put("entName", map.get("DWMC"));
log.info("发送内容" + obj); String doPost = shengneiUtil.doPosts(obj);
String doPost = shengneiUtil.doPost(url, obj.toString(), redisUtils.get("access_token").toString(), httpClinet); log.info("接口返回信息" + doPost);
Map resultMap = JSONUtil.toMap(doPost); return doPost;
//todo-sn 2021/10/11 10:30 Ash:判断token是否失效,失效重新获取token后再次发送请求;未测试 }
if ("token失效?".equals(resultMap.get("message"))){ /**
shengneiUtil.getToken(httpClinet); * @Title: getSocialSecurityCertificateDetail
doPost = shengneiUtil.doPost(url, obj.toString(), redisUtils.get("access_token").toString(), httpClinet); * @Description: 企业登记信息查询实现
} * * @param: Map
* * @return: String
* @date: 2021/10/11 13:56
*/
@Override
public String getSocialSecurityCertificateDetail(Map map1) {
log.info("企业登记信息查询");
Map map = (Map) map1.get("BODY");
JSONObject obj = new JSONObject();
obj.put("idCard", map.get("ZJHM"));
obj.put("name", map.get("XINGMING"));
String doPost = shengneiUtil.doPosts(obj);
log.info("接口返回信息" + doPost);
return doPost;
}
/**
* @Title: gatlicresidentidcardlistquery
* @Description: 公安厅居民身份证信息查询实现
* * @param: Map
* * @return: String
* @date: 2021/10/11 13:56
*/
@Override
public String gatlicresidentidcardlistquery(Map map1) {
log.info("公安厅居民身份证信息查询");
Map map = (Map) map1.get("BODY");
JSONObject obj = new JSONObject();
obj.put("idcardNo", map.get("ZJHM"));
obj.put("name", map.get("XINGMING"));
String doPost = shengneiUtil.doPosts(obj);
log.info("接口返回信息" + doPost); log.info("接口返回信息" + doPost);
return doPost; return doPost;
} }
......
...@@ -27,8 +27,8 @@ import java.io.IOException; ...@@ -27,8 +27,8 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.ArrayList; import java.text.SimpleDateFormat;
import java.util.List; import java.util.*;
/** /**
* @author JiangHeJia * @author JiangHeJia
...@@ -42,6 +42,7 @@ import java.util.List; ...@@ -42,6 +42,7 @@ import java.util.List;
public class shengneiUtil { public class shengneiUtil {
/** /**
* httpclient * httpclient
*
* @return * @return
*/ */
public static CloseableHttpClient createSSLClientDefault() { public static CloseableHttpClient createSSLClientDefault() {
...@@ -76,15 +77,16 @@ public class shengneiUtil { ...@@ -76,15 +77,16 @@ public class shengneiUtil {
nvps.add(new BasicNameValuePair("client_secret", "0b525da488a54ad8bf27ac3d857ed407")); nvps.add(new BasicNameValuePair("client_secret", "0b525da488a54ad8bf27ac3d857ed407"));
nvps.add(new BasicNameValuePair("grant_type", "client_credentials")); nvps.add(new BasicNameValuePair("grant_type", "client_credentials"));
nvps.add(new BasicNameValuePair("scope", "token")); nvps.add(new BasicNameValuePair("scope", "token"));
String jsonStr = httpPostCoder(httpClinet,"https://gateway.zsj.jl.cegn.cn/oauth2/token", nvps); //post请求 String jsonStr = httpPostCoder(httpClinet, "https://gateway.zsj.jl.cegn.cn/oauth2/token", nvps); //post请求
JSONObject parseObject = JSON.parseObject(jsonStr); JSONObject parseObject = JSON.parseObject(jsonStr);
if (!"".equals(parseObject.getString("access_token"))){ if (!"".equals(parseObject.getString("access_token"))) {
redisUtils.set("access_token",parseObject.getString("access_token")); redisUtils.set("access_token", parseObject.getString("access_token"));
log.info("获取token:"+redisUtils.get("access_token")); log.info("获取token:" + redisUtils.get("access_token"));
}else{ } else {
log.info("返回token为空"); log.info("返回token为空");
} }
} }
/** /**
* 非json参数方式POST提交 * 非json参数方式POST提交
* *
...@@ -93,7 +95,7 @@ public class shengneiUtil { ...@@ -93,7 +95,7 @@ public class shengneiUtil {
* @return * @return
*/ */
public static String httpPostCoder(CloseableHttpClient httpclient,String uri, List<NameValuePair> params) { public static String httpPostCoder(CloseableHttpClient httpclient, String uri, List<NameValuePair> params) {
String result = ""; String result = "";
try { try {
HttpPost httpPost = new HttpPost(uri); HttpPost httpPost = new HttpPost(uri);
...@@ -112,8 +114,10 @@ public class shengneiUtil { ...@@ -112,8 +114,10 @@ public class shengneiUtil {
} }
return result; return result;
} }
/** /**
* 转化 * 转化
*
* @param is * @param is
* @return * @return
*/ */
...@@ -138,10 +142,11 @@ public class shengneiUtil { ...@@ -138,10 +142,11 @@ public class shengneiUtil {
} }
return sb.toString(); return sb.toString();
} }
public static String doPost(String url ,String param,String token,CloseableHttpClient httpClinet){
public static String doPost(String url, String param, String token, CloseableHttpClient httpClinet) {
try { try {
HttpPost post = new HttpPost(url); HttpPost post = new HttpPost(url);
StringEntity entity = new StringEntity(param,"utf-8"); StringEntity entity = new StringEntity(param, "utf-8");
entity.setContentEncoding("UTF-8"); entity.setContentEncoding("UTF-8");
entity.setContentType("application/json"); entity.setContentType("application/json");
post.setEntity(entity); post.setEntity(entity);
...@@ -151,9 +156,29 @@ public class shengneiUtil { ...@@ -151,9 +156,29 @@ public class shengneiUtil {
HttpResponse response = httpClinet.execute(post); HttpResponse response = httpClinet.execute(post);
String rspBody = EntityUtils.toString(response.getEntity()); String rspBody = EntityUtils.toString(response.getEntity());
return rspBody; return rspBody;
}catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return ""; return "";
} }
public static String doPosts(JSONObject obj) {
CloseableHttpClient httpClinet = createSSLClientDefault();
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String da = sdf.format(date);
String url = "https://gateway.zsj.jl.cegn.cn/api/visual/queryEBaseinfos";
obj.put("appId", "9eb8158ca2654c149ed2e7ea6e5b6830");
obj.put("version", "1.0.0");
obj.put("charset", "2");
obj.put("format", "JSON");
obj.put("timestamp", da);
log.info("发送内容" + obj);
//todo-sn 2021/10/11 10:30 Ash:判断token是否失效,失效重新获取token后再次发送请求;未测试
//todo-sn 2021/10/13 15:51 Ash: 判断token是否为空,为空获取token
if (Objects.equals(redisUtils.get("access_token"), "") || Objects.equals(redisUtils.get("access_token"), null)) {
getToken(httpClinet);
}
return doPost(url, obj.toString(), redisUtils.get("access_token").toString(), httpClinet);
}
} }
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