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 {
@Autowired
private ICEGNService ICEGNService;
@ApiOperation("查询公司注册信息")
@ApiOperation("企业登记基本信息查询")
@AnonymousAccess
@RequestMapping("/queryEBaseinfosController")
public String Test(Map map1) {
@RequestMapping("/queryEBaseinfos")
public String queryEBaseinfos(Map 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 {
String queryEBaseinfos(Map map);
String getSocialSecurityCertificateDetail(Map map);
String gatlicresidentidcardlistquery(Map map);
}
package me.zhengjie.serviceimpl;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.java.Log;
import me.zhengjie.service.ICEGNService;
import me.zhengjie.util.shengneiUtil;
import me.zhengjie.util.JSONUtil;
import me.zhengjie.utils.RedisUtils;
import org.apache.http.impl.client.CloseableHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
/**
* @author JiangHeJia
* @version V1.0
* @version V1.1
* @Title: IGatewayZsjJIServiceImpl
* @Package el-admin
* @Description: TODO(调用政务外网接口实现类)
* @date 2021/10/11 11:14
* @Description: 调用政务外网接口实现类
* @date 2021年10月13日16:12:48
*/
@Service
@Log
public class IGatewayZsjJIServiceImpl implements ICEGNService {
public class CGENServiceImpl implements ICEGNService {
@Autowired
RedisUtils redisUtils;
/**
* @Title: queryEBaseinfos
* @Description: TODO(企业登记信息查询实现)
* @Description: 企业登记信息查询实现
* * @param: Map
* * @return: String
* @date: 2021/10/11 13:56
......@@ -40,28 +35,47 @@ public class IGatewayZsjJIServiceImpl implements ICEGNService {
@Override
public String queryEBaseinfos(Map map1) {
log.info("企业登记信息查询");
CloseableHttpClient httpClinet = shengneiUtil.createSSLClientDefault();
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();
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("entName", map.get("DWMC"));
log.info("发送内容" + obj);
String doPost = shengneiUtil.doPost(url, obj.toString(), redisUtils.get("access_token").toString(), httpClinet);
Map resultMap = JSONUtil.toMap(doPost);
//todo-sn 2021/10/11 10:30 Ash:判断token是否失效,失效重新获取token后再次发送请求;未测试
if ("token失效?".equals(resultMap.get("message"))){
shengneiUtil.getToken(httpClinet);
doPost = shengneiUtil.doPost(url, obj.toString(), redisUtils.get("access_token").toString(), httpClinet);
}
String doPost = shengneiUtil.doPosts(obj);
log.info("接口返回信息" + doPost);
return doPost;
}
/**
* @Title: getSocialSecurityCertificateDetail
* @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);
return doPost;
}
......
......@@ -27,8 +27,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author JiangHeJia
......@@ -42,6 +42,7 @@ import java.util.List;
public class shengneiUtil {
/**
* httpclient
*
* @return
*/
public static CloseableHttpClient createSSLClientDefault() {
......@@ -76,15 +77,16 @@ public class shengneiUtil {
nvps.add(new BasicNameValuePair("client_secret", "0b525da488a54ad8bf27ac3d857ed407"));
nvps.add(new BasicNameValuePair("grant_type", "client_credentials"));
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);
if (!"".equals(parseObject.getString("access_token"))){
redisUtils.set("access_token",parseObject.getString("access_token"));
log.info("获取token:"+redisUtils.get("access_token"));
}else{
if (!"".equals(parseObject.getString("access_token"))) {
redisUtils.set("access_token", parseObject.getString("access_token"));
log.info("获取token:" + redisUtils.get("access_token"));
} else {
log.info("返回token为空");
}
}
/**
* 非json参数方式POST提交
*
......@@ -93,7 +95,7 @@ public class shengneiUtil {
* @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 = "";
try {
HttpPost httpPost = new HttpPost(uri);
......@@ -112,8 +114,10 @@ public class shengneiUtil {
}
return result;
}
/**
* 转化
*
* @param is
* @return
*/
......@@ -138,10 +142,11 @@ public class shengneiUtil {
}
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 {
HttpPost post = new HttpPost(url);
StringEntity entity = new StringEntity(param,"utf-8");
StringEntity entity = new StringEntity(param, "utf-8");
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
post.setEntity(entity);
......@@ -151,9 +156,29 @@ public class shengneiUtil {
HttpResponse response = httpClinet.execute(post);
String rspBody = EntityUtils.toString(response.getEntity());
return rspBody;
}catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
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