Commit 66d9427e authored by 张欣's avatar 张欣

Merge remote-tracking branch 'origin/master'

parents 2e06786a bd499f3d
...@@ -47,6 +47,12 @@ ...@@ -47,6 +47,12 @@
<version>1.18.12</version> <version>1.18.12</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.1-jre</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
......
...@@ -1036,6 +1036,117 @@ public class RequestController { ...@@ -1036,6 +1036,117 @@ public class RequestController {
return restTemlateService.commonSendRequest(paramMap, apiMethod); return restTemlateService.commonSendRequest(paramMap, apiMethod);
} }
/**
* 六十一.浙江杭州国土局不动产权属证书信息查询
*
* @param bdcqzh
* @param idCard
* @param additional
* @return
*/
@PostMapping("/zjshzgtjbdcqczsxxcx")
public ResponseEntity<String> zjshzgtjbdcqczsxxcx(String bdcqzh, String idCard, String additional) {
// api签名
String apiMethod = "zjshzgtjbdcqczsxxcx.action";
// api参数
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
paramMap.add("lice_cd", bdcqzh);
paramMap.add("id_nbr", idCard);
paramMap.add("additional", additional);
return restTemlateService.commonSendRequest(paramMap, apiMethod);
}
/**
* 六十二.浙江杭州国土抵押登记信息查询(新)
*
* @param param
* @return
*/
@PostMapping("/zjshzgtdydjxxcx")
public ResponseEntity<String> zjshzgtdydjxxcx(BaseParamVO param) {
// api签名
String apiMethod = "zjshzgtdydjxxcx.action";
// api参数
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
paramMap.add("name", param.getUserName());
paramMap.add("id_nbr", param.getIdCard());
paramMap.add("additional", param.getAdditional());
return restTemlateService.commonSendRequest(paramMap, apiMethod);
}
/**
* 六十三.浙江省失业保险参保人员信息查询
*
* @param param
* @return
*/
@PostMapping("/unemploymentInsuredInfo")
public ResponseEntity<String> unemploymentInsuredInfo(BaseParamVO param) {
// api签名
String apiMethod = "unemploymentInsuredInfo.action";
// api参数
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
paramMap.add("name", param.getUserName());
paramMap.add("cardId", param.getIdCard());
paramMap.add("additional", param.getAdditional());
return restTemlateService.commonSendRequest(paramMap, apiMethod);
}
/**
* 六十四.浙江省城镇三无对象供养查询
*
* @param param
* @return
*/
@PostMapping("/withoutSupportInfo")
public ResponseEntity<String> withoutSupportInfo(BaseParamVO param) {
// api签名
String apiMethod = "withoutSupportInfo.action";
// api参数
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
paramMap.add("name", param.getUserName());
paramMap.add("cardId", param.getIdCard());
paramMap.add("additional", param.getAdditional());
return restTemlateService.commonSendRequest(paramMap, apiMethod);
}
/**
* 六十五.浙江省低保救助信息查询
*
* @param param
* @return
*/
@PostMapping("/lowestRescueInfo")
public ResponseEntity<String> lowestRescueInfo(BaseParamVO param) {
// api签名
String apiMethod = "lowestRescueInfo.action";
// api参数
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
paramMap.add("cardId", param.getIdCard());
paramMap.add("additional", param.getAdditional());
return restTemlateService.commonSendRequest(paramMap, apiMethod);
}
/**
* 六十六.浙江省企业基本信息查询
*
* @param param
* @return
*/
@PostMapping("/enterpriseInfo")
public ResponseEntity<String> enterpriseInfo(SixtySixParamVO param) {
// api签名
String apiMethod = "enterpriseInfo.action";
// api参数
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
paramMap.add("uniscId", param.getUniscId());
paramMap.add("companyName", param.getOrgName());
paramMap.add("registerNo", param.getRegisterNo());
paramMap.add("entType", param.getEntType());
paramMap.add("additional", param.getAdditional());
return restTemlateService.commonSendRequest(paramMap, apiMethod);
}
@PostMapping("/") @PostMapping("/")
public ResponseEntity<String> method(BaseParamVO param) { public ResponseEntity<String> method(BaseParamVO param) {
......
package com.mth.requestsecret.controller;
import com.alibaba.fastjson.JSONObject;
import com.mth.requestsecret.service.RestTemlateService;
import com.mth.requestsecret.util.AESUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 招必得接口
*
* @author MaTianHao
* @date 2020/8/20
*/
@RestController
@Slf4j
public class ZbdController {
@Autowired
RestTemlateService restTemlateService;
/**
* 2.2 获取标段信息接口
*
* @param beginDate
* @param endDate
* @return
* @throws Exception
*/
@PostMapping("/getTenderInfo")
public ResponseEntity getTenderInfo(String beginDate, String endDate) throws Exception {
String apiMethod = "/la/supervise/getTenderInfo.do";
// 1. 设置参数
JSONObject requestParam = new JSONObject();
requestParam.put("BeginDate", beginDate);
requestParam.put("EndDate", endDate);
// 2. 加密参数并发送请求
return encryptRequestParam(requestParam, apiMethod);
}
/**
* 2.3 获取报名信息接口
*
* @param tenderNo
* @return
* @throws Exception
*/
@PostMapping("/getTenderBidInfo")
public ResponseEntity getTenderBidInfo(String tenderNo) throws Exception {
String apiMethod = "/la/supervise/getTenderBidInfo.do";
// 1. 设置参数
JSONObject requestParam = new JSONObject();
requestParam.put("TenderNo", tenderNo);
// 2. 加密参数并发送请求
return encryptRequestParam(requestParam, apiMethod);
}
/**
* 2.4 获取开标信息接口
*
* @param tenderNo
* @return
* @throws Exception
*/
@PostMapping("/getTenderOpenBidInfo")
public ResponseEntity getTenderOpenBidInfo(String tenderNo) throws Exception {
String apiMethod = "/la/supervise/getTenderOpenBidInfo.do";
// 1. 设置参数
JSONObject requestParam = new JSONObject();
requestParam.put("TenderNo", tenderNo);
// 2. 加密参数并发送请求
return encryptRequestParam(requestParam, apiMethod);
}
/**
* 2.5 获取中标信息接口
*
* @param tenderNo
* @return
* @throws Exception
*/
@PostMapping("/getTenderWinInfo")
public ResponseEntity getTenderWinInfo(String tenderNo) throws Exception {
String apiMethod = "/la/supervise/getTenderWinInfo.do";
// 1. 设置参数
JSONObject requestParam = new JSONObject();
requestParam.put("TenderNo", tenderNo);
// 2. 加密参数并发送请求
return encryptRequestParam(requestParam, apiMethod);
}
/**
* 2.6 获取评标信息接口
*
* @param tenderNo
* @return
* @throws Exception
*/
@PostMapping("/getTenderEvalInfo")
public ResponseEntity getTenderEvalInfo(String tenderNo) throws Exception {
String apiMethod = "/la/supervise/getTenderEvalInfo.do";
// 1. 设置参数
JSONObject requestParam = new JSONObject();
requestParam.put("TenderNo", tenderNo);
// 2. 加密参数并发送请求
return encryptRequestParam(requestParam, apiMethod);
}
/**
* 异常响应体
*/
private ResponseEntity exceptionResponseEntity() {
JSONObject resultBody = new JSONObject();
resultBody.put("success", false);
resultBody.put("error", "时间戳接口返回异常");
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(resultBody);
}
/**
* 根据 key 和 iv 加密参数
*/
private ResponseEntity encryptRequestParam(JSONObject requestParam, String apiMethod) throws Exception {
String encrypt = AESUtils.encrypt(requestParam.toJSONString());
JSONObject param = new JSONObject();
param.put("_args", encrypt);
log.info("{} - 参数:{}", apiMethod, requestParam.toJSONString());
try {
return restTemlateService.zbdSendRequest(param, apiMethod);
} catch (Exception e) {
return exceptionResponseEntity();
}
}
}
package com.mth.requestsecret.controller.vo;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author MaTianHao
* @date 2020/8/19
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class SixtySixParamVO extends CompanyParamVO {
/**
* 注册号
*/
private String registerNo;
/**
* 企业类型 E企业,P个体
*/
private String entType;
}
...@@ -38,13 +38,13 @@ public class RequestSecretSchedulerTask implements SchedulingConfigurer { ...@@ -38,13 +38,13 @@ public class RequestSecretSchedulerTask implements SchedulingConfigurer {
@Autowired @Autowired
RedisUtils redisUtil; RedisUtils redisUtil;
@Value("${DATA_API_ADDRESS}") @Value("${ruicheng.address}")
private String pathUrl; private String pathUrl;
@Value("${app.key}") @Value("${ruicheng.key}")
private String appKey; private String appKey;
@Value("${app.secret}") @Value("${ruicheng.secret}")
private String appSecret; private String appSecret;
/** /**
......
...@@ -2,6 +2,7 @@ package com.mth.requestsecret.service; ...@@ -2,6 +2,7 @@ package com.mth.requestsecret.service;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.mth.requestsecret.scheduler.RequestSecretSchedulerTask; import com.mth.requestsecret.scheduler.RequestSecretSchedulerTask;
import com.mth.requestsecret.util.AESUtils;
import com.mth.requestsecret.util.DSLUtils; import com.mth.requestsecret.util.DSLUtils;
import com.mth.requestsecret.util.MD5Utils; import com.mth.requestsecret.util.MD5Utils;
import com.mth.requestsecret.util.RedisUtils; import com.mth.requestsecret.util.RedisUtils;
...@@ -14,6 +15,7 @@ import org.springframework.util.MultiValueMap; ...@@ -14,6 +15,7 @@ import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.util.Date; import java.util.Date;
import java.util.Objects;
import static com.mth.requestsecret.constant.Constants.RESPONSE_CODE_14; import static com.mth.requestsecret.constant.Constants.RESPONSE_CODE_14;
import static com.mth.requestsecret.constant.Constants.SJJ_REQUEST_SECRET_PREFIX; import static com.mth.requestsecret.constant.Constants.SJJ_REQUEST_SECRET_PREFIX;
...@@ -40,12 +42,28 @@ public class RestTemlateService { ...@@ -40,12 +42,28 @@ public class RestTemlateService {
private ThreadLocal<Integer> threadLocal = ThreadLocal.withInitial(() -> 0); private ThreadLocal<Integer> threadLocal = ThreadLocal.withInitial(() -> 0);
@Value("${DATA_API_ADDRESS}") @Value("${ruicheng.address}")
private String pathUrl; private String pathUrl;
@Value("${app.key}") @Value("${ruicheng.key}")
private String appKey; private String appKey;
@Value("${zbd.appid}")
private String zbdAppid;
@Value("${zbd.appSecret}")
private String zbdAppSecret;
@Value("${zbd.address}")
private String zbdAddress;
/**
* 瑞成平台接口发送请求
*
* @param paramMap
* @param apiMethod
* @return
*/
public ResponseEntity<String> commonSendRequest(MultiValueMap<String, Object> paramMap, final String apiMethod) { public ResponseEntity<String> commonSendRequest(MultiValueMap<String, Object> paramMap, final String apiMethod) {
// 请求url拼接api签名和公共参数 // 请求url拼接api签名和公共参数
StringBuilder url = new StringBuilder() StringBuilder url = new StringBuilder()
...@@ -97,4 +115,57 @@ public class RestTemlateService { ...@@ -97,4 +115,57 @@ public class RestTemlateService {
} }
return responseEntity; return responseEntity;
} }
/**
* 招必得平台接口发送请求
*/
public ResponseEntity<String> zbdSendRequest(JSONObject paramMap, final String apiMethod) {
// 1. 获取请求时间戳并解密
String timeStamp = getZbdTimeStampAndDecrypt();
// 2. 拼接header验证签名
String signStr = zbdAppid + zbdAppSecret + timeStamp;
String sign = MD5Utils.encoderByMd5UpperCase(signStr);
// authorization : appid=xxx&sign=xxx
String authorization = "appid=" + zbdAppid + "&sign=" + sign;
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("authorization", authorization);
// 3. 发送请求
HttpEntity<String> request = new HttpEntity<>(paramMap.toJSONString(), headers);
String url = zbdAddress + apiMethod;
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, request, String.class);
// 4. 日志记录
log.info("招必得api:{}", apiMethod);
log.info("api url:{}", url);
log.info("api params:{}", paramMap);
log.info("api response:{}", responseEntity);
return responseEntity;
}
/**
* 获取请求时间戳并解密
*
* @return
*/
private String getZbdTimeStampAndDecrypt() {
String timeStampUrl = zbdAddress + "/gen/querytimestamp.do?appid=2020081001";
ResponseEntity<String> timeStampResponse = restTemplate.getForEntity(timeStampUrl, String.class);
JSONObject body = JSONObject.parseObject(timeStampResponse.getBody());
if (!(Objects.nonNull(body) && Objects.equals("true", body.getString("success")))) {
log.warn("招必得请求时间戳接口返回异常:{}", timeStampResponse);
throw new RuntimeException("时间戳接口异常");
}
// 解析返回值
String encryptTimestamp = body.getJSONObject("data").getString("encrypt_key");
// 解密
return AESUtils.decrypt(encryptTimestamp);
}
} }
\ No newline at end of file
package com.mth.requestsecret.util;
import lombok.extern.slf4j.Slf4j;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
/**
* @author MaTianHao
* @date 2020/8/19
*/
@Slf4j
public class AESUtils {
/**
* AES/CBC协定密钥key(256位)
*/
private final static String KEY = "LaKEXJRbiocF1iYOssFgj5Tdq1m0kFVO";
/**
* AES/CBC协定向量iv(128位)
*/
private final static String IV = "LaKEXJRbiocF1iYO";
/**
* 加密
*/
public static String encrypt(String sstr) throws Exception {
byte[] keyByte = KEY.getBytes("utf-8");
SecretKeySpec keySpec = new SecretKeySpec(keyByte, "AES");
// 算法/模式/补码方式
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
byte[] ivByte = IV.getBytes(StandardCharsets.UTF_8);
// 使用CBC模式,需要一个向量iv,可增加加密算法的强度
IvParameterSpec iv = new IvParameterSpec(ivByte);
cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv);
byte[] encrype = cipher.doFinal(sstr.getBytes());
// 此处使用BASE64做转码功能,同时能起到2次加密的作用。
return Base64.getEncoder().encodeToString(encrype);
}
/**
* 解密
*/
public static String decrypt(String sstr) {
try {
byte[] keyByte = KEY.getBytes("utf-8");
SecretKeySpec keySpec = new SecretKeySpec(keyByte, "AES");
// 算法/模式/补码方式
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
// 使用CBC模式,需要一个向量iv,可增加加密算法的强度
IvParameterSpec ivParameterSpec = new IvParameterSpec(IV.getBytes());
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivParameterSpec);
byte[] encrype = Base64.getDecoder().decode(sstr);
byte[] origin = cipher.doFinal(encrype);
return new String(origin);
} catch (Exception e) {
return null;
}
}
}
package com.mth.requestsecret.util; package com.mth.requestsecret.util;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
public class MD5Utils { public class MD5Utils {
public static String encoderByMd5(String plainText) { /**
String re_md5 = new String(); * md5加密
try { *
MessageDigest md = MessageDigest.getInstance("MD5"); * @param plainText
md.update(plainText.getBytes()); * @return
byte b[] = md.digest(); */
public static String encoderByMd5(String plainText) {
int i; String re_md5 = new String();
try {
StringBuffer buf = new StringBuffer(""); MessageDigest md = MessageDigest.getInstance("MD5");
for (int offset = 0; offset < b.length; offset++) { md.update(plainText.getBytes());
i = b[offset]; byte b[] = md.digest();
if (i < 0)
i += 256; int i;
if (i < 16)
buf.append("0"); StringBuffer buf = new StringBuffer("");
buf.append(Integer.toHexString(i)); for (int offset = 0; offset < b.length; offset++) {
} i = b[offset];
if (i < 0)
re_md5 = buf.toString(); i += 256;
if (i < 16)
} catch (NoSuchAlgorithmException e) { buf.append("0");
e.printStackTrace(); buf.append(Integer.toHexString(i));
} }
return re_md5;
} re_md5 = buf.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return re_md5;
}
/**
* md5加密(大写)
*
* @param plainText
* @return
*/
public static String encoderByMd5UpperCase(String plainText) {
String md5 = encoderByMd5(plainText);
return md5.toUpperCase();
}
} }
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