|
@ -3,6 +3,7 @@ package com.epmet.service.impl; |
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
|
|
import com.epmet.commons.tools.redis.RedisUtils; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.dto.result.WzmDocumentRsultDTO; |
|
|
import com.epmet.dto.result.WzmDocumentRsultDTO; |
|
|
import com.epmet.dto.result.WzmProjectResultDTO; |
|
|
import com.epmet.dto.result.WzmProjectResultDTO; |
|
@ -18,7 +19,9 @@ import org.apache.http.impl.client.CloseableHttpClient; |
|
|
import org.apache.http.impl.client.HttpClients; |
|
|
import org.apache.http.impl.client.HttpClients; |
|
|
import org.apache.http.util.EntityUtils; |
|
|
import org.apache.http.util.EntityUtils; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.nio.charset.Charset; |
|
|
import java.nio.charset.Charset; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
@ -35,9 +38,21 @@ import java.util.Map; |
|
|
@Service |
|
|
@Service |
|
|
public class ActWithoutProofServiceImpl implements ActWithoutProofService { |
|
|
public class ActWithoutProofServiceImpl implements ActWithoutProofService { |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
private RedisUtils redisUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public List<WzmProjectResultDTO> getZmTasks(Map<String, Object> param) throws IOException { |
|
|
public List<WzmProjectResultDTO> getZmTasks(Map<String, Object> param) throws IOException { |
|
|
|
|
|
|
|
|
|
|
|
String listKey = "WITHOUT_PROOF_LIST"; |
|
|
|
|
|
|
|
|
|
|
|
List<WzmProjectResultDTO> list = (List<WzmProjectResultDTO>) redisUtils.get(listKey); |
|
|
|
|
|
|
|
|
|
|
|
if(!ObjectUtils.isEmpty(list)) { |
|
|
|
|
|
return list; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
CloseableHttpClient client = null; |
|
|
CloseableHttpClient client = null; |
|
|
CloseableHttpResponse response = null; |
|
|
CloseableHttpResponse response = null; |
|
|
try { |
|
|
try { |
|
@ -64,7 +79,7 @@ public class ActWithoutProofServiceImpl implements ActWithoutProofService { |
|
|
post.setHeader("appKey", ActWithoutProofUtils.APP_KEY); |
|
|
post.setHeader("appKey", ActWithoutProofUtils.APP_KEY); |
|
|
post.setHeader("Content-Type", "application/json"); |
|
|
post.setHeader("Content-Type", "application/json"); |
|
|
params = new JSONObject(); |
|
|
params = new JSONObject(); |
|
|
params.put("token", param.get("token")); |
|
|
params.put("token", getToken(false)); |
|
|
params.put("params", baseEncode); |
|
|
params.put("params", baseEncode); |
|
|
post.setEntity(new StringEntity(params.toString(), Charset.forName("UTF-8"))); |
|
|
post.setEntity(new StringEntity(params.toString(), Charset.forName("UTF-8"))); |
|
|
response = client.execute(post); |
|
|
response = client.execute(post); |
|
@ -72,6 +87,9 @@ public class ActWithoutProofServiceImpl implements ActWithoutProofService { |
|
|
JSONObject result = JSONObject.parseObject(EntityUtils.toString(response.getEntity())); |
|
|
JSONObject result = JSONObject.parseObject(EntityUtils.toString(response.getEntity())); |
|
|
List<WzmProjectResultDTO> resultList = new ArrayList<>(); |
|
|
List<WzmProjectResultDTO> resultList = new ArrayList<>(); |
|
|
if (result.getString("code").equals("200")) { |
|
|
if (result.getString("code").equals("200")) { |
|
|
|
|
|
if(isTokenExpire(result)) { |
|
|
|
|
|
getToken(true); |
|
|
|
|
|
} else { |
|
|
JSONArray jsonArray = JSONObject.parseObject(result.getJSONObject("data").getString("custom")).getJSONArray("result"); |
|
|
JSONArray jsonArray = JSONObject.parseObject(result.getJSONObject("data").getString("custom")).getJSONArray("result"); |
|
|
if (null != jsonArray && jsonArray.size() > 0) { |
|
|
if (null != jsonArray && jsonArray.size() > 0) { |
|
|
for (Object data : jsonArray) { |
|
|
for (Object data : jsonArray) { |
|
@ -84,7 +102,10 @@ public class ActWithoutProofServiceImpl implements ActWithoutProofService { |
|
|
resultList.add(dto); |
|
|
resultList.add(dto); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
redisUtils.set(listKey, resultList); |
|
|
|
|
|
} |
|
|
log.info(result.toString()); |
|
|
log.info(result.toString()); |
|
|
|
|
|
|
|
|
return resultList; |
|
|
return resultList; |
|
|
} else { |
|
|
} else { |
|
|
String erro = JSONObject.parseObject(result.getJSONObject("data").getString("custom")).getString("text"); |
|
|
String erro = JSONObject.parseObject(result.getJSONObject("data").getString("custom")).getString("text"); |
|
@ -102,7 +123,8 @@ public class ActWithoutProofServiceImpl implements ActWithoutProofService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public List<WzmDocumentRsultDTO> getWzmProject(String token, String idCard, String certType, String qrcode, String xm, String zmtaskguid) throws IOException { |
|
|
public List<WzmDocumentRsultDTO> getWzmProject(String idCard, String certType, String qrcode, String xm, String zmtaskguid) throws IOException { |
|
|
|
|
|
|
|
|
CloseableHttpClient client = null; |
|
|
CloseableHttpClient client = null; |
|
|
CloseableHttpResponse response = null; |
|
|
CloseableHttpResponse response = null; |
|
|
try { |
|
|
try { |
|
@ -137,7 +159,7 @@ public class ActWithoutProofServiceImpl implements ActWithoutProofService { |
|
|
post.setHeader("Content-Type", "application/json"); |
|
|
post.setHeader("Content-Type", "application/json"); |
|
|
post.setHeader("Accept-Encoding", "deflate/br"); |
|
|
post.setHeader("Accept-Encoding", "deflate/br"); |
|
|
params = new JSONObject(); |
|
|
params = new JSONObject(); |
|
|
params.put("token", token); |
|
|
params.put("token", getToken(false)); |
|
|
params.put("params", baseEncode); |
|
|
params.put("params", baseEncode); |
|
|
post.setEntity(new StringEntity(params.toString(), Charset.forName("UTF-8"))); |
|
|
post.setEntity(new StringEntity(params.toString(), Charset.forName("UTF-8"))); |
|
|
response = client.execute(post); |
|
|
response = client.execute(post); |
|
@ -146,12 +168,15 @@ public class ActWithoutProofServiceImpl implements ActWithoutProofService { |
|
|
WzmDocumentRsultDTO dto = null; |
|
|
WzmDocumentRsultDTO dto = null; |
|
|
List<WzmDocumentRsultDTO> dtoList= new ArrayList<>(); |
|
|
List<WzmDocumentRsultDTO> dtoList= new ArrayList<>(); |
|
|
if (result.getString("code").equals("200")) { |
|
|
if (result.getString("code").equals("200")) { |
|
|
|
|
|
if(isTokenExpire(result)) { |
|
|
|
|
|
getToken(true); |
|
|
|
|
|
} else { |
|
|
JSONArray jsonArray = JSONObject.parseObject(result.getJSONObject("data").getString("custom")).getJSONArray("resultlist"); |
|
|
JSONArray jsonArray = JSONObject.parseObject(result.getJSONObject("data").getString("custom")).getJSONArray("resultlist"); |
|
|
if (null != jsonArray && jsonArray.size() > 0) { |
|
|
if (null != jsonArray && jsonArray.size() > 0) { |
|
|
JSONObject j = JSONObject.parseObject(jsonArray.get(0).toString()); |
|
|
JSONObject j = JSONObject.parseObject(jsonArray.get(0).toString()); |
|
|
dto = new WzmDocumentRsultDTO(); |
|
|
dto = new WzmDocumentRsultDTO(); |
|
|
dto.setZmresultname(j.getString("zmresultname")); |
|
|
dto.setZmresultname(j.getString("zmresultname")); |
|
|
if(StringUtils.isNotEmpty(j.getString("downloadurl"))){ |
|
|
if (StringUtils.isNotEmpty(j.getString("downloadurl"))) { |
|
|
String url = j.getString("downloadurl"); |
|
|
String url = j.getString("downloadurl"); |
|
|
if (url.startsWith("http://172.20.84.138/")) { |
|
|
if (url.startsWith("http://172.20.84.138/")) { |
|
|
url = url.replaceAll("http://172.20.84.138/", "https://rzzhsq.shuzirizhao.cn/"); |
|
|
url = url.replaceAll("http://172.20.84.138/", "https://rzzhsq.shuzirizhao.cn/"); |
|
@ -159,11 +184,12 @@ public class ActWithoutProofServiceImpl implements ActWithoutProofService { |
|
|
dto.setDownloadurl(url); |
|
|
dto.setDownloadurl(url); |
|
|
} |
|
|
} |
|
|
dto.setTimeqrcode(j.getString("timeqrcode")); |
|
|
dto.setTimeqrcode(j.getString("timeqrcode")); |
|
|
if(StringUtils.isNotEmpty(j.getString("base64str"))){ |
|
|
if (StringUtils.isNotEmpty(j.getString("base64str"))) { |
|
|
dto.setBase64str("data:image/jpeg;base64," + j.getString("base64str")); |
|
|
dto.setBase64str("data:image/jpeg;base64," + j.getString("base64str")); |
|
|
} |
|
|
} |
|
|
dtoList.add(dto); |
|
|
dtoList.add(dto); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
return dtoList; |
|
|
return dtoList; |
|
|
} else { |
|
|
} else { |
|
|
String erro = JSONObject.parseObject(result.getJSONObject("data").getString("custom")).getString("text"); |
|
|
String erro = JSONObject.parseObject(result.getJSONObject("data").getString("custom")).getString("text"); |
|
@ -181,7 +207,7 @@ public class ActWithoutProofServiceImpl implements ActWithoutProofService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Result redealProject(String token, String idCard, String zmtaskguid) throws IOException { |
|
|
public Result redealProject(String idCard, String zmtaskguid) throws IOException { |
|
|
CloseableHttpClient client = null; |
|
|
CloseableHttpClient client = null; |
|
|
CloseableHttpResponse response = null; |
|
|
CloseableHttpResponse response = null; |
|
|
try { |
|
|
try { |
|
@ -205,15 +231,20 @@ public class ActWithoutProofServiceImpl implements ActWithoutProofService { |
|
|
post.setHeader("appKey", ActWithoutProofUtils.APP_KEY); |
|
|
post.setHeader("appKey", ActWithoutProofUtils.APP_KEY); |
|
|
post.setHeader("Content-Type", "application/json"); |
|
|
post.setHeader("Content-Type", "application/json"); |
|
|
params = new JSONObject(); |
|
|
params = new JSONObject(); |
|
|
params.put("token", token); |
|
|
params.put("token", getToken(false)); |
|
|
params.put("params", baseEncode); |
|
|
params.put("params", baseEncode); |
|
|
post.setEntity(new StringEntity(params.toString(), Charset.forName("UTF-8"))); |
|
|
post.setEntity(new StringEntity(params.toString(), Charset.forName("UTF-8"))); |
|
|
response = client.execute(post); |
|
|
response = client.execute(post); |
|
|
//返回
|
|
|
//返回
|
|
|
JSONObject result = JSONObject.parseObject(EntityUtils.toString(response.getEntity())); |
|
|
JSONObject result = JSONObject.parseObject(EntityUtils.toString(response.getEntity())); |
|
|
if (result.getString("code").equals("200")) { |
|
|
if (result.getString("code").equals("200")) { |
|
|
|
|
|
if(isTokenExpire(result)) { |
|
|
|
|
|
getToken(true); |
|
|
|
|
|
return new Result().error("API调用失败,请重试"); |
|
|
|
|
|
} else { |
|
|
JSONObject json = JSONObject.parseObject(result.getJSONObject("data").getString("custom")); |
|
|
JSONObject json = JSONObject.parseObject(result.getJSONObject("data").getString("custom")); |
|
|
return new Result().ok(json.getString("text")); |
|
|
return new Result().ok(json.getString("text")); |
|
|
|
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
JSONObject json = JSONObject.parseObject(result.getJSONObject("data").getString("custom")); |
|
|
JSONObject json = JSONObject.parseObject(result.getJSONObject("data").getString("custom")); |
|
|
return new Result().error(-1, json.getString("text")); |
|
|
return new Result().error(-1, json.getString("text")); |
|
@ -227,4 +258,72 @@ public class ActWithoutProofServiceImpl implements ActWithoutProofService { |
|
|
response.close(); |
|
|
response.close(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public String getToken(Boolean refresh) throws IOException { |
|
|
|
|
|
String tokenKey = "WITHOUT_PROOF_TOKEN"; |
|
|
|
|
|
String token = null; |
|
|
|
|
|
|
|
|
|
|
|
if(refresh) { |
|
|
|
|
|
token = getTokenAndRefresh(tokenKey); |
|
|
|
|
|
} else { |
|
|
|
|
|
token = (String) redisUtils.get(tokenKey); |
|
|
|
|
|
if(StringUtils.isEmpty(token)) { |
|
|
|
|
|
token = getTokenAndRefresh(tokenKey); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return token; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
* 接口是否成功获取数据 |
|
|
|
|
|
* @param result |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
private Boolean isSuccess(JSONObject result) { |
|
|
|
|
|
Boolean success = Boolean.FALSE; |
|
|
|
|
|
if(result != null && !result.isEmpty()) { |
|
|
|
|
|
JSONObject customObject = JSONObject.parseObject(result.getJSONObject("data").getString("custom")); |
|
|
|
|
|
int code = customObject.getInteger("code"); |
|
|
|
|
|
if(code == 1) { |
|
|
|
|
|
success = Boolean.TRUE; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return success; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 是否token过期 |
|
|
|
|
|
* @param result |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
private Boolean isTokenExpire(JSONObject result) { |
|
|
|
|
|
Boolean expire = Boolean.FALSE; |
|
|
|
|
|
if(result != null && !result.isEmpty()) { |
|
|
|
|
|
if(!isSuccess(result)) { |
|
|
|
|
|
JSONObject customObject = JSONObject.parseObject(result.getJSONObject("data").getString("custom")); |
|
|
|
|
|
int code = customObject.getInteger("code"); |
|
|
|
|
|
String message = customObject.getString("text"); |
|
|
|
|
|
if(code == 0 && "身份验证失败".equals(message)) { |
|
|
|
|
|
expire = Boolean.TRUE; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return expire; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取token并将token存入redis缓存 |
|
|
|
|
|
* @param tokenKey |
|
|
|
|
|
* @return |
|
|
|
|
|
* @throws IOException |
|
|
|
|
|
*/ |
|
|
|
|
|
private String getTokenAndRefresh(String tokenKey) throws IOException { |
|
|
|
|
|
String token = null; |
|
|
|
|
|
token = ActWithoutProofUtils.getToken(); |
|
|
|
|
|
redisUtils.set(tokenKey, token); |
|
|
|
|
|
return token; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|