还原转发接口

This commit is contained in:
lvleigang 2024-10-18 09:23:50 +08:00
parent d1687abd91
commit f17ade4145
3 changed files with 62 additions and 204 deletions

View File

@ -1,58 +0,0 @@
package com.hzya.frame.sysnew.application.entity;
/**
* 应用表(SysApplication)实体类
*
* @author makejava
* @since 2023-09-22 16:22:18
*/
public class U8CReturnEntity {
private String status;
private String data;
private String taskNumber;
private String errorcode;
private String errormsg;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public String getTaskNumber() {
return taskNumber;
}
public void setTaskNumber(String taskNumber) {
this.taskNumber = taskNumber;
}
public String getErrorcode() {
return errorcode;
}
public void setErrorcode(String errorcode) {
this.errorcode = errorcode;
}
public String getErrormsg() {
return errormsg;
}
public void setErrormsg(String errormsg) {
this.errormsg = errormsg;
}
}

View File

@ -1689,18 +1689,10 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
@DSTransactional()
public JsonResultEntity externalCallInterface(ServletRequest servletRequest, ServletResponse servletResponse) {
long startTime1 = System.currentTimeMillis();
//例如A应用发送数据到中台中台转发到B应用
HttpServletRequest request = (HttpServletRequest) servletRequest;
logger.info("发送数据1"+(System.currentTimeMillis()-startTime1));
String oldbodys = ServletUtil.getBody(servletRequest);
logger.info("发送数据2"+(System.currentTimeMillis()-startTime1));
Map<String, String> oldheaderMap = ServletUtil.getHeaderMap(request);
logger.info("发送数据3"+(System.currentTimeMillis()-startTime1));
String oldquerys = request.getQueryString();
//应用key
String publicKey = request.getHeader("publicKey");
@ -1710,11 +1702,8 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
String appId = request.getHeader("appId");
//apiCode
String apiCode = request.getHeader("apiCode");
logger.info("发送数据4"+(System.currentTimeMillis()-startTime1));
String ip = IPHelper.getIpAddr(request);
logger.info("发送数据5"+(System.currentTimeMillis()-startTime1));
if (publicKey == null || "".equals(publicKey)) {
return BaseResult.getFailureMessageEntity("请先传递公钥");
}
@ -1730,20 +1719,17 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
logger.info("请求参数publicKey" + publicKey + "】secretKey" + secretKey + "】appId" + appId + "】apiCode" + apiCode);
//根据请求a应用的公钥密钥是否能查找到一条数据
logger.info("发送数据6"+(System.currentTimeMillis()-startTime1));
SysApplicationEntity sendApp = getAppByPublicKeySecretKey(publicKey, secretKey);
if (sendApp == null) {
//saveLog(new SysApplicationEntity(), new SysApplicationEntity(), new SysApplicationApiEntity(), oldbodys, null, oldheaderMap, null, null, oldquerys, null, null, false,"公钥、密钥错误");
return BaseResult.getFailureMessageEntity("公钥、密钥错误,请联系管理员");
}
//判断应用是否启用
if (sendApp.getAppStatus() == null || !"1".equals(sendApp.getAppStatus())) {
saveLog(sendApp, new SysApplicationEntity(), new SysApplicationApiEntity(), oldbodys, null, oldheaderMap, null, null, oldquerys, null, null, false,sendApp.getName() + "应用未启用");
return BaseResult.getFailureMessageEntity(sendApp.getName() + "应用未启用,请联系管理员");
}
logger.info("发送数据7"+(System.currentTimeMillis()-startTime1));
SysApplicationEntity receiveApp = getAppByAppId(appId);
@ -1761,14 +1747,12 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
saveLog(sendApp, receiveApp, new SysApplicationApiEntity(), oldbodys, null, oldheaderMap, null, null, oldquerys, null, null, false,receiveApp.getName() + "应用接口环境未启用" );
return BaseResult.getFailureMessageEntity(receiveApp.getName() + "应用接口环境未启用,请联系管理员");
}
logger.info("发送数据8"+(System.currentTimeMillis()-startTime1));
SysApplicationApiEntity receiveApi = getApiByAppIdApiCode(receiveApp.getId(), apiCode);
if (receiveApi == null) {
saveLog(sendApp, receiveApp, new SysApplicationApiEntity(), oldbodys, null, oldheaderMap, null, null, oldquerys, null, null, false,receiveApp.getName() + ":" + apiCode + "未启用或者未创建" );
return BaseResult.getFailureMessageEntity(receiveApp.getName() + ":" + apiCode + "未启用或者未创建");
}
logger.info("发送数据9"+(System.currentTimeMillis()-startTime1));
SysApplicationApiAuthEntity sysApplicationApiAuthEntity = getApiAuthByNameAppId(sendApp.getId(), receiveApp.getId());
if (sysApplicationApiAuthEntity == null) {
@ -1780,7 +1764,6 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
saveLog(sendApp, receiveApp, receiveApi, oldbodys, null, oldheaderMap, null, null, oldquerys, null, null, false,receiveApp.getName() + "发送应用" + receiveApp.getName() + "的ip白名单配置错误" );
return BaseResult.getFailureMessageEntity(receiveApp.getName() + "发送应用" + receiveApp.getName() + "的ip白名单配置错误");
}
logger.info("发送数据10"+(System.currentTimeMillis()-startTime1));
SysApplicationApiAuthDetailEntity sysApplicationApiAuthDetailEntity = getApiAuthDetailByAppIdApiIdTripartiteSystemId(receiveApp.getId(), receiveApi.getId(), sysApplicationApiAuthEntity.getId());
if (sysApplicationApiAuthDetailEntity == null) {
@ -1788,7 +1771,6 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
return BaseResult.getFailureMessageEntity(receiveApi.getApiName() + "未授权给" + sendApp.getName() + ",请联系管理员");
}
SysExtensionApiEntity sysExtensionApiEntity = new SysExtensionApiEntity();
logger.info("发送数据11"+(System.currentTimeMillis()-startTime1));
List<String> a = Arrays.asList(new String[]{"apicode", "appid", "secretkey", "publickey", "x-forwarded-for", "cookie", "x-forwarded-proto", "x-real-ip", "content-length", "accept-language", "host", "content-type", "connection", "cache-control", "accept-encoding", "pragma", "accept", "user-agent"});
@ -1810,7 +1792,6 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
}
}
logger.info("发送数据12"+(System.currentTimeMillis()-startTime1));
sysExtensionApiEntity.setSendApp(sendApp);
@ -1858,8 +1839,6 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
}
}
logger.info("发送数据13"+(System.currentTimeMillis()-startTime1));
headers = sysExtensionApiEntity.getHeaders();
String querys = sysExtensionApiEntity.getQuerys();
String bodys = sysExtensionApiEntity.getBodys();
@ -1882,8 +1861,6 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
if ("2".equals(receiveApi.getRequestMethod())) {
method = "GET";
}
logger.info("发送数据14"+(System.currentTimeMillis()-startTime1));
//List<String> a = Arrays.asList(new String[]{"apicode", "appid", "secretkey", "publickey", "x-forwarded-for", "cookie", "x-forwarded-proto", "x-real-ip", "content-length", "accept-language", "host", "content-type", "connection", "cache-control", "accept-encoding", "pragma", "accept", "user-agent"});
//Map<String, String> headers = new HashMap<>();
//if (receiveApi.getHeaderIn() != null && !"".equals(receiveApi.getHeaderIn())) {
@ -1905,8 +1882,6 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
if ("POST".equals(method)) {
logger.info("发送数据15"+(System.currentTimeMillis()-startTime1));
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
// HttpClient
CloseableHttpClient closeableHttpClient = httpClientBuilder.disableCookieManagement().build();
@ -1923,8 +1898,6 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
}
StringBuilder body = new StringBuilder();
boolean flag = true;
logger.info("发送数据16"+(System.currentTimeMillis()-startTime1));
try {
if (bodys != null && !"".equals(bodys)) {
ByteArrayEntity entity = new ByteArrayEntity(bodys.getBytes("UTF-8"));
@ -1932,16 +1905,13 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
post.setEntity(entity);
}
response = closeableHttpClient.execute(post);
logger.info("发送数据17"+(System.currentTimeMillis()-startTime1));
HttpEntity entity = response.getEntity();
body.append(resultToStr(entity));
//body.append(EntityUtils.toString(entity,"UTF-8"));
synchronized (lock) {
body.append(EntityUtils.toString(entity,"UTF-8"));
}
flag = true;
logger.info("返回结果:" + body);
logger.info("发送数据18"+(System.currentTimeMillis()-startTime1));
} catch (Exception e) {
logger.error("请求错误:" + e.getMessage());
body.append(e.getMessage());
@ -1961,13 +1931,8 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
}
}
logger.info("发送数据19 "+(System.currentTimeMillis()-startTime1));
logger.info("保存日志开始");
SysMessageManageLogEntity sysMessageManageLogEntity = saveLog(sendApp, receiveApp, receiveApi, oldbodys,bodys, oldheaderMap,headers, headers, oldquerys,querys, body.toString(),true,null);
logger.info("发送数据20 "+(System.currentTimeMillis()-startTime1));
if (methods != null && methods.length > 0) {
for (Method m : methods) {
if (null != m) {
@ -1983,30 +1948,16 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
}
}
}
logger.info("发送数据21 "+(System.currentTimeMillis()-startTime1));
logger.info("保存日志结束");
if (flag) {
try {
if (JSONUtil.isTypeJSON(body.toString())) {
JSONObject jsonObject = JSONObject.parseObject(body.toString());
if(sysMessageManageLogEntity.getStatus() != null && "3".equals(sysMessageManageLogEntity.getStatus())){
if(sysMessageManageLogEntity.getReturnObject() != null ){
return BaseResult.getSuccessMessageEntity("转发成功", sysMessageManageLogEntity.getReturnObject());
}else {
return BaseResult.getSuccessMessageEntity("转发成功", sysMessageManageLogEntity.getU8CReturnEntity());
}
return BaseResult.getSuccessMessageEntity("转发成功", jsonObject);
}else {
if(sysMessageManageLogEntity.getReturnObject() != null ){
return BaseResult.getFailureMessageEntity("转发失败", sysMessageManageLogEntity.getReturnObject());
}else if(sysMessageManageLogEntity.getU8CReturnEntity() != null ){
return BaseResult.getSuccessMessageEntity("转发失败", sysMessageManageLogEntity.getU8CReturnEntity());
}else {
JSONObject jsonObject = JSONObject.parseObject(body.toString());
logger.info("发送数据错误22 "+(System.currentTimeMillis()-startTime1));
return BaseResult.getFailureMessageEntity("转发失败", jsonObject);
}
return BaseResult.getFailureMessageEntity("转发失败", jsonObject);
}
} catch (Exception e) {
logger.info("发送数据错误22 "+(System.currentTimeMillis()-startTime1));
} else {
if(sysMessageManageLogEntity.getStatus() != null && "3".equals(sysMessageManageLogEntity.getStatus())){
return BaseResult.getSuccessMessageEntity("转发成功", body);
}else {
@ -2036,7 +1987,6 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
boolean flag = true;
try {
response = closeableHttpClient.execute(get);
HttpEntity entity = response.getEntity();
synchronized (lock) {
@ -2081,14 +2031,14 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
}
logger.info("保存日志结束");
if (flag) {
try {
if (JSONUtil.isTypeJSON(body.toString())) {
JSONObject jsonObject = JSONObject.parseObject(body.toString());
if(sysMessageManageLogEntity.getStatus() != null && "3".equals(sysMessageManageLogEntity.getStatus())){
return BaseResult.getSuccessMessageEntity("转发成功", jsonObject);
}else {
return BaseResult.getFailureMessageEntity("转发失败", jsonObject);
}
} catch (Exception e) {
} else {
if(sysMessageManageLogEntity.getStatus() != null && "3".equals(sysMessageManageLogEntity.getStatus())){
return BaseResult.getSuccessMessageEntity("转发成功", body);
}else {
@ -2101,8 +2051,6 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
}
}
/*****
* 请求结果转换str
* @content:
@ -2593,7 +2541,7 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
JSONObject jsonObject1 = JSONObject.parseObject(body);
String retCode = jsonObject1.getString("retCode");
if(retCode != null && "0000".equals(retCode)){
JSONObject jsonObject2 = JSONObject.parseObject(jsonObject1.getString("Data"));
JSONObject jsonObject2 = JSONObject.parseObject(jsonObject1.getString("data"));
String fileBytes = jsonObject2.getString("fileBytes");
if(fileBytes != null && !"".equals(fileBytes)){
jsonObject2.put("fileBytes","");
@ -2618,77 +2566,55 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
if (receiveApi.getReturnSuccessField() != null && !"".equals(receiveApi.getReturnSuccessField())
&& receiveApi.getReturnSuccessValue() != null && !"".equals(receiveApi.getReturnSuccessValue())) {
if (JSONUtil.isTypeJSON(body)) {
if(receiveApi.getApiCode() != null && "8000350006".equals(receiveApi.getApiCode())){
U8CReturnEntity u8CReturnEntity = JSONObject.parseObject(body, U8CReturnEntity.class);
sysMessageManageLogEntity.setU8CReturnEntity(u8CReturnEntity);
if(u8CReturnEntity.getStatus() != null && "success".equals(u8CReturnEntity.getStatus())){
sysMessageManageLogEntity.setStatus("3");//返回信息
JSONObject cheackdatas = JSONObject.parseObject(body);
JSONObject datas = JSONObject.parseObject(body);
String checkdata = cheackdatas.getString(receiveApi.getReturnSuccessField());
if (checkdata != null && receiveApi.getReturnSuccessValue().equals(checkdata)) {
sysMessageManageLogEntity.setStatus("3");//返回信息
if (receiveApi.getReturnMsg() != null && !"".equals(receiveApi.getReturnMsg())) {
String returnMsg = cheackdatas.getString(receiveApi.getReturnMsg());
sysMessageManageLogEntity.setRemark("接口调用成功,返回信息如下:" + returnMsg);//返回信息
} else {
sysMessageManageLogEntity.setRemark("接口调用成功");//返回信息
}
}else if(receiveApi.getReturnSuccessValue().equals("not null") && checkdata != null){
sysMessageManageLogEntity.setStatus("3");//返回信息
if (receiveApi.getReturnMsg() != null && !"".equals(receiveApi.getReturnMsg())) {
String returnMsg = cheackdatas.getString(receiveApi.getReturnMsg());
sysMessageManageLogEntity.setRemark("接口调用成功,返回信息如下:" + returnMsg);//返回信息
} else {
sysMessageManageLogEntity.setRemark("接口调用成功");//返回信息
}else {
sysMessageManageLogEntity.setStatus("4");//返回信息
sysMessageManageLogEntity.setRemark("接口调用成功,返回信息如下:" + u8CReturnEntity.getErrormsg());//返回信息
}
}else {
JSONObject cheackdatas = JSONObject.parseObject(body);
sysMessageManageLogEntity.setReturnObject(cheackdatas);
JSONObject datas = JSONObject.parseObject(body);
String checkdata = cheackdatas.getString(receiveApi.getReturnSuccessField());
if (checkdata != null && receiveApi.getReturnSuccessValue().equals(checkdata)) {
sysMessageManageLogEntity.setStatus("3");//返回信息
if (receiveApi.getReturnMsg() != null && !"".equals(receiveApi.getReturnMsg())) {
String returnMsg = cheackdatas.getString(receiveApi.getReturnMsg());
sysMessageManageLogEntity.setRemark("接口调用成功,返回信息如下:" + returnMsg);//返回信息
} else {
sysMessageManageLogEntity.setRemark("接口调用成功");//返回信息
}
}else if(receiveApi.getReturnSuccessValue().equals("not null") && checkdata != null){
sysMessageManageLogEntity.setStatus("3");//返回信息
if (receiveApi.getReturnMsg() != null && !"".equals(receiveApi.getReturnMsg())) {
String returnMsg = cheackdatas.getString(receiveApi.getReturnMsg());
sysMessageManageLogEntity.setRemark("接口调用成功,返回信息如下:" + returnMsg);//返回信息
} else {
sysMessageManageLogEntity.setRemark("接口调用成功");//返回信息
}
}else {
String fieldname = receiveApi.getReturnSuccessField();
if(fieldname.contains(".")){
String[] fileds = fieldname.split("\\.");
boolean flags = false;
for (int i = 0; i < fileds.length; i++) {
if (JSONUtil.isTypeJSON(datas.getString(fileds[i]))) {
datas = datas.getJSONObject(fileds[i]);
if(fileds.length-2 == i ){
String a = datas.getString(fileds[i+1]);
if (a != null && receiveApi.getReturnSuccessValue().equals(a)) {
flags = true;
break;
}else if(receiveApi.getReturnSuccessValue().equals("not null") && a != null){
flags = true;
break;
}else {
break;
}
String fieldname = receiveApi.getReturnSuccessField();
if(fieldname.contains(".")){
String[] fileds = fieldname.split("\\.");
boolean flags = false;
for (int i = 0; i < fileds.length; i++) {
if (JSONUtil.isTypeJSON(datas.getString(fileds[i]))) {
datas = datas.getJSONObject(fileds[i]);
if(fileds.length-2 == i ){
String a = datas.getString(fileds[i+1]);
if (a != null && receiveApi.getReturnSuccessValue().equals(a)) {
flags = true;
break;
}else if(receiveApi.getReturnSuccessValue().equals("not null") && a != null){
flags = true;
break;
}else {
break;
}
}
}
if(flags){
sysMessageManageLogEntity.setStatus("3");//返回信息
if (receiveApi.getReturnMsg() != null && !"".equals(receiveApi.getReturnMsg())) {
String returnMsg = cheackdatas.getString(receiveApi.getReturnMsg());
sysMessageManageLogEntity.setRemark("接口调用成功,返回信息如下:" + returnMsg);//返回信息
} else {
sysMessageManageLogEntity.setRemark("接口调用成功");//返回信息
}
}else {
sysMessageManageLogEntity.setStatus("4");//返回信息
if (receiveApi.getReturnMsg() != null && !"".equals(receiveApi.getReturnMsg())) {
String returnMsg = cheackdatas.getString(receiveApi.getReturnMsg());
sysMessageManageLogEntity.setRemark("接口调用失败,返回值错误,返回信息如下:" + returnMsg);//返回信息
} else {
sysMessageManageLogEntity.setRemark("接口调用失败,返回值错误");//返回信息
}
}
if(flags){
sysMessageManageLogEntity.setStatus("3");//返回信息
if (receiveApi.getReturnMsg() != null && !"".equals(receiveApi.getReturnMsg())) {
String returnMsg = cheackdatas.getString(receiveApi.getReturnMsg());
sysMessageManageLogEntity.setRemark("接口调用成功,返回信息如下:" + returnMsg);//返回信息
} else {
sysMessageManageLogEntity.setRemark("接口调用成功");//返回信息
}
}else {
sysMessageManageLogEntity.setStatus("4");//返回信息
if (receiveApi.getReturnMsg() != null && !"".equals(receiveApi.getReturnMsg())) {
@ -2698,6 +2624,15 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
sysMessageManageLogEntity.setRemark("接口调用失败,返回值错误");//返回信息
}
}
}else {
sysMessageManageLogEntity.setStatus("4");//返回信息
if (receiveApi.getReturnMsg() != null && !"".equals(receiveApi.getReturnMsg())) {
String returnMsg = cheackdatas.getString(receiveApi.getReturnMsg());
sysMessageManageLogEntity.setRemark("接口调用失败,返回值错误,返回信息如下:" + returnMsg);//返回信息
} else {
sysMessageManageLogEntity.setRemark("接口调用失败,返回值错误");//返回信息
}
}
}
} else {

View File

@ -1,7 +1,6 @@
package com.hzya.frame.sysnew.messageManageLog.entity;
import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.sysnew.application.entity.U8CReturnEntity;
import com.hzya.frame.web.entity.BaseEntity;
import java.util.Date;
@ -49,9 +48,6 @@ public class SysMessageManageLogEntity extends BaseEntity {
private Date createTimeEnd;
private List<String> ids;
private JSONObject returnObject;
private U8CReturnEntity u8CReturnEntity;
public String getReturnType() {
return returnType;
}
@ -203,20 +199,5 @@ public class SysMessageManageLogEntity extends BaseEntity {
this.createTimeEnd = createTimeEnd;
}
public JSONObject getReturnObject() {
return returnObject;
}
public void setReturnObject(JSONObject returnObject) {
this.returnObject = returnObject;
}
public U8CReturnEntity getU8CReturnEntity() {
return u8CReturnEntity;
}
public void setU8CReturnEntity(U8CReturnEntity u8CReturnEntity) {
this.u8CReturnEntity = u8CReturnEntity;
}
}