|
@@ -17,15 +17,19 @@ import com.boman.domain.dto.AjaxResult;
|
|
|
import com.boman.domain.utils.ThreadPoolService;
|
|
|
import com.boman.system.api.RemoteDeptService;
|
|
|
import com.boman.web.core.domain.GridInfo;
|
|
|
+import com.boman.web.core.domain.JsonRequest;
|
|
|
import com.boman.web.core.mapper.CzrkMapper;
|
|
|
import com.boman.web.core.mapper.GridInfoMapper;
|
|
|
import com.boman.web.core.service.ip.IpTimesService;
|
|
|
import com.boman.web.core.service.ip.IpTimesServiceImpl;
|
|
|
+import com.boman.web.core.utils.AESUtil;
|
|
|
import com.boman.web.core.utils.AuthUtils;
|
|
|
import com.boman.web.core.utils.IdCardUtils;
|
|
|
+import com.boman.web.core.utils.RSAUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.BooleanUtils;
|
|
|
+import org.apache.tomcat.util.buf.HexUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Isolation;
|
|
@@ -192,11 +196,23 @@ public class CzrkServiceImpl implements ICzrkService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void packAddr(JSONObject czrks) {
|
|
|
+ if (isEmpty(czrks)) return;
|
|
|
+ // 户籍地
|
|
|
+ String province = nullToEmpty(czrks.getString("province")), city = nullToEmpty(czrks.getString("city")), region = nullToEmpty(czrks.getString("region")), villageTowns = nullToEmpty(czrks.getString("villageTowns")), village = nullToEmpty(czrks.getString("village")), villageGroup = nullToEmpty(czrks.getString("villageGroup")), nowIn = nullToEmpty(czrks.getString("nowIn"));
|
|
|
+ czrks.put("domicileSelect", province + city + region + villageTowns + village + villageGroup + nowIn);
|
|
|
+
|
|
|
+ // 现居住地
|
|
|
+ String provinceCz = nullToEmpty(czrks.getString("provinceIdXjd")), cityCz = nullToEmpty(czrks.getString("cityIdXjd")), regionCz = nullToEmpty(czrks.getString("regionXjd")), villageTownsCz = nullToEmpty(czrks.getString("villageTownsXjd")), villageCz = nullToEmpty(czrks.getString("villageXjd")), nowInCz = nullToEmpty(czrks.getString("nowIn"));
|
|
|
+ czrks.put("nowInSelect",provinceCz + cityCz + regionCz + villageTownsCz + villageCz + nowInCz);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private void packCzrkJzdzAddr(List<CzrkJzdz> czrkJzdzList) {
|
|
|
if (isEmpty(czrkJzdzList)) return;
|
|
|
for (CzrkJzdz czrkJzdz : czrkJzdzList) {
|
|
|
// 户籍地
|
|
|
- String province = nullToEmpty(czrkJzdz.getProvince()), city = nullToEmpty(czrkJzdz.getCity()), region = nullToEmpty(czrkJzdz.getRegion()), villageTowns = nullToEmpty(czrkJzdz.getTown()), village = nullToEmpty(czrkJzdz.getVillage()), nowIn = nullToEmpty(czrkJzdz.getNowIn());
|
|
|
+ String province = nullToEmpty(czrkJzdz.getProvince()), city = nullToEmpty(czrkJzdz.getCity()), region = nullToEmpty(czrkJzdz.getRegion()), villageTowns = nullToEmpty(czrkJzdz.getTown()), village = nullToEmpty(czrkJzdz.getVillage()), nowIn = nullToEmpty(czrkJzdz.getNowIn());
|
|
|
czrkJzdz.setNowIn(province + city + region + villageTowns + village + nowIn);
|
|
|
}
|
|
|
}
|
|
@@ -284,11 +300,11 @@ public class CzrkServiceImpl implements ICzrkService {
|
|
|
log.info("{}于{}根据id:{},获取信息"
|
|
|
, AuthUtils.getLoginUser().getSysUser().getUserName(), DateUtils.dateTimeNow(), id);
|
|
|
Czrk czrk = czrkMapper.selectCzrkById(id);
|
|
|
- if (czrk != null){
|
|
|
+ if (czrk != null) {
|
|
|
Long gridId = czrk.getGridId();
|
|
|
- if (gridId != null){
|
|
|
+ if (gridId != null) {
|
|
|
GridInfo gridInfo = gridInfoMapper.selectGridInfoById(gridId);
|
|
|
- if (gridInfo != null){
|
|
|
+ if (gridInfo != null) {
|
|
|
String areaName = gridInfo.getAreaName();
|
|
|
czrk.setGridName(areaName);
|
|
|
}
|
|
@@ -750,7 +766,7 @@ public class CzrkServiceImpl implements ICzrkService {
|
|
|
});
|
|
|
|
|
|
return ZHEN;
|
|
|
- }else if (roleKeySets.contains("village")) {
|
|
|
+ } else if (roleKeySets.contains("village")) {
|
|
|
JSONObject jsonObject = redisService.getCacheObject(packRedisKey("village:" + deptId));
|
|
|
if (isNotEmpty(jsonObject)) {
|
|
|
CUN = jsonObject;
|
|
@@ -893,7 +909,7 @@ public class CzrkServiceImpl implements ICzrkService {
|
|
|
return jsonObject;
|
|
|
}
|
|
|
|
|
|
- ThreadPoolService.execute(()->{
|
|
|
+ ThreadPoolService.execute(() -> {
|
|
|
List<Long> deptIdList = null;
|
|
|
// 市领导 todo 此处不应该写死
|
|
|
List<String> roleKeySets = map(sysUser.getRoles(), SysRole::getRoleKey);
|
|
@@ -986,6 +1002,7 @@ public class CzrkServiceImpl implements ICzrkService {
|
|
|
|
|
|
/**
|
|
|
* 根据身份证号查询用户信息
|
|
|
+ *
|
|
|
* @param czrk
|
|
|
* @return
|
|
|
*/
|
|
@@ -1013,7 +1030,8 @@ public class CzrkServiceImpl implements ICzrkService {
|
|
|
checkAuth(appKey, appSecret);
|
|
|
checkIdCard(idCard);
|
|
|
|
|
|
-// String ip = IpUtils.getIpAddr(((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
|
|
+
|
|
|
+ String ipAddr = IpUtils.getIpAddr(((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
|
|
// log.info("调用ip:{}", ip);
|
|
|
// JSONObject jsonObject = ipTimesService.getByIp(ip);
|
|
|
JSONObject jsonObject = ipTimesService.countByUsername(appKey, appSecret);
|
|
@@ -1022,7 +1040,16 @@ public class CzrkServiceImpl implements ICzrkService {
|
|
|
return AjaxResult.error("appKey or appSecret is error");
|
|
|
}
|
|
|
|
|
|
+ String isStrong = jsonObject.getString("is_strong");
|
|
|
String ip = jsonObject.getString("ip");
|
|
|
+
|
|
|
+ //是否是强校验
|
|
|
+ if ("Y".equals(isStrong)) {
|
|
|
+ if (!ipAddr.equals(ip)) {
|
|
|
+ log.error("appKey:{}, appSecret:{}, ip:{}, idCard:{}", appKey, appSecret, ipAddr, idCard);
|
|
|
+ return AjaxResult.error("appKey or appSecret or ip is error");
|
|
|
+ }
|
|
|
+ }
|
|
|
String today = DateUtils.getDate();
|
|
|
String redisKey = IP_TIMES + jsonObject.getString("ip") + ":" + today;
|
|
|
Integer cacheTimes = redisService.getCacheObject(redisKey);
|
|
@@ -1033,22 +1060,113 @@ public class CzrkServiceImpl implements ICzrkService {
|
|
|
return AjaxResult.error("今日访问次数已用尽,请明日再试");
|
|
|
}
|
|
|
|
|
|
- Czrk czrk = czrkMapper.getColumnNamesByIdCard(jsonObject.getString("column_names"), idCard);
|
|
|
+ JSONObject czrk = czrkMapper.getColumnNamesByIdCard(jsonObject.getString("column_names"), idCard);
|
|
|
if (czrk == null) {
|
|
|
log.error("ip:{}, 时间:{}, 根据idCard:{}, 未查询到信息, 已经查询了 {} 次", ip, today, idCard, cacheTimes);
|
|
|
return AjaxResult.error("根据身份证号码未查询到信息");
|
|
|
}
|
|
|
|
|
|
- long time = DateUtils.getTodayEnd().getTime(),time1 = DateUtils.getNowDate().getTime();
|
|
|
+ long time = DateUtils.getTodayEnd().getTime(), time1 = DateUtils.getNowDate().getTime();
|
|
|
redisService.setCacheObject(redisKey, cacheTimes, ((time - time1) / 1000), TimeUnit.SECONDS);
|
|
|
- packAddr(Collections.singletonList(czrk));
|
|
|
+/* packAddr(Collections.singletonList(czrk));
|
|
|
|
|
|
CzrkJzdz czrkJzdz = new CzrkJzdz();
|
|
|
czrkJzdz.setCzrkId(czrk.getId());
|
|
|
List<CzrkJzdz> czrkJzdzList = czrkJzdzService.selectCzrkJzdzList(czrkJzdz);
|
|
|
packCzrkJzdzAddr(czrkJzdzList);
|
|
|
czrk.setCzrkJzdzList(czrkJzdzList);
|
|
|
- log.info("appKey:{}, appSecret:{}, idCard:{}, 查询到信息,czrk:{}", appKey, appSecret, idCard, JSON.toJSONString(czrk));
|
|
|
+ log.info("appKey:{}, appSecret:{}, idCard:{}, 查询到信息,czrk:{}", appKey, appSecret, idCard, JSON.toJSONString(czrk));*/
|
|
|
+ return AjaxResult.success(czrk);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * RSE加密请求
|
|
|
+ * 用RSE加密 ase的key(因为res加密有长度限制,ase没有,ase只有一个秘钥,所以使用rse来加密ase)
|
|
|
+ * 公钥对ase进行加密
|
|
|
+ * 私钥对签名进行加密
|
|
|
+ * 加密前的ase对请求参数进行加密
|
|
|
+ * ase用appid的前16位
|
|
|
+ * appid = uuid32
|
|
|
+ *
|
|
|
+ * @param jsonRequest
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AjaxResult getInfoJson(JsonRequest jsonRequest) {
|
|
|
+ //获取这个用户的appId
|
|
|
+ String appId = jsonRequest.getAppId();
|
|
|
+ if (StringUtils.isBlank(appId)) {
|
|
|
+ return AjaxResult.error("缺少appId参数");
|
|
|
+ }
|
|
|
+ //拿着appid去查询对应的密钥对
|
|
|
+ JSONObject ipTimes = ipTimesService.selectByAppId(appId);
|
|
|
+ if (ipTimes == null || ipTimes.size() == 0) {
|
|
|
+ return AjaxResult.error("该appId不存在");
|
|
|
+ }
|
|
|
+ String publicKey = ipTimes.getString("app_key");
|
|
|
+ String privateKey = ipTimes.getString("app_secret");
|
|
|
+ Map<String, Object> paramMap = RSAUtil.bean2Map(jsonRequest);
|
|
|
+ paramMap.remove("sign");
|
|
|
+ //参数排序
|
|
|
+ Map<String, Object> sortedMap = RSAUtil.sort(paramMap);
|
|
|
+ //拼接参数:key1Value1key2Value2
|
|
|
+ String urlParams2 = RSAUtil.groupStringParam(sortedMap);
|
|
|
+ //签名验证
|
|
|
+ boolean verify = RSAUtil.verify(HexUtils.fromHexString(urlParams2), publicKey, jsonRequest.getSign());
|
|
|
+ if (!verify) {
|
|
|
+ throw new RuntimeException("签名验证失败");
|
|
|
+ }
|
|
|
+ //私钥解密,获取aseKey
|
|
|
+ String aseKey = RSAUtil.decryptByPrivateKey(HexUtils.fromHexString(jsonRequest.getAseKey()), privateKey);
|
|
|
+ String requestBody = "";
|
|
|
+ if (!StringUtils.isEmpty(jsonRequest.getBody())) {
|
|
|
+ // 解密请求报文
|
|
|
+ try {
|
|
|
+ //vi值为18
|
|
|
+ requestBody = AESUtil.decrypt(jsonRequest.getBody(), aseKey, appId.substring(16));
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("请求参数解密异常");
|
|
|
+ }
|
|
|
+ System.out.println("业务参数解密结果:" + requestBody);
|
|
|
+ }
|
|
|
+ //获取请求的id
|
|
|
+ String ipAddr = IpUtils.getIpAddr(((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
|
|
+ String isStrong = ipTimes.getString("is_strong");
|
|
|
+ String ip = ipTimes.getString("ip");
|
|
|
+ //是否是强校验
|
|
|
+ if ("Y".equals(isStrong)) {
|
|
|
+ if (!ipAddr.equals(ip)) {
|
|
|
+ return AjaxResult.error("ip不正确");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String today = DateUtils.getDate();
|
|
|
+ String redisKey = IP_TIMES + ip + ":" + today;
|
|
|
+ Integer cacheTimes = redisService.getCacheObject(redisKey);
|
|
|
+ if (cacheTimes == null) cacheTimes = 0;
|
|
|
+ int times = ipTimes.getIntValue("times");
|
|
|
+ if (++cacheTimes > times) {
|
|
|
+ log.error("ip:{}, 时间:{}, 访问超次数, 已经查询了 {} 次", ip, today, cacheTimes);
|
|
|
+ return AjaxResult.error("今日访问次数已用尽,请明日再试");
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(requestBody);
|
|
|
+ String idCard = jsonObject.getString("idCard");
|
|
|
+ JSONObject czrk = czrkMapper.getColumnNamesByIdCard(ipTimes.getString("column_names"), idCard);
|
|
|
+ if (czrk == null) {
|
|
|
+ log.error("ip:{}, 时间:{}, 根据idCard:{}, 未查询到信息, 已经查询了 {} 次", ip, today, idCard, cacheTimes);
|
|
|
+ return AjaxResult.error("根据身份证号码未查询到信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ long time = DateUtils.getTodayEnd().getTime(), time1 = DateUtils.getNowDate().getTime();
|
|
|
+ redisService.setCacheObject(redisKey, cacheTimes, ((time - time1) / 1000), TimeUnit.SECONDS);
|
|
|
+ packAddr(czrk);
|
|
|
+
|
|
|
+ CzrkJzdz czrkJzdz = new CzrkJzdz();
|
|
|
+ czrkJzdz.setCzrkId(czrk.getLong("id"));
|
|
|
+ List<CzrkJzdz> czrkJzdzList = czrkJzdzService.selectCzrkJzdzList(czrkJzdz);
|
|
|
+ packCzrkJzdzAddr(czrkJzdzList);
|
|
|
+ czrk.put("czrkJzdzList", czrkJzdzList);
|
|
|
+ log.info("appKey:{}, appSecret:{}, idCard:{}, 查询到信息,czrk:{}", publicKey, privateKey, idCard, JSON.toJSONString(czrk));
|
|
|
return AjaxResult.success(czrk);
|
|
|
}
|
|
|
|
|
@@ -1061,12 +1179,13 @@ public class CzrkServiceImpl implements ICzrkService {
|
|
|
}
|
|
|
|
|
|
private void checkAuth(String appKey, String appSecret) {
|
|
|
- if (isEmpty(appKey) || isEmpty(appSecret) ) {
|
|
|
+ if (isEmpty(appKey) || isEmpty(appSecret)) {
|
|
|
throw new RuntimeException("appKey or appSecret must not be empty");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
private void checkIdCard(String idCard) {
|
|
|
- if (isEmpty(idCard) ) {
|
|
|
+ if (isEmpty(idCard)) {
|
|
|
throw new RuntimeException("idCard must not be empty");
|
|
|
}
|
|
|
}
|