Commit c7b031bb authored by 赵啸非's avatar 赵啸非

添加水印图片

parent f8bc1077
...@@ -123,11 +123,11 @@ public class TestSendMsgController { ...@@ -123,11 +123,11 @@ public class TestSendMsgController {
@GetMapping("subtree") @GetMapping("subtree")
public Rest<Void> subtree(Long parentId) { public Rest<Object> subtree(Long parentId) {
// List<CertificateIndustryTreeSelect> allListByParentId = certificateIndustryService.getAllListByParentId(parentId, null) List<CertificateIndustryTreeSelect> allListByParentList = certificateIndustryService.getAllListByParentId(parentId, null);
return Rest.ok(); return Rest.ok(allListByParentList);
} }
public static void main(String[] args) { public static void main(String[] args) {
......
...@@ -42,88 +42,6 @@ public class CertificateIndustryController extends BaseCRUDJsonBodyMappingContro ...@@ -42,88 +42,6 @@ public class CertificateIndustryController extends BaseCRUDJsonBodyMappingContro
super.init(model, context); super.init(model, context);
} }
@Override
@DataPermission
public Rest<Object> list(CertificateIndustryEntity query) {
return super.list(query);
}
@PostMapping({"treeList"})
@UnAuth
public Rest<Object> treeList(@RequestBody CertificateIndustryEntity query) {
Rest<Object> ret = new Rest();
Map<String, Object> model = new HashMap();
Context context = this.getContext();
String busiDesc = "查询" + this.getModuleDesc();
int code;
try {
List<CertificateIndustryEntity> result = this.getService().find(query, context);
if (CollectionUtils.isNotEmpty(result)) {
List<CertificateIndustryEntity> collect = result.stream().filter(t -> t.getParentId() == -1).map(
m -> {
m.setChildren(getChildren(m, result));
return m;
}
).collect(Collectors.toList());
model.put("data", collect);
} else {
model.put("data", result);
}
code = this.doListAfter(query, (Map) model, context);
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception var9) {
code = -1;
this.doException(this.request, busiDesc, model, var9);
}
this.init(model, context);
ret.setCode(code);
ret.setData(model);
ret.setDict(model.get("dict"));
ret.setMsg(model.get("message_info") == null ? "" : model.remove("message_info").toString());
return ret;
}
private List<CertificateIndustryEntity> getChildren(CertificateIndustryEntity root, List<CertificateIndustryEntity> all) {
List<CertificateIndustryEntity> children = all.stream().filter(t -> {
return Objects.equals(t.getParentId(), root.getId());
}).map(
m -> {
m.setChildren(getChildren(m, all));
return m;
}
).collect(Collectors.toList());
return children;
}
@PostMapping("list/exclude")
public String excludeList(CertificateIndustryEntity query) {
Map<String, Object> model = new HashMap<>();
JSONObject ret = new JSONObject();
String busiDesc = "查询" + this.getModuleDesc();
Long id = query.getId();
int code=VALUE_RESULT_SUCCESS;
try {
Set<Long> idSet = new HashSet<>();
idSet.add(query.getId());
List<CertificateIndustryEntity> collect = this.service.find(new CertificateIndustryQuery()).stream().map(item -> {
if(idSet.contains(item.getId())) return null;
return item;
}).filter(f -> f != null).collect(Collectors.toList());
model.put("result", collect);
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
code = VALUE_RESULT_FAILURE;
this.doException(request, busiDesc, model, e);
}
ret.put(KEY_RESULT_DATA, model);
ret.put(KEY_RESULT_CODE, code);
return ret.toJSONString();
}
/** /**
* 获取站点下拉树列表 * 获取站点下拉树列表
*/ */
......
import java.util.Arrays;
import java.util.Map;
public class ParamUtil {
public static String sort(Map<String, String> params, String[] args) {
Arrays.sort(args);
StringBuffer paramStr = new StringBuffer();
for (String s : args) {
if (paramStr.length() >= 1) {
paramStr.append("&");
}
paramStr.append(s).append("=").append(params.get(s));
}
return paramStr.toString();
}
}
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import javax.crypto.Cipher;
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* RSA签名算法工具
*
* @author WuBin
*
*/
public class RsaUtil {
private static Logger logger = LoggerFactory.getLogger(RsaUtil.class);
/**
* RSA最大加密明文大小
*/
private static final int MAX_ENCRYPT_BLOCK = 117;
/**
* RSA最大解密密文大小
*/
private static final int MAX_DECRYPT_BLOCK = 128;
/**
* 转换私钥
*
* @param key
* 私钥字符
* @return 私钥
*/
public static PrivateKey parsePrivateKey(String key) {
try {
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(
Base64.decodeBase64(key));
KeyFactory kf = KeyFactory.getInstance("RSA");
return kf.generatePrivate(keySpec);
} catch (Exception e) {
throw new RuntimeException("转换私钥失败", e);
}
}
/**
* 转换私钥
*
* @param is
* 私钥文件流
* @return 私钥
*/
public static PrivateKey parsePrivateKey(InputStream is) {
try {
byte[] encodedKey = new byte[is.available()];
is.read(encodedKey);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encodedKey);
KeyFactory kf = KeyFactory.getInstance("RSA");
return kf.generatePrivate(keySpec);
} catch (Exception e) {
throw new RuntimeException("转换私钥失败", e);
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
logger.error("关闭文件流失败", e);
}
}
}
/**
* 签名Sha1WithRSA
*
* @param privateKey
* 私钥
* @param data
* 待签名数据
* @return 签名数据
*/
public static byte[] sign(PrivateKey privateKey, byte[]... data) {
return sign(privateKey, "Sha1WithRSA", data);
}
/**
* 签名Sha256WithRSA
*
* @param privateKey
* 私钥
* @param data
* 待签名数据
* @return 签名数据
*/
public static byte[] sign256(PrivateKey privateKey, byte[]... data) {
return sign(privateKey, "Sha256WithRSA", data);
}
/**
* 签名
*
* @param privateKey
* 私钥
* @param algorithm
* 签名算法
* @param data
* 待签名数据
* @return 签名数据
*/
public static byte[] sign(PrivateKey privateKey, String algorithm,
byte[]... data) {
try {
Signature signObject = Signature.getInstance(algorithm);
signObject.initSign(privateKey);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (byte[] sub : data) {
if (sub != null) {
baos.write(sub);
}
}
signObject.update(baos.toByteArray());
return signObject.sign();
} catch (Exception e) {
throw new RuntimeException("签名失败", e);
}
}
/**
* 解密
*
* @param privateKey
* 私钥
* @param data
* 待解密数据
* @return 解密数据
*/
public static byte[] decrypt(PrivateKey privateKey, byte[]... data) {
try {
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, privateKey);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (byte[] sub : data) {
if (sub != null) {
baos.write(sub);
}
}
byte[] encryptedData = baos.toByteArray();
int inputLen = baos.toByteArray().length;
ByteArrayOutputStream out = new ByteArrayOutputStream();
int offSet = 0;
byte[] cache;
int i = 0;
while (inputLen - offSet > 0) {
if (inputLen - offSet > MAX_DECRYPT_BLOCK) {
cache = cipher.doFinal(encryptedData, offSet,
MAX_DECRYPT_BLOCK);
} else {
cache = cipher.doFinal(encryptedData, offSet, inputLen
- offSet);
}
out.write(cache, 0, cache.length);
i++;
offSet = i * MAX_DECRYPT_BLOCK;
}
return out.toByteArray();
} catch (Exception e) {
throw new RuntimeException("解密失败", e);
}
}
/**
* 转换公钥
*
* @param key
* 公钥字符
* @return 公钥
*/
public static PublicKey parsePublicKey(String key) {
try {
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(
Base64.decodeBase64(key));
KeyFactory kf = KeyFactory.getInstance("RSA");
return kf.generatePublic(keySpec);
} catch (Exception e) {
throw new RuntimeException("转换公钥失败", e);
}
}
/**
* 验签Sha1WithRSA
*
* @param publicKey
* 公钥
* @param sign
* 签名
* @param data
* 待验签数据
* @return 是否通过
*/
public static boolean verify(PublicKey publicKey, byte[] sign,
byte[]... data) {
return verify(publicKey, "Sha1WithRSA", sign, data);
}
/**
* 验签Sha256WithRSA
*
* @param publicKey
* 公钥
* @param sign
* 签名
* @param data
* 待验签数据
* @return 是否通过
*/
public static boolean verify256(PublicKey publicKey, byte[] sign,
byte[]... data) {
return verify(publicKey, "Sha256WithRSA", sign, data);
}
/**
* 验签
*
* @param publicKey
* 公钥
* @param algorithm
* 签名算法
* @param sign
* 签名
* @param data
* 待验签数据
* @return 是否通过
*/
public static boolean verify(PublicKey publicKey, String algorithm,
byte[] sign, byte[]... data) {
try {
Signature signObject = Signature.getInstance(algorithm);
signObject.initVerify(publicKey);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (byte[] sub : data) {
if (sub != null) {
baos.write(sub);
}
}
signObject.update(baos.toByteArray());
return signObject.verify(sign);
} catch (Exception e) {
throw new RuntimeException("验签失败", e);
}
}
/**
* 加密
*
* @param publicKey
* 公钥
* @param data
* 待加密数据
* @return 加密数据
*/
public static byte[] encrypt(PublicKey publicKey, byte[]... data) {
try {
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (byte[] sub : data) {
if (sub != null) {
baos.write(sub);
}
}
byte[] originalData = baos.toByteArray();
int inputLen = baos.toByteArray().length;
ByteArrayOutputStream out = new ByteArrayOutputStream();
int offSet = 0;
byte[] cache;
int i = 0;
while (inputLen - offSet > 0) {
if (inputLen - offSet > MAX_ENCRYPT_BLOCK) {
cache = cipher.doFinal(originalData, offSet,
MAX_ENCRYPT_BLOCK);
} else {
cache = cipher.doFinal(originalData, offSet, inputLen
- offSet);
}
out.write(cache, 0, cache.length);
i++;
offSet = i * MAX_ENCRYPT_BLOCK;
}
return out.toByteArray();
} catch (Exception e) {
throw new RuntimeException("加密失败", e);
}
}
}
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
public class ZjptTest {
/**
*
* 接口访问地址
*/
public static final String URL= "http://103.203.218.240:8003/ScrsGgfwService/inf/api.do";
/**
* 编码格式
*/
public static final String ENCODING = "UTF-8";
/**
* 服务端公钥
*/
public static final String SERVER_PUBLICKEY="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC6Yp7i1otL0vowUTrFpCbrTXKy09L6zp4VpNWsCsU4daddfGzkCA5nr/7rt5to77qXx0cEGafqCMNHe9ru4cDjbmjq6MUFzlRB0ezI8RXs1MiewGh3nRPufdKid8uPzWGo4VAGZkv2keum+GT2W5OVBnaHiZMtLQiaSMXXHNwcawIDAQAB";
/**
* 客户端私钥
*/
public static final String CLIENT_PRIKEY = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAMC2J7I7udTnJdWwarWYpdG6BEVl8YV4iTmSKAjah0/673HtgXjzwJEf7gjVYE2Rf+fOTUX6zUQZXkI6hlt+B8GlgeJGFdMUcAAbqF5gqsB5X6/NBwq1SQF5mpTSeQSHRgMRnGAayCNWohgE9mnnyKcGYQK9iPoI71+MGHL34+x1AgMBAAECgYEAtspQ3uN+Ae76WTWMEhHnfwY1VOo8bACIEP6MUNGPNZLsmiDRBTwXtNAXhXN3dDwFmYd6jl01ZFm3qZQ/qvrhOOx4EMNgO6C7qUd4OhDtarEC0Brg5awjuMCDBd25t/cJg7GgFv5ccGYwz9K96AhCVj/Zsd55eXDH2TH+9baPpwECQQDfmgn1lzycwBaHEGJhLZ2wBVWkhMqZ/F0LPcjWVIwoook55ihaXqPw33GiF2JMUPfOSsfIRapXdUaXcdbaTXRBAkEA3KJSCurcBz0FzluQYFWsNZPJzuR724cAeNcSsQHsgQtRTnpEOlikj8xRxoEKdNdipPfiaF+kCpK4Z6z/lJgbNQJBANQPOObL2dYnbrYFWegj5OrtBD4VGjhT2MIyhGiQoqRfEZnxp8+c9goZP6GkX7tVBs+EqFhNibGMLbivZD6BOoECQGmV2JNW77MbFeM6WG5xsXb2YdZ763YUNjqeGljRJeBfjSp0QqB1eVNDoULQ0DM4PAHciuIOGw/gRRWAadMvs50CQQCCXRywZhSvVTuWnj6Wy3D77wac4ckLVahIMahNoy/UNqdoCEnO168C7m9BpwUjnb+ipGx6/nhY9BZAogfWygV1";
public static String HttpPostWithJson(String url, String json) {
String returnValue = "这是默认返回值,接口调用失败";
CloseableHttpClient httpClient = HttpClients.createDefault();
ResponseHandler<String> responseHandler = new BasicResponseHandler();
try{
//第一步:创建HttpClient对象
httpClient = HttpClients.createDefault();
//第二步:创建httpPost对象
HttpPost httpPost = new HttpPost(url);
//第三步:给httpPost设置JSON格式的参数
StringEntity requestEntity = new StringEntity(json,"utf-8");
requestEntity.setContentEncoding("UTF-8");
httpPost.setHeader("Content-type", "application/json");
httpPost.setEntity(requestEntity);
//第四步:发送HttpPost请求,获取返回值
returnValue = httpClient.execute(httpPost,responseHandler); //调接口获取返回值时,必须用此方法
}
catch(Exception e){
e.printStackTrace();
}finally {
try {
httpClient.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//第五步:处理返回值
return returnValue;
}
/**
*
* @Title: sentPOST
* @Description: 处理参数及发起请求
* @param @param method
* @param @param params
* @param @return 参数
* @return String 返回类型
* @throws
*/
public static String sentPOST(String method,String params){
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd/HHmmss/");
Map<String, String> map = new HashMap<String, String>();
//公共参数
map.put("sysCode", "CdsbPdjhXt"); //系统编号
map.put("channelName", "成都社保排队叫号系统"); //渠道
map.put("callCode", "I01046"); //系统代码
map.put("method", method); //方法
map.put("identityFlag", "3");
map.put("timestamp", sdf.format(new Date()));//时间格式"yyyyMMdd/HHmmss/"
map.put("params", params);
try {
//加签
String[] args = new String[] {"sysCode", "channelName", "method", "timestamp", "params", "identityFlag"};
String paramStr = ParamUtil.sort(map, args);
byte[] signByte = RsaUtil.sign(RsaUtil.parsePrivateKey(CLIENT_PRIKEY), paramStr.getBytes(ENCODING));
String signStr = Base64.encodeBase64String(signByte);
map.put("sign", signStr);
//转为json格式
//JSONObject jsonObject = JSONObject.(map);
//发起http请求
String returnValue = HttpPostWithJson(URL, JSONObject.toJSONString(map));
return returnValue;
}catch(Exception e ){
e.printStackTrace();
return null;
}
}
/**
*
* @Title: main
* @Description: test
* @param @param args
* @param @throws Exception 参数
* @return void 返回类型
* @throws
*/
public static void main(String[] args) throws Exception {
//请求参数
Map<String, Object> map = new HashMap<String, Object>();
//接口参数
map.put("sfz","511181198903042414");
map.put("dwbm","1212");
JSONObject jsonObject = new JSONObject();
jsonObject.put("id","");
jsonObject.put("name","社保综合业务");
jsonObject.put("describe","社保综合业务,综合A,B业务");
map.put("type",jsonObject);
//JSONObject jsonObject = JSONObject.fromObject(map);
String p =JSONObject.toJSONString(map);
//参数加密
String encStr = Base64.encodeBase64String(RsaUtil.encrypt(RsaUtil.parsePublicKey(SERVER_PUBLICKEY), p.getBytes()));
System.out.println("加密后的字符串为:" + encStr);
String returnValue = sentPOST("接口名",encStr);
//返回数据
System.out.println(returnValue);
}
}
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