Commit f961580b authored by 万建斌's avatar 万建斌

2019-10-16 bug修复

parent da0dd8c1
......@@ -116,7 +116,12 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</dependency>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.1</version>
</dependency>
</dependencies>
......
......@@ -3,17 +3,34 @@ package com.cesgroup.common.utils;
import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import com.cesgroup.common.utils.http.HttpClientHelper;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.MapUtils;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
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.HttpGet;
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.hibernate.validator.internal.util.privilegedactions.GetMethod;
import javax.crypto.Cipher;
import java.io.IOException;
import java.net.URI;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
/**
* @program: kyb-search
......@@ -32,6 +49,31 @@ public class RSAEncryptUtil {
private static String CHARSET = "UTF-8";
public static void main(String[] args) throws Exception {
List<String> list = new ArrayList<>();
String[] ids = {"CN201310641619.6","CN85108702","CN86105552","CN85102316","CN85100424","CN85107140","CN85105258","CN87104444","CN86106501","CN85104116"};
for (int i = 0; i< 10; i++) {
String id = ids[i];
// Thread thread = new Thread(new Runnable() {
// @Override
// public void run() {
// for (int i = 0; i< 10; i++) {
long before = new Date().getTime();
String result = test(id);
long after = new Date().getTime();
long pass = (after - before);
System.out.println("此次访问结果:" + result);
System.out.println("此次访问总耗时:" + pass + "ms");
list.add(pass + "ms");
System.out.println("此次访问总耗时:" + list);
// }
// }
// });
// thread.start();
}
}
public static String test(String id){
//生成公钥和私钥
Map keyMap = new HashMap();
keyMap.put("publicKey", "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCJLuCIAqbnO1eunvgp3vby+2s0RnpNq3OFNpIQqStuTVIbedulgS2mEPASi9k5eHlc5n7MlHZMxdNRlBzo81EVa7bVCdS9nw2kMPNJoKLUX0RA8NFIYpkXakocDwCl1J8kNWuN1dMwQOZ7JPZQJaer9aAY/tu2aVpJG+CKTbQHRQIDAQAB");
......@@ -45,12 +87,15 @@ public class RSAEncryptUtil {
System.out.println("随机生成的公钥为:" + MapUtils.getString(keyMap, "publicKey"));
System.out.println("随机生成的私钥为:" + MapUtils.getString(keyMap, "privateKey"));
String sign = "";
try {
/*
* 拼接待签名字符串 RSA2对应的函数
*/
Map map = new HashMap();
map.put("id", "CN85107777");
map.put("id", id);
String content = AlipaySignature.getSignCheckContentV2(map);
// String content = JSON.toJSONString(map);
......@@ -61,7 +106,7 @@ public class RSAEncryptUtil {
/*
* 对数据签名 RSA2对应的函数和密钥
*/
String sign = AlipaySignature.rsaSign(map, MapUtils.getString(keyMap, "privateKey"), CHARSET);
sign = AlipaySignature.rsaSign(map, MapUtils.getString(keyMap, "privateKey"), CHARSET);
// String sign = sign(content, MapUtils.getString(keyMap, "privateKey"));
System.out.println("原始sign:" + sign);
......@@ -82,6 +127,77 @@ public class RSAEncryptUtil {
e.printStackTrace();
}
String token = "eyJhbGciOiJIUzI1NiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAAAKtWyirJVLJSMrJU0lEqLk0CMY2M9QwNTPSMDI31zEyBwpmJJUpWhqbmhoZGpiZGRjpKqRUFEAEjQ0MLkEBpcWqRX2JuKqbuWgDU063KYQAAAA.vqKvfqvl5F-biOFWxK6l9bRRAse_SjTfp2xbXYS5j9A";
String uriString ="http://116.236.205.182:1195/v1/queryById";
HashMap<String, Object> header = new HashMap<String, Object>();
header.put("token", token);
header.put("Content-Type", "application/json");
header.put("Accept", "application/json");
header.put("Call-Source", "PC_SEPARATE");
HashMap<String, Object> paramMap = new HashMap<>();
paramMap.put("id", id);
paramMap.put("sign", sign);
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null;
String result = "";
try {
// 通过址默认配置创建一个httpClient实例
httpClient = HttpClients.createDefault();
// 创建httpGet远程连接实例
HttpPost httpGet = new HttpPost(uriString);
//设置参数
if (paramMap != null && paramMap.size() > 0) {
List<NameValuePair> params = new ArrayList<>();
for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
params.add(new BasicNameValuePair(entry.getKey(), URLEncoder.encode(entry.getValue().toString(), "UTF-8")));
}
String strParams = EntityUtils.toString(new UrlEncodedFormEntity(params));
// 防止多参数时,分隔符","被转义
String realParams = URLDecoder.decode(strParams, "UTF-8");
httpGet.setURI(new URI(httpGet.getURI().toString().indexOf("?") > 0 ? httpGet.getURI().toString() + "&" + realParams : httpGet.getURI().toString() + "?" + realParams));
}
// 设置头
if (header != null && header.size() > 0) {
for (Map.Entry<String, Object> entry : header.entrySet()) {
httpGet.addHeader(entry.getKey(), entry.getValue().toString());
}
}
// 设置配置请求参数
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000)// 连接主机服务超时时间
.setConnectionRequestTimeout(35000)// 请求超时时间
.setSocketTimeout(60000)// 数据读取超时时间
.build();
// 为httpGet实例设置配置
httpGet.setConfig(requestConfig);
// 执行get请求得到返回对象
response = httpClient.execute(httpGet);
// 通过返回对象获取返回数据
HttpEntity entity = response.getEntity();
// 通过EntityUtils中的toString方法将结果转换为字符串
result = EntityUtils.toString(entity);
} catch (Exception e) {
e.printStackTrace();
} finally {
// 关闭资源
if (null != response) {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != httpClient) {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
public static String sign(String content, String privateKey) {
......
package com.cesgroup.kingkong.web;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
......@@ -7,7 +10,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cesgroup.common.utils.RestAPIResult;
import com.cesgroup.kingkong.interceptor.RequiredPermission;
import com.cesgroup.kingkong.service.impl.QueryService;
......@@ -70,8 +72,33 @@ public class SearchContrllor {
result = queryService.queryArticleInfo(params);
}
panResult.setRespData(result);
panResult.setRespData(parseResult(result));
return panResult;
}
/**
* 整理返回信息
* @return
*/
private List<Map<String, Object>> parseResult(Map<String, Object> beforehand){
if(beforehand != null && beforehand.size() > 0){
List<Map<String, Object>> resultList = (List<Map<String, Object>>) beforehand.get("entry");
List<Map<String, Object>> result = new ArrayList<>();
for (Map<String, Object> map: resultList) {
Map<String, Object> temp = new HashMap<>();
temp.put("dc:creator", map.get("dc:creator"));
temp.put("subtypeDescription", map.get("subtypeDescription"));
temp.put("prism:publicationName", map.get("prism:publicationName"));
temp.put("prism:volume", map.get("prism:volume"));
temp.put("citedby-count", map.get("citedby-count"));
temp.put("prism:pageRange", map.get("prism:pageRange"));
temp.put("dc:title", map.get("dc:title"));
temp.put("prism:coverDisplayDate", map.get("prism:coverDisplayDate"));
result.add(temp);
}
return result;
}
return null;
}
}
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