Commit b0e5e30b by caojingji

对接新版的网安接口 修改为新的对接方式

parent 8efe25ec
......@@ -31,7 +31,7 @@ public enum ResultEnum {
TASK_SEND_ERROR(22,"任务发送失败!"),
REQUEST_URL_ERROR(23,"请求远程地址错误!"),
REQUEST_TOKEN_ERROR(24,"Token值请求失败!"),
RESULT_ERROR(55,"发生了未知错误!"),
DB_QUERYIMSIS(502,"数据库查询IMSI出错!"),
DB_QUERYERROR(501,"数据库查询出错!"),
......
......@@ -145,7 +145,8 @@ public class PushWaDataServiceImpl implements PushWaDataService {
param.put("startTime",kssjL);
param.put("endTime",jssjL);
param.put("objectValue",objectValue);
result = doPostWaData("trackTraveTogetherForPhoneTask",param.toJSONString());
param.put("objectType",objectType);
result = doPostWaData("trackTravelTogetherForPhoneTask",param.toJSONString());
}catch (Exception e){
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage());
}
......@@ -162,7 +163,7 @@ public class PushWaDataServiceImpl implements PushWaDataService {
public String getTogetherTaskInfo(String taskId) throws InterServiceException{
String result = null;
try{
String url = "trackTraveTogetherForPhoneTaskInfo/"+taskId;
String url = "trackTravelTogetherForPhoneTaskInfo/"+taskId;
result = doPostWaData(url,null);
}catch (Exception e){
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage());
......
......@@ -185,7 +185,6 @@ public class HttpClient {
HttpPost httpPost = new HttpPost(url);
// 设置请求和传输超时时间
httpPost.setConfig(requestConfig);
httpPost.setHeader(HTTP.CONTENT_TYPE,"application/json");
if(headers != null) {
for (String key : headers.keySet()) {
httpPost.setHeader(key, headers.get(key));
......@@ -194,7 +193,7 @@ public class HttpClient {
try{
//设置参数解决中文乱码
if (null != json){
StringEntity entity = new StringEntity(json, "utf-8");
StringEntity entity = new StringEntity(json,"utf-8");
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
httpPost.setEntity(entity);
......@@ -202,11 +201,12 @@ public class HttpClient {
//发送请求
CloseableHttpResponse result = httpClient.execute(httpPost);
if (result.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
String str = "";
// 读取服务器返回的json数据(然后解析)
jsonResult = EntityUtils.toString(result.getEntity(), "utf-8");
}else{
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage());
}
}catch (IOException e){
}catch (Exception e){
e.printStackTrace();
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage(),e);
}finally{
......@@ -234,16 +234,12 @@ public class HttpClient {
CloseableHttpResponse result = httpClient.execute(httpPost);
if (result.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
String str = "";
try{
// 读取服务器返回的json数据(然后解析)
str = EntityUtils.toString(result.getEntity(), "utf-8");
// 把json字符串转换成json对象
jsonResult = JSONObject.parseObject(str);
}catch (Exception e){
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage(),e);
}
// 读取服务器返回的json数据(然后解析)
str = EntityUtils.toString(result.getEntity(), "utf-8");
// 把json字符串转换成json对象
jsonResult = JSONObject.parseObject(str);
}
}catch (IOException e){
}catch (Exception e){
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage(),e);
}finally{
httpPost.releaseConnection();
......@@ -263,13 +259,14 @@ public class HttpClient {
try {
//1、获取并判断token是否过期,如果过期获取新的token值 并将其存储(一般情况下 token的有效期间为24小时)
result_token = getToken();
System.out.println("result_token============" + result_token);
//2 将token值传递
if(!StringUtil.ckeckEmpty(result_token)){
Map<String,String> headers = new HashMap<String,String>();
headers.put("Authorization",result_token);
return doPostJson(url,headers,json);
}else{
return null;
throw new InterServiceException(ResultEnum.REQUEST_TOKEN_ERROR.getCode(),ResultEnum.REQUEST_TOKEN_ERROR.getMessage());
}
} catch (Exception e) {
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage(),e);
......@@ -287,7 +284,7 @@ public class HttpClient {
long nowtime = new Date().getTime();
String token = PropertieUtil.readValue("token.properties","token");
String expiration = PropertieUtil.readValue("token.properties","expiration");
if(StringUtil.ckeckEmpty(token) || nowtime > Long.valueOf(expiration)){
if(StringUtil.ckeckEmpty(token) || StringUtil.ckeckEmpty(expiration)){
//2 如果过期先获取新的token值
String apiKey = PropertieUtil.readValue("token.properties","apiKey");
String username = PropertieUtil.readValue("token.properties","username");
......@@ -303,7 +300,23 @@ public class HttpClient {
PropertieUtil.writeProperties("token.properties","expiration",result_expiration);
}
}else{
result_token = token;
if(nowtime > Long.valueOf(expiration)){
String apiKey = PropertieUtil.readValue("token.properties","apiKey");
String username = PropertieUtil.readValue("token.properties","username");
String token_url = PropertieUtil.readValue("token.properties","token_url");
JSONObject object = new JSONObject();
object.put("apiKey", apiKey);
object.put("username", username);
JSONObject result = doPostJson(token_url,object);
if(null != result){
result_token = result.getString("token");
String result_expiration = result.getString("expiration");
PropertieUtil.writeProperties("token.properties","token",result_token);
PropertieUtil.writeProperties("token.properties","expiration",result_expiration);
}
}else{
result_token = token;
}
}
}catch (Exception e){
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage(),e);
......
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