Commit 4ae52f29 by liulianglang

单点登录,用户姓名,撤控

parent 1301bb61
......@@ -54,4 +54,25 @@ public class gjcxController {
}
}
@PostMapping("/deleteBkzp")
public R deleteBkzp(String certNo){
try {
return R.ok().data(ztService.deleteBkzp(certNo));
} catch (Exception e) {
e.printStackTrace();
return R.error(e.getMessage());
}
}
@PostMapping("/deleteYjjl")
public R deleteYjjl(String xxzjbh){
try {
return R.ok().data(ztService.deleteYjjl(xxzjbh));
} catch (Exception e) {
e.printStackTrace();
return R.error(e.getMessage());
}
}
}
package org.springblade.founder.ztrxyj.entity;
import lombok.Data;
import java.util.Date;
@Data
public class ZtryYjYhcz {
/**
* 信息主键
*/
private String xxzjbh;
/**
* 信息主键
*/
private String glxxzjbh;
/**
* 信息登记人员_姓名
*/
private String xxdjryXm;
/**
* 信息登记人员_联系电话
*/
private String xxdjryLxdh;
/**
* 信息登记单位_公安机关名称
*/
private String xxdjdwGajgmc;
/**
* 信息登记人员_公民身份号码
*/
private String xxdjryGmsfhm;
/**
* 信息登记单位_公安机关机构代码
*/
private String xxdjdwGajgjgdm;
/**
* 登记时间
*/
private Date djsj;
/**
* 操作类型:1删除
*/
private String czlx;
}
......@@ -21,7 +21,25 @@ public class Ztryyjxx {
private String score;
private String captureTime;
private String captureTimeKssj;
private String scrxm;
public String getScrxm() {
return scrxm;
}
public void setScrxm(String scrxm) {
this.scrxm = scrxm;
}
public String getScrdwmc() {
return scrdwmc;
}
public void setScrdwmc(String scrdwmc) {
this.scrdwmc = scrdwmc;
}
private String scrdwmc;
public String getCaptureTimeKssj() {
return captureTimeKssj;
}
......@@ -47,6 +65,16 @@ public class Ztryyjxx {
private String deviceId;
private String deviceName;
private String captureUrl;
public String getScbz() {
return scbz;
}
public void setScbz(String scbz) {
this.scbz = scbz;
}
private String scbz;
private int page;
......
......@@ -3,6 +3,7 @@ package org.springblade.founder.ztrxyj.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.springblade.founder.ztrxyj.entity.ZtryBksj;
import org.springblade.founder.ztrxyj.entity.ZtryYjYhcz;
import org.springblade.founder.ztrxyj.entity.Ztryyjxx;
import org.springframework.stereotype.Component;
......@@ -23,4 +24,10 @@ public interface ztgjMapper {
List<ZtryBksj> getBkzpList(ZtryBksj ztryBksj);
int getBkzpListCount(ZtryBksj ztryBksj);
ZtryBksj getMaztryZp(String certNo);
int updatesftsZtzp(String certNo);
int insertYjYhcz(ZtryYjYhcz ztryYjYhcz);
int updateYjsc(String xxzjbh);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.founder.ztrxyj.mapper.ztgjMapper">
<insert id="insertYjYhcz">
insert into tb_maztry_yj_yhcz(xxzjbh,glxxzjbh, xxdjry_xm, xxdjry_lxdh, xxdjdw_gajgmc, xxdjry_gmsfhm, xxdjdw_gajgjgdm, djsj, czlx)
values (#{xxzjbh},#{glxxzjbh}, #{xxdjryXm}, #{xxdjryLxdh}, #{xxdjdwGajgmc}, #{xxdjryGmsfhm}, #{xxdjdwGajgjgdm}, now(), #{czlx})
</insert>
<update id="updatesftsZtzp">
update tb_ry_maztryzp set sfts = '3' ,gxsj=now()
where identitycard=#{ certNo , jdbcType=VARCHAR }
</update>
<update id="updateYjsc">
update tb_maztry_yj set scbz='1',gxsj=now() where xxzjbh = #{xxzjbh}
</update>
<select id="getListYjgj" resultType="org.springblade.founder.ztrxyj.entity.Ztryyjxx">
select xxzjbh, faceName, faceUrl, score, captureTime,
faceDbId, faceCertNo, alarmTime, faceDbName, panoramaUrl, deviceId, deviceName, captureUrl from tb_maztry_yj yj right join (
select
faceCertNo idcard, max(captureTime) zpsj
from tb_maztry_yj
select xxzjbh, faceName, faceUrl, score, captureTime,
faceDbId, faceCertNo, alarmTime, faceDbName, panoramaUrl, deviceId, deviceName,
captureUrl from tb_maztry_yj yj right join (
select idcard,zpsj from ( select
faceCertNo idcard, max(captureTime) zpsj
from tb_maztry_yj
<where>
<if test="xxzjbh != null and xxzjbh != ''">
and scbz='0'
<if test="xxzjbh != null and xxzjbh != ''">
and xxzjbh = #{xxzjbh}
</if>
<if test="faceName != null and faceName != ''">
......@@ -23,10 +40,10 @@ from tb_maztry_yj
and captureTime = #{captureTime}
</if>
<if test="captureTimeKssj != null and captureTimeKssj != ''">
and captureTime <![CDATA[>=]]> DATE_FORMAT(#{captureTimeKssj,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%s')
and captureTime <![CDATA[>=]]> DATE_FORMAT(#{captureTimeKssj,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%s')
</if>
<if test="captureTimeJssj != null and captureTimeJssj != ''">
and captureTime <![CDATA[<]]> DATE_FORMAT(#{captureTimeJssj,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%s')
and captureTime <![CDATA[<]]> DATE_FORMAT(#{captureTimeJssj,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%s')
</if>
<if test="faceDbId != null and faceDbId != ''">
and faceDbId = #{faceDbId}
......@@ -50,16 +67,21 @@ from tb_maztry_yj
</where>
group by faceCertNo order by zpsj desc limit #{ page }, #{ limit }
) bb on yj.faceCertNo=bb.idcard and yj.captureTime=bb.zpsj
group by
faceCertNo ) abc left join tb_ry_maztryzp zp on zp.identitycard=abc.idcard where zp.sfts='1'
order
by abc.zpsj desc limit #{ page }, #{ limit }
) bb on yj.faceCertNo=bb.idcard and yj.captureTime=bb.zpsj
</select>
<select id="getListYjgjCount" resultType="java.lang.Integer">
select count(1) from ( select
faceCertNo idcard, max(captureTime) zpsj
from tb_maztry_yj
select count(1) from ( select idcard,zpsj from ( select
faceCertNo idcard, max(captureTime) zpsj
from tb_maztry_yj
<where>
and scbz='0'
<if test="xxzjbh != null and xxzjbh != ''">
and xxzjbh = #{xxzjbh}
</if>
......@@ -74,10 +96,10 @@ from tb_maztry_yj
and captureTime = #{captureTime}
</if>
<if test="captureTimeKssj != null and captureTimeKssj != ''">
and captureTime <![CDATA[>=]]> DATE_FORMAT(#{captureTimeKssj,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%s')
and captureTime <![CDATA[>=]]> DATE_FORMAT(#{captureTimeKssj,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%s')
</if>
<if test="captureTimeJssj != null and captureTimeJssj != ''">
and captureTime <![CDATA[<]]> DATE_FORMAT(#{captureTimeJssj,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%s')
and captureTime <![CDATA[<]]> DATE_FORMAT(#{captureTimeJssj,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%s')
</if>
<if test="faceDbId != null and faceDbId != ''">
and faceDbId = #{faceDbId}
......@@ -101,14 +123,21 @@ from tb_maztry_yj
</where>
group by faceCertNo ) bb
group by
faceCertNo ) abc left join tb_ry_maztryzp zp on zp.identitycard=abc.idcard where zp.sfts='1'
) bb
</select>
<select id="getListYjXqgj" resultType="org.springblade.founder.ztrxyj.entity.Ztryyjxx">
select xxzjbh, faceName, faceUrl, score, captureTime,
faceDbId, faceCertNo, alarmTime, faceDbName, panoramaUrl, deviceId, deviceName, captureUrl
faceDbId, faceCertNo, alarmTime, faceDbName, panoramaUrl, deviceId, deviceName, captureUrl,
(select cz.xxdjry_xm from tb_maztry_yj_yhcz cz where cz.glxxzjbh=yj.xxzjbh limit 1 ) scrxm,
(select cz.xxdjdw_gajgmc from tb_maztry_yj_yhcz cz where cz.glxxzjbh=yj.xxzjbh limit 1) scrdwmc
from tb_maztry_yj yj
<where>
<if test="scbz != null and scbz != ''">
and scbz=#{scbz}
</if>
<if test="xxzjbh != null and xxzjbh != ''">
and xxzjbh = #{xxzjbh}
</if>
......@@ -155,6 +184,10 @@ group by faceCertNo ) bb
<select id="getListYjXqgjCount" resultType="java.lang.Integer">
select count(1) from tb_maztry_yj yj
<where>
<if test="scbz != null and scbz != ''">
and scbz=#{scbz}
</if>
<if test="xxzjbh != null and xxzjbh != ''">
and xxzjbh = #{xxzjbh}
</if>
......@@ -219,6 +252,10 @@ group by faceCertNo ) bb
and xm = #{name}
</if>
</select>
<select id="getMaztryZp" resultType="org.springblade.founder.ztrxyj.entity.ZtryBksj">
select ztry.xm as name,ztry.identitycard as certNo ,ztry.ckzp as imgFace from tb_ry_maztryzp ztry
where ztry.identitycard=#{certNo}
</select>
</mapper>
......@@ -14,5 +14,7 @@ public interface ztgjService {
Map<String, Object> getBkzpList(ZtryBksj ztryBksj);
Map<String, Object> deleteBkzp(String certNo);
Map<String, Object> deleteYjjl(String xxzjbh);
}
......@@ -4,13 +4,17 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.founder.utils.EasyUIPage;
import org.springblade.founder.utils.HttpClient;
import org.springblade.founder.utils.R;
import org.springblade.founder.ztrxyj.entity.ZtryBksj;
import org.springblade.founder.ztrxyj.entity.ZtryYjYhcz;
import org.springblade.founder.ztrxyj.entity.Ztryyjxx;
import org.springblade.founder.ztrxyj.mapper.ztgjMapper;
import org.springblade.founder.ztrxyj.utils.TokenUtils;
import org.springblade.modules.system.entity.XzxtUser;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
......@@ -66,6 +70,81 @@ public class ztgjServiceImpl implements ztgjService {
}
@Override
public Map<String, Object> deleteBkzp(String certNo) {
ZtryBksj sj=ztgj.getMaztryZp(certNo);
String url = "http://74.10.30.174:18093/govServerWeb/personFace/pictureToFaceDb";
String token="";
if(sj!=null) {
if(StringUtils.isEmpty(token)){
token= TokenUtils.getHnKyToken();
}
Map herders=new HashMap();
//设置请求的header参数
herders.put("Authorization",token);
herders.put("Content-Type","application/json");
//推送布控入库人像
// JSONObject params = new JSONObject();// 请求参数
// params.put("imgFace",imgFace);
// params.put("captureBeginTime"
// ,gxsjKssj);
// params.put("captureEndTime",gxsjJssj);
// params.put("","");
sj.setImgFace(sj.getImgFace().replaceAll("\\s*|\r|\n|\t",""));
// System.out.println(sj.getImgFace());
sj.setOperate("0");
sj.setFaceDBId("700046010603000104");
try {
String resultString = HttpClient.doPostJson(url, herders, JSONObject.toJSONString(sj));
System.out.println("bksjts==="+resultString);
JSONObject result=JSONObject.parseObject(resultString);
if(result.getInteger("code")==200){
ztgj.updatesftsZtzp(certNo);
}else {
//推送未成功2,删除3,推送成功1
ztgj.updatesftsZtzp(certNo);
}
}catch (Exception e){
e.printStackTrace();
}
}
return null;
}
@Override
public Map<String, Object> deleteYjjl(String xxzjbh) {
XzxtUser user = SecureUtil.getUserXzxt();
ZtryYjYhcz yhcz=new ZtryYjYhcz();
yhcz.setXxzjbh(getOrderIdByUuid());
yhcz.setGlxxzjbh(xxzjbh);
yhcz.setXxdjryXm(user.getRealname());
yhcz.setXxdjdwGajgjgdm(user.getUnitcode());
yhcz.setXxdjdwGajgmc(user.getUnitname());
yhcz.setXxdjryGmsfhm(user.getIdentitycard());
yhcz.setXxdjryLxdh(user.getPhone());
yhcz.setCzlx("1"); //删除
ztgj.updateYjsc(xxzjbh);
ztgj.insertYjYhcz(yhcz);
return null;
}
private static String getOrderIdByUuid() {
//最大支持1-9个集群机器部署
int machineId = 1;
int hashCodeV = UUID.randomUUID().toString().hashCode();
//有可能是负数
if (hashCodeV < 0) {
hashCodeV = -hashCodeV;
}
// 0 代表前面补充0
// 4 代表长度为4
// d 代表参数为正数型
return machineId + String.format("%015d", hashCodeV);
}
@Override
public Map<String, Object> getListYjXqgj(Ztryyjxx ztryyjxx) {
Map<String, Object> rtMap = new HashMap<>();
EasyUIPage easyUIPage = new EasyUIPage();
......
package org.springblade.founder.ztrxyj.utils;
import cn.hutool.core.exceptions.ExceptionUtil;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
import java.util.Properties;
@Slf4j
public class PropertieUtil {
/**
* 读取配置文件某属性绝对路径下的token
*/
public String readTokenValue(String key, String url) {
String value = "";
try {
Properties prop = new Properties();
// FileInputStream fileInputStream = new FileInputStream(url);
InputStream fileInputStream = this.getClass().getResourceAsStream("/token.properties");
prop.load(fileInputStream);
value = prop.getProperty(key);
fileInputStream.close();
} catch (Exception e) {
e.printStackTrace();
log.error(ExceptionUtil.getMessage(e));
}
return value;
}
/**
* 将值写入配置文件绝对路径下的token
*/
public void writeTokenProperties(String token_url, String parameterName, String parameterValue) throws Exception {
String filePath = token_url;
// 获取配置文件
Properties pps = new Properties();
// FileInputStream fileInputStream = new FileInputStream(filePath);
InputStream fileInputStream = this.getClass().getResourceAsStream("/token.properties");
InputStream in = new BufferedInputStream(fileInputStream);
InputStreamReader inputStreamReader = new InputStreamReader(in, "UTF-8");
pps.load(inputStreamReader);
inputStreamReader.close();
in.close();
fileInputStream.close();
//true表示追加打开,false表示每次都是清空重写
OutputStream out = new FileOutputStream(filePath);
// 设置配置名称和值
pps.setProperty(parameterName, parameterValue);
// comments 等于配置文件的注释
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(out, "UTF-8");
pps.store(outputStreamWriter, "Update " + parameterName + " name");
out.flush();
outputStreamWriter.close();
out.close();
}
}
package org.springblade.founder.ztrxyj.utils;
import org.apache.commons.codec.binary.Base64;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
/**
* SHA1WithRSA-数字签名工具类
* Created by yangyang on 2022/04/27.
*/
public class RsaUtil {
//加密算法
public static final String SIGN_ALGORITHMS = "SHA1WithRSA";
//私钥
private static final String privateKey = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANF/IIsbi9+v5V0VlXeDWp3LlWNXf1gQ3EYjbdj4qMJJoVaLUv2T6fsQq4MTGO6h0HaPQPb80g2VXXgtwOBAGhTN5ifi8VLkHp8h+sU3/hmR2q3eyUeUEaX8t53leWQiI462O23bysectI5lmqzkL/68LTzSpu8z308XSWOFdXKVAgMBAAECgYA7qjIxjCndDjKLvT7xZ8aiFD46qcvJ4BtsGmEJn2Ao3WGGzW1YbQ0BhTDjxseeBxXg/lGpRj3ownZ5aMZ616bVa8xFdI9agmElnM78RhUgJNtOelY4yB3vMQmdpYxhA6Zp+Z10DCvKyxiostqrLw/zdSr8ZkmRof1DUMml5FZzYQJBAPe8zQsHqXeGSjvAEpPpBX87Wzc7/T6tObuOokxOrWfPmZFO7qy2rsdOkmn8LghIhzvOognoT6DiBhO4UIgJAMkCQQDYe9Kfju7JhbhE0SRh+1hSRRV8+6vRmpTIxJpy+AN3Oc6oeiQ6UE7/ZxyeZ0pDgmBZGJDBHoX1rIYrsuMmgrVtAkEA0YwHO88tTwZuAABFNoshtS71xtCdMsi/TqAlM7pQ/sAgu0IyrDCRwc/6FF/UZ/lBOhtcAFlaEVFdpox+wbIr0QJBAM9BJHF7ruKiMbs4m2Nu9ay11Q+2BlYCb0US7Gb7SJ4hatdjMEHf1vGvrvd8Hd4p+MHzwcoRxeBhToaRmeSpqLUCQFFTCNRlE/0Qo8hKLJlu8NpN00/VznTp+llGsSelmpOJ3QVWWoFR4egxfkvS5k+lU3Xwwu4ljXh7gLxPRfTprgk=";
//公钥
private static final String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDRfyCLG4vfr+VdFZV3g1qdy5VjV39YENxGI23Y+KjCSaFWi1L9k+n7EKuDExjuodB2j0D2/NINlV14LcDgQBoUzeYn4vFS5B6fIfrFN/4Zkdqt3slHlBGl/Led5XlkIiOOtjtt28rHnLSOZZqs5C/+vC080qbvM99PF0ljhXVylQIDAQAB";
/**
* 使用私钥给入参签名
* @param param 签名的数据
* @return 返回入参签名16进制字符串
* */
public static String sign(String param) {
try {
//获取privatekey
byte[] privateKeyByte = new Base64().decode(privateKey);
KeyFactory keyfactory = KeyFactory.getInstance("RSA");
PKCS8EncodedKeySpec encoderule = new PKCS8EncodedKeySpec(privateKeyByte);
PrivateKey key = keyfactory.generatePrivate(encoderule);
//用私钥给入参加签
Signature sign = Signature.getInstance(SIGN_ALGORITHMS);
sign.initSign(key);
sign.update(param.getBytes());
byte[] signature = sign.sign();
//将签名的入参转换成16进制字符串
return Base64.encodeBase64String(signature);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 用公钥验证签名
* @param param 入参
* @param signature 使用私钥签名的入参字符串
* @param publicKey 公钥
* @return 返回验证结果
* */
// public static boolean verifyRes(String param,String signature,String publicKey){
// try {
// //获取公钥
// KeyFactory keyFactory=KeyFactory.getInstance("RSA");
// byte[] publicKeyByte= new Base64().decode(publicKey);
// X509EncodedKeySpec encodeRule=new X509EncodedKeySpec(publicKeyByte);
// PublicKey key= keyFactory.generatePublic(encodeRule);
//
// //用获取到的公钥对 入参中未加签参数param入参中的加签之后的参数signature进行验签
// Signature sign=Signature.getInstance(SIGN_ALGORITHMS);
// sign.initVerify(key);
// sign.update(param.getBytes());
//
// //将16进制码转成字符数组
// byte[] hexByte = Base64.decodeBase64(signature);
// //验证签名
// return sign.verify(hexByte);
//
// } catch (Exception e) {
// e.printStackTrace();
// }
// return false;
// }
/**
* byte数组转换成十六进制字符串
* @param bytes byte数组
* @return 返回十六进制字符串
*/
private static String bytesToHexStr(byte[] bytes) {
StringBuffer stringBuffer = new StringBuffer("");
for (int i = 0; i < bytes.length; ++i) {
stringBuffer.append(Integer.toHexString(0x0100 + (bytes[i] & 0x00FF)).substring(1).toUpperCase());
}
return stringBuffer.toString();
}
/**
* 十六进制字符串转成byte数组
* @param hexStr 十六进制字符串
* @return 返回byte数组
* */
private static byte[] hexStrToBytes(String hexStr) {
byte[] bytes = new byte[hexStr.length() / 2];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) Integer.parseInt(hexStr.substring(2 * i, 2 * i + 2), 16);
}
return bytes;
}
public static void main(String[] args) {
String param = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI3NC4xMC4zMC4xNzQiLCJpc3MiOiJ0b2tlbi5idWlsZGVyIiwiaWF0IjoxNjUxMjIyOTcwfQ.WIbBf23zZ-KKpCbOX9z6qX0Tqzyanl_WBnvE8YWyle4.xingjdj";
String sign = sign(param);
System.out.println("签名后的参数>>>"+sign);
// System.out.println("验证结果>>>"+verifyRes(param,sign,publicKey));
}
}
package org.springblade.founder.ztrxyj.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springblade.common.tool.HttpUtil;
import org.springblade.founder.utils.HttpClient;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
import java.util.*;
/**
* @ClassName: HttpClient
* @Auther: yangyang
* @Description: java类作用描述
* @CreateDate: 2022-04-28
* @Version: 1.0
*/
@Component
public class TokenUtils {
private static Log logger = LogFactory.getLog(HttpClient.class);
private static RequestConfig requestConfig = null;
private static String tokenPath="token.properties";
static{
// 设置请求和传输超时时间
//setConnectTimeout:设置连接超时时间,单位毫秒。
//setSocketTimeout:请求获取数据的超时时间,单位毫秒。 如果访问一个接口,多少时间内无法返回数据,就直接放弃此次调用。
//setConnectionRequestTimeout:设置从connect Manager获取Connection 超时时间,单位毫秒
requestConfig = RequestConfig.custom().setSocketTimeout(120000).setConnectTimeout(120000).build();
try{
// ClassPathResource classPathResource = new ClassPathResource("token.properties");
// tokenPath= classPathResource.getFile().getPath();
}catch (Exception e){
e.printStackTrace();
}
}
// 云天token
public static String getYtgsToken(){
PropertieUtil propertieUtil=new PropertieUtil();
String result_token = "";
try{
//1 先比较已有token是否过期
long nowtime = new Date().getTime();
//获取绝对路径下的token属性文件
String token= propertieUtil.readTokenValue("token",tokenPath);;
String expiration =propertieUtil.readTokenValue("expiration",tokenPath);
if(StringUtils.isEmpty(token) || StringUtils.isEmpty(expiration)){
result_token=readeWriteYtToken(nowtime);
}else{
//token值已过期
if(nowtime > Long.valueOf(expiration)){
result_token=readeWriteYtToken(nowtime);
}else{
result_token = token;
}
}
}catch (Exception e){
e.printStackTrace();
logger.info(e.getMessage());
}
return result_token;
}
//读和写云天的token值
public static String readeWriteYtToken(long nowtime){
PropertieUtil propertieUtil=new PropertieUtil();
String result_token="";
//2 如果过期先获取新的token值
String Authorization =propertieUtil.readTokenValue("Authorization",tokenPath);
String ContentType =propertieUtil.readTokenValue("Content-Type",tokenPath);
Map headerMap=new HashMap();
headerMap.put("Authorization",Authorization);
headerMap.put("Content-Type",ContentType);
String username =propertieUtil.readTokenValue("username",tokenPath);
String password =propertieUtil.readTokenValue("password",tokenPath);
String grant_type =propertieUtil.readTokenValue("grant_type",tokenPath);
String scope =propertieUtil.readTokenValue("scope",tokenPath);
String client_secret=propertieUtil.readTokenValue("client_secret",tokenPath);
String client_id =propertieUtil.readTokenValue("client_id",tokenPath);
JSONObject object = new JSONObject();
object.put("username", username);
object.put("password", password);
object.put("grant_type", grant_type);
object.put("scope", scope);
object.put("client_secret", client_secret);
object.put("client_id", client_id);
String token_url =propertieUtil.readTokenValue("token_url",tokenPath);
try {
String resultString = HttpClient.doPostJson(token_url,headerMap,JSONObject.toJSONString(object));
if (!StringUtils.isEmpty(resultString)) {
JSONObject result=JSONObject.parseObject(resultString);
result_token = result.getString("access_token");
String expires_in = result.getString("expires_in");//有效时间段 单位为秒
String result_expiration = nowtime+Integer.parseInt(expires_in)*1000+"";
//写入新的token值和本次token的过期时间
propertieUtil.writeTokenProperties(tokenPath, "token", result_token);
propertieUtil.writeTokenProperties(tokenPath, "expiration", result_expiration);
}
}catch (Exception e){
e.printStackTrace();
logger.info(e.getMessage());
}
return result_token;
}
/**
* 将参数拼接为?key1=a&key2=b形式提交
* @param url
* @param headers
* @param jsonParam
* @return
*/
public static String doPostUrlEncodedFormEntity(String url, Map<String, String> headers, String jsonParam){
String resultString = "";
HttpPost httpPost = new HttpPost(url);
try{
//给httpPost请求设置header
if(null!=headers&&headers.size()>0){
for(String key:headers.keySet()){
httpPost.addHeader(key,headers.get(key));
}
}
// 设置参数解决中文乱码
if (null != jsonParam){
List<NameValuePair> paramList=new ArrayList<>();
Map<String, String> paramMap=(Map<String, String>) JSON.parse(jsonParam);
paramMap.forEach((key,value) -> paramList.add(new BasicNameValuePair(key,value)));
//模拟表单
UrlEncodedFormEntity entity=new UrlEncodedFormEntity(paramList);
entity.setContentEncoding("UTF-8");
httpPost.setEntity(entity);
}
// 设置请求和传输超时时间
httpPost.setConfig(requestConfig);
//创建客户端连接请求
CloseableHttpClient httpClient = HttpClients.createDefault();
// 发送请求
CloseableHttpResponse result = httpClient.execute(httpPost);
System.out.println("StatusCode===="+result.getStatusLine().getStatusCode());
if (result.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
// 读取服务器返回的json数据(然后解析)
resultString = EntityUtils.toString(result.getEntity(), "utf-8");
}
}catch (Exception e){
e.printStackTrace();
logger.info(e.getMessage());
}finally{
httpPost.releaseConnection();
}
return resultString;
}
// 海南凯亚token获取
public static String getHnKyToken(){
PropertieUtil propertieUtil=new PropertieUtil();
String result_token = "";
try{
//先比较已有token是否过期
long nowtime = new Date().getTime();
//获取绝对路径下的token属性文件
String token= propertieUtil.readTokenValue("tokenKy",tokenPath);;
String expiration =propertieUtil.readTokenValue("expirationKy",tokenPath);
System.out.println("tokenPath-----"+tokenPath);
System.out.println("expirationKy-----"+expiration);
if(StringUtils.isEmpty(token) || StringUtils.isEmpty(expiration)){
result_token=readeWriteHnKyToken(nowtime);
}else{
//token值已过期
if(nowtime > Long.valueOf(expiration)){
result_token=readeWriteHnKyToken(nowtime);
}else{
result_token = token;
}
}
}catch (Exception e){
e.printStackTrace();
logger.info(e.getMessage());
}
return result_token;
}
// 海南凯亚token获取
public static String getHnKyTokencc(String token){
PropertieUtil propertieUtil=new PropertieUtil();
String result_token = "";
try{
//先比较已有token是否过期
long nowtime = new Date().getTime();
//获取绝对路径下的token属性文件
// String token= propertieUtil.readTokenValue("tokenKy",tokenPath);;
String expiration =propertieUtil.readTokenValue("expirationKy",tokenPath);
System.out.println("tokenPath-----"+tokenPath);
System.out.println("expirationKy-----"+expiration);
if(StringUtils.isEmpty(token) || StringUtils.isEmpty(expiration)){
result_token=readeWriteHnKyToken(nowtime);
}else{
//token值已过期
if(nowtime > Long.valueOf(expiration)){
result_token=readeWriteHnKyToken(nowtime);
}else{
result_token = token;
}
}
}catch (Exception e){
e.printStackTrace();
logger.info(e.getMessage());
}
return result_token;
}
//读和写海南凯亚的token值
public static String readeWriteHnKyToken(long nowtime){
PropertieUtil propertieUtil=new PropertieUtil();
String result_token="";
//如果过期先获取新的token值
Map headerMap=new HashMap();
headerMap.put("login-channel","API");
String username =propertieUtil.readTokenValue("usernameKy",tokenPath);
String token_url =propertieUtil.readTokenValue("token_urlKy",tokenPath);
System.out.println("读写字段名1"+username);
String clientUid = getClientUid(token_url);// 随机码
System.out.println("随机码+"+clientUid);
String password =RsaUtil.sign(clientUid+"."+username);// 随机码+“.”+用户名 RSA私钥进行SHA1WithRSA数字签名
JSONObject object = new JSONObject();
object.put("username", username);
object.put("password", password);
object.put("clientUid", clientUid);
try {
String resultString = HttpClient.doPostJson(token_url+"/auth/login",headerMap,JSONObject.toJSONString(object));
if (!StringUtils.isEmpty(resultString)) {
JSONObject result=JSONObject.parseObject(resultString);
System.out.println("=====jjjj==="+result.toJSONString());
if(result.getInteger("code")==200){
JSONObject resultData=result.getJSONObject("data");
result_token = resultData.getString("authorization");
String expires_in = resultData.getString("expireTime");//有效时间段 单位为秒 1800秒
String result_expiration = nowtime+Integer.parseInt(expires_in)*1000+"";
//写入新的token值和本次token的过期时间
System.out.println("====="+result_token);
propertieUtil.writeTokenProperties(tokenPath, "tokenKy", result_token);
propertieUtil.writeTokenProperties(tokenPath, "expirationKy", result_expiration);
}else{
return result.getString("msg");
}
}
}catch (Exception e){
e.printStackTrace();
logger.info("获取token错误"+e.getMessage());
}
return result_token;
}
// 获取海南凯亚的clientUid
public static String getClientUid(String token_url){
JSONObject jsonObject = JSONObject.parseObject(HttpUtil.doGet(token_url+"/auth/getClientUid"));
return jsonObject.getString("clientUid");
}
}
......@@ -123,7 +123,7 @@ public class AuthController {
if (StringUtils.isNotEmpty(username)) {//用户名不为空时继续验证
SysNewUser user = new SysNewUser();
user.setUsername(username);
user.setTrueName(jsonObj.getString("realname"));
user.setTrueName(jsonObj.getString("trueName"));
user.setIdentitycard(jsonObj.getString("identitycard"));
user.setUnitcode(jsonObj.getString("unitcode"));
user.setUnitname(jsonObj.getString("unitname"));
......
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