Browse Source

无证名办事

dev
luyan 2 years ago
parent
commit
754be730dc
  1. 36
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/WzmDocumentRsultDTO.java
  2. 38
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/WzmProjectResultDTO.java
  3. 91
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/ActWithoutProofController.java
  4. 48
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/ActWithoutProofService.java
  5. 221
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/ActWithoutProofServiceImpl.java
  6. 240
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/util/ActWithoutProofUtils.java

36
epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/WzmDocumentRsultDTO.java

@ -0,0 +1,36 @@
package com.epmet.dto.result;
import lombok.Data;
import java.io.Serializable;
/**
* @author yan Lu
* @description 证明附件
* @create 2023/7/12 16:54
*/
@Data
public class WzmDocumentRsultDTO implements Serializable {
private static final long serialVersionUID = -7440939498135959130L;
/**
* 证明图片字符串
*/
private String base64str;
/**
* 证明时间戳
*/
private String timeqrcode;
/**
* 证明下载地址
*/
private String downloadurl;
/**
* 证明名称
*/
private String zmresultname;
}

38
epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/WzmProjectResultDTO.java

@ -0,0 +1,38 @@
package com.epmet.dto.result;
import lombok.Data;
import java.io.Serializable;
/**
* @author yan Lu
* @description 证明信息
* @create 2023/7/12 14:05
*/
@Data
public class WzmProjectResultDTO implements Serializable {
private static final long serialVersionUID = 5352302690919596385L;
/**
* 证明开具部门名称
*/
private String dealouname;
/**
* 证明类型 10:法人 20:个人
*/
private String applyertype;
/**
* 证明guid
*/
private String rowguid;
/**
* 证明名称
*/
private String zmtaskname;
}

91
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/ActWithoutProofController.java

@ -0,0 +1,91 @@
package com.epmet.controller;
import com.epmet.commons.tools.utils.Result;
import com.epmet.service.ActWithoutProofService;
import com.epmet.util.ActWithoutProofUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.Map;
/**
* @author yan Lu
* @description 无证名办事
* @create 2023/7/11 18:20
*/
@RestController
@RequestMapping("actingWP")
public class ActWithoutProofController {
@Autowired
private ActWithoutProofService actWithoutProofService;
/**
* 获取所有证明信息
*
* @param params
* @return
* @throws IOException
*/
@GetMapping("getAll")
public Result getAll(@RequestParam Map<String, Object> params) throws IOException {
String token = ActWithoutProofUtils.getToken();
if (StringUtils.isEmpty(token)) {
return new Result().error(-1, "获取token失败,请联系管理员!");
}
params.put("token", token);
return new Result().ok(actWithoutProofService.getZmTasks(params));
}
/**
* 根据证件号码和证明id获取证明附件下载地址
*
* @param params
* @return
* @throws IOException
*/
@GetMapping("getWzmProject")
public Result getWzmProject(@RequestParam Map<String, Object> params) throws IOException {
String idCard = "", certType = "", qrcode = "", xm = "", zmtaskguid = "";
String token = ActWithoutProofUtils.getToken();
if (StringUtils.isEmpty(token)) {
return new Result().error(-1, "获取token失败,请联系管理员!");
}
if (null != params.get("idCard")) {
idCard = (String) params.get("idCard");
certType = "001";//身份证
}
if (null != params.get("qrcode")) {
qrcode = (String) params.get("qrcode");
certType = "002";//统一信用代码证
}
if (null != params.get("xm")) {
xm = (String) params.get("xm");
}
if (null != params.get("zmtaskguid")) {
zmtaskguid = (String) params.get("zmtaskguid");
}
return new Result().ok(actWithoutProofService.getWzmProject(token, idCard, certType, qrcode, xm, zmtaskguid));
}
@GetMapping("redealProject")
public Result redealProject(@RequestParam Map<String, Object> params) throws IOException {
String idCard = "", zmtaskguid = "";
String token = ActWithoutProofUtils.getToken();
if (StringUtils.isEmpty(token)) {
return new Result().error(-1, "获取token失败,请联系管理员!");
}
if (null != params.get("idCard")) {
idCard = (String) params.get("idCard");
}
if (null != params.get("zmtaskguid")) {
zmtaskguid = (String) params.get("zmtaskguid");
}
return new Result().ok(actWithoutProofService.redealProject(token, idCard, zmtaskguid));
}
}

48
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/ActWithoutProofService.java

@ -0,0 +1,48 @@
package com.epmet.service;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.result.WzmDocumentRsultDTO;
import com.epmet.dto.result.WzmProjectResultDTO;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* @author yan Lu
* @description 描述
* @create 2023/7/12 09:47
*/
public interface ActWithoutProofService {
/**
* 获取所有证明信息
*
* @param token
* @return
* @throws IOException
*/
List<WzmProjectResultDTO> getZmTasks(Map<String, Object> token) throws IOException;
/**
* 根据居民身份证获取证明
*
* @param token
* @param idCard 身份证号码
* @param certType 证件类型 001身份证 002统一信用代码证
* @param qrcode 营业执照必填
* @param xm 残疾人证和不动产权属状况证明必填
* @param zmtaskguid 证明guid
*/
WzmDocumentRsultDTO getWzmProject(String token, String idCard, String certType, String qrcode, String xm, String zmtaskguid) throws IOException;
/**
* 重新开具证明
*
* @param token
* @param idCard
* @param zmtaskguid
* @return
*/
Result redealProject(String token, String idCard, String zmtaskguid) throws IOException;
}

221
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/ActWithoutProofServiceImpl.java

@ -0,0 +1,221 @@
package com.epmet.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.result.WzmDocumentRsultDTO;
import com.epmet.dto.result.WzmProjectResultDTO;
import com.epmet.service.ActWithoutProofService;
import com.epmet.util.ActWithoutProofUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Map;
/**
* @author yan Lu
* @description 描述
* @create 2023/7/12 09:48
*/
@Slf4j
@Service
public class ActWithoutProofServiceImpl implements ActWithoutProofService {
@Override
public List<WzmProjectResultDTO> getZmTasks(Map<String, Object> param) throws IOException {
CloseableHttpClient client = null;
CloseableHttpResponse response = null;
try {
//封装查询参数
JSONObject params = new JSONObject();
//分页大小 默认10
params.put("pageSize", null != param.get("pageSize") ? param.get("pageSize") : 10);
//当前页码 0开始
params.put("currentPage", null != param.get("currentPage") ? param.get("pageSize") : 0);
//证明名称 模糊查询
params.put("key", null != param.get("key") ? param.get("key") : "");
//申请人类型
params.put("type", null != param.get("type") ? param.get("type") : "");
//加密查询参数
byte[] encryptResult = ActWithoutProofUtils.encrypt(params.toString(), ActWithoutProofUtils.KEY);
String encryptResultStr = ActWithoutProofUtils.parseByte2HexStr(encryptResult);
String baseEncode = Base64.getEncoder().encodeToString(encryptResultStr.getBytes());
//请求
client = HttpClients.createDefault();
HttpPost post = new HttpPost(ActWithoutProofUtils.ALL_URL);
RequestConfig config = RequestConfig.custom().setConnectTimeout(10000).setConnectionRequestTimeout(3000).setSocketTimeout(10000).build();
post.setConfig(config);
post.setHeader("appKey", ActWithoutProofUtils.APP_KEY);
post.setHeader("Content-Type", "application/json");
params = new JSONObject();
params.put("token", param.get("token"));
params.put("params", baseEncode);
post.setEntity(new StringEntity(params.toString(), Charset.forName("UTF-8")));
response = client.execute(post);
//返回
JSONObject result = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
List<WzmProjectResultDTO> resultList = new ArrayList<>();
if (result.getString("code").equals("200")) {
JSONArray jsonArray = JSONObject.parseObject(result.getJSONObject("data").getString("custom")).getJSONArray("result");
if (null != jsonArray && jsonArray.size() > 0) {
for (Object data : jsonArray) {
JSONObject j = JSONObject.parseObject(data.toString());
WzmProjectResultDTO dto = new WzmProjectResultDTO();
dto.setDealouname(j.getString("dealouname"));
dto.setRowguid(j.getString("rowguid"));
dto.setApplyertype(j.getString("applyertype"));
dto.setZmtaskname(j.getString("zmtaskname"));
resultList.add(dto);
}
}
log.info(result.toString());
return resultList;
} else {
String erro = JSONObject.parseObject(result.getJSONObject("data").getString("custom")).getString("text");
log.error(erro, result.toString());
}
return new ArrayList<>();
} catch (Exception e) {
throw new EpmetException("获取失败,请联系管理员!");
} finally {
if (null != client) {
client.close();
}
response.close();
}
}
@Override
public WzmDocumentRsultDTO getWzmProject(String token, String idCard, String certType, String qrcode, String xm, String zmtaskguid) throws IOException {
CloseableHttpClient client = null;
CloseableHttpResponse response = null;
try {
//封装查询参数
JSONObject params = new JSONObject();
if (StringUtils.isNotEmpty(idCard)) {
//证件号码
params.put("certnum", idCard);
}
if (StringUtils.isNotEmpty(qrcode)) {
//营业执照必填
params.put("qrcode", qrcode);
//残疾人证和不动产权属状况证明必填
params.put("xm", xm);
}
//证明guid
params.put("zmtaskguid", zmtaskguid);
//证件类型 001 身份证 002 统一信用代码
params.put("certtype", certType);
//调用部门名称
params.put("searchou", ActWithoutProofUtils.LOGIN_ID);
//加密查询参数
byte[] encryptResult = ActWithoutProofUtils.encrypt(params.toString(), ActWithoutProofUtils.KEY);
String encryptResultStr = ActWithoutProofUtils.parseByte2HexStr(encryptResult);
String baseEncode = Base64.getEncoder().encodeToString(encryptResultStr.getBytes());
//请求
client = HttpClients.createDefault();
HttpPost post = new HttpPost(ActWithoutProofUtils.IdCard_URL);
RequestConfig config = RequestConfig.custom().setConnectTimeout(10000).setConnectionRequestTimeout(3000).setSocketTimeout(10000).build();
post.setConfig(config);
post.setHeader("appKey", ActWithoutProofUtils.APP_KEY);
post.setHeader("Content-Type", "application/json");
post.setHeader("Accept-Encoding", "deflate/br");
params = new JSONObject();
params.put("token", token);
params.put("params", baseEncode);
post.setEntity(new StringEntity(params.toString(), Charset.forName("UTF-8")));
response = client.execute(post);
//返回
JSONObject result = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
WzmDocumentRsultDTO dto = null;
if (result.getString("code").equals("200")) {
JSONArray jsonArray = JSONObject.parseObject(result.getJSONObject("data").getString("custom")).getJSONArray("result");
if (null != jsonArray && jsonArray.size() > 0) {
JSONObject j = JSONObject.parseObject(jsonArray.get(0).toString());
dto = new WzmDocumentRsultDTO();
dto.setZmresultname(j.getString("zmresultname"));
dto.setDownloadurl(j.getString("downloadurl"));
dto.setTimeqrcode(j.getString("timeqrcode"));
dto.setBase64str(j.getString("base64str"));
}
log.info(result.toString());
return dto;
} else {
String erro = JSONObject.parseObject(result.getJSONObject("data").getString("custom")).getString("text");
log.error(erro, result.toString());
return new WzmDocumentRsultDTO();
}
} catch (Exception e) {
throw new EpmetException("获取失败,请联系管理员!");
} finally {
if (null != client) {
client.close();
}
response.close();
}
}
@Override
public Result redealProject(String token, String idCard, String zmtaskguid) throws IOException {
CloseableHttpClient client = null;
CloseableHttpResponse response = null;
try {
//封装查询参数
JSONObject params = new JSONObject();
if (StringUtils.isNotEmpty(idCard)) {
params.put("certnum", idCard);
}
if (StringUtils.isNotEmpty(zmtaskguid)) {
params.put("zmtaskguid", zmtaskguid);
}
//加密查询参数
byte[] encryptResult = ActWithoutProofUtils.encrypt(params.toString(), ActWithoutProofUtils.KEY);
String encryptResultStr = ActWithoutProofUtils.parseByte2HexStr(encryptResult);
String baseEncode = Base64.getEncoder().encodeToString(encryptResultStr.getBytes());
//请求
client = HttpClients.createDefault();
HttpPost post = new HttpPost(ActWithoutProofUtils.REDEAL_URL);
RequestConfig config = RequestConfig.custom().setConnectTimeout(10000).setConnectionRequestTimeout(3000).setSocketTimeout(10000).build();
post.setConfig(config);
post.setHeader("appKey", ActWithoutProofUtils.APP_KEY);
post.setHeader("Content-Type", "application/json");
params = new JSONObject();
params.put("token", token);
params.put("params", baseEncode);
post.setEntity(new StringEntity(params.toString(), Charset.forName("UTF-8")));
response = client.execute(post);
//返回
JSONObject result = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
if (result.getString("code").equals("200")) {
JSONObject json = JSONObject.parseObject(result.getJSONObject("data").getString("custom"));
return new Result().ok(json.getString("text"));
} else {
JSONObject json = JSONObject.parseObject(result.getJSONObject("data").getString("custom"));
return new Result().error(-1, json.getString("text"));
}
} catch (Exception e) {
throw new EpmetException("请求失败,请联系管理员!");
} finally {
if (null != client) {
client.close();
}
response.close();
}
}
}

240
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/util/ActWithoutProofUtils.java

@ -0,0 +1,240 @@
package com.epmet.util;
import com.alibaba.fastjson.JSONObject;
import com.epmet.commons.tools.exception.EpmetException;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Base64;
/**
* @author yan Lu
* @description 无证名办事工具类
* @create 2023/7/11 18:42
*/
@Slf4j
public class ActWithoutProofUtils {
/**
* 认证用户
*/
public static final String LOGIN_ID = "zhihuishequ";
/**
* 数据加解密密钥
*/
public static final String KEY = "1122334455667788";
public static final String TOKEN_TITLE = "Epoint_WebSerivce_**##0601";
/**
* 加密后的参数值,没有KEY先这么用
*/
public static final String PARAM = "NTBBNTg3NEFDOUYyODdENEUwRDEyNDJBM0ZBQzFFN0Q3QUMwODZCQzFDQjUxRDI1MjA2NUJCMzNGMkVGOTg2OA==";
/**
* AppKey 客户端密钥
*/
public static final String APP_KEY = "1119322649315508224";
/**
* 1获取token URL
*/
public static final String TOKEN_URL = "https://rzzhsq.shuzirizhao.cn/gateway/api/1/rzzwfw/rest/rzwzmrest/getToken";
/**
* 2获取所有证明信息
*/
public static final String ALL_URL = "https://rzzhsq.shuzirizhao.cn/gateway/api/1/rzzwfw/rest/rzwzmcontroller/getZmTasks";
/**
* 3根据证件号码和证明id获取证明附件下载地址
*/
public static final String IdCard_URL = "https://rzzhsq.shuzirizhao.cn/gateway/api/1/rzzwfw/rest/rzwzmcontroller/getWzmProject";
/**
* 4重新开具
*/
public static final String REDEAL_URL = "https://rzzhsq.shuzirizhao.cn/gateway/api/1/rzzwfw/rest/rzwzmcontroller/redealProject";
/**
* 加密
*
* @param content 需要加密的内容
* @param password 加密密码
* @return
*/
public static byte[] encrypt(String content, String password) {
try {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128, new SecureRandom(password.getBytes()));
SecretKey secretKey = kgen.generateKey();
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
Cipher cipher = Cipher.getInstance("AES");// 创建密码器
byte[] byteContent = content.getBytes("utf-8");
cipher.init(Cipher.ENCRYPT_MODE, key);// 初始化
byte[] result = cipher.doFinal(byteContent);
return result; // 加密
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
return null;
}
/**
* 将二进制转换成16进制
*
* @param buf
* @return
*/
public static String parseByte2HexStr(byte buf[]) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < buf.length; i++) {
String hex = Integer.toHexString(buf[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
sb.append(hex.toUpperCase());
}
return sb.toString();
}
/**
* 解密 解密的时候要传入byte数组
*
* @param content 待解密内容
* @param password 解密密钥
* @return
*/
public static byte[] decrypt(byte[] content, String password) {
try {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128, new SecureRandom(password.getBytes()));
SecretKey secretKey = kgen.generateKey();
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
Cipher cipher = Cipher.getInstance("AES");// 创建密码器
cipher.init(Cipher.DECRYPT_MODE, key);// 初始化
byte[] result = cipher.doFinal(content);
return result; // 加密
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
JSONObject json = new JSONObject();
// json.put("certnum", "371102199801156835");
// json.put("certtype", "001");
// json.put("zmtaskguid", "49c82fe4-6a14-49e0-a688-69ca4b6961dc");
// json.put("zmtaskguid", "5cf03561-8e6e-4954-b9dd-eac898ae43f3");
// json.put("searchou", "公安局1号窗口");
// json.put("searchou", "zhihuishequ");
// json.put("xm", "");
json.put("loginid", "zhihuishequ");
String content = json.toString();
String key = "1122334455667788";
// 加密
System.out.println("加密前:" + content);
byte[] encryptResult = encrypt(content, key);
String encryptResultStr = parseByte2HexStr(encryptResult);
String baseEncode = Base64.getEncoder().encodeToString(encryptResultStr.getBytes());
System.out.println("加密后:" + baseEncode);
//解密
String baseDecode = new String(Base64.getDecoder().decode(baseEncode));
byte[] decryptFrom = parseHexStr2Byte(baseDecode);
byte[] decryptResult = decrypt(decryptFrom, key);
System.out.println("解密后:" + new String(decryptResult));
}
/**
* 将16进制转换为二进制
*
* @param hexStr
* @return
*/
public static byte[] parseHexStr2Byte(String hexStr) {
if (hexStr.length() < 1)
return null;
byte[] result = new byte[hexStr.length() / 2];
for (int i = 0; i < hexStr.length() / 2; i++) {
int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
result[i] = (byte) (high * 16 + low);
}
return result;
}
public static String getToken() throws IOException {
CloseableHttpClient client = null;
CloseableHttpResponse response = null;
try {
client = HttpClients.createDefault();
HttpPost post = new HttpPost(TOKEN_URL);
RequestConfig config = RequestConfig.custom().setConnectTimeout(10000).setConnectionRequestTimeout(3000).setSocketTimeout(10000).build();
post.setConfig(config);
post.setHeader("appKey", APP_KEY);
post.setHeader("Content-Type", "application/json");
JSONObject infoJson = new JSONObject();
infoJson.put("token", TOKEN_TITLE);
infoJson.put("params", PARAM);
post.setEntity(new StringEntity(infoJson.toString(), Charset.forName("UTF-8")));
response = client.execute(post);
JSONObject result = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
if (result.getString("code").equals("200")) {
log.info(result.toString());
return JSONObject.parseObject(result.getJSONObject("data").getString("custom")).getString("access_token");
} else {
String erro = JSONObject.parseObject(result.getJSONObject("data").getString("custom")).getString("text");
log.error(erro, result.toString());
return "";
}
} catch (Exception e) {
throw new EpmetException("获取token失败,请联系管理员!");
} finally {
if (null != client) {
client.close();
}
response.close();
}
}
}
Loading…
Cancel
Save