|
|
@ -48,9 +48,13 @@ public class ShellController { |
|
|
|
@PostMapping("/api") |
|
|
|
@Log(title = "远程行对接qad", businessType = BusinessType.INSERT, isManager = false) |
|
|
|
public AjaxResult api(HttpServletRequest request, @RequestBody String body) throws IOException, JSchException { |
|
|
|
System.out.println("接收到的body:" + body); |
|
|
|
String interfaceName = request.getHeader("interface"); |
|
|
|
System.out.println("接收到的interface:" + interfaceName); |
|
|
|
String sign = request.getHeader("sign"); |
|
|
|
System.out.println("接收到的sign:" + sign); |
|
|
|
String timeStr = request.getHeader("timestamp"); |
|
|
|
System.out.println("接收到的timeStr:" + timeStr); |
|
|
|
if(timeStr == null || timeStr.isEmpty()) { |
|
|
|
return AjaxResult.error(HttpStatus.TIMESTAMP_ERROR, "时间戳不正确"); |
|
|
|
} |
|
|
@ -122,4 +126,88 @@ public class ShellController { |
|
|
|
return linuxAccessService.executeShell(linuxAccess, qadAccess, traceid, inJson, domain); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 对外提供一个接口,通过header中的interfaceName反射机制调用方法,方法必须写到这个controller中,并且不用加PostMapping注解。 |
|
|
|
* |
|
|
|
* @param request request |
|
|
|
* @param body 请求主体 |
|
|
|
* @return 结果 |
|
|
|
*/ |
|
|
|
@PostMapping("/apiSecret") |
|
|
|
@Log(title = "远程行对接qad", businessType = BusinessType.INSERT, isManager = false) |
|
|
|
public AjaxResult apiSecret(HttpServletRequest request, @RequestBody String body) throws IOException, JSchException { |
|
|
|
System.out.println("接收到的body:" + body); |
|
|
|
String interfaceName = request.getHeader("interface"); |
|
|
|
System.out.println("接收到的interface:" + interfaceName); |
|
|
|
String timeStr = request.getHeader("timestamp"); |
|
|
|
System.out.println("接收到的timeStr:" + timeStr); |
|
|
|
String secret = request.getHeader("secret"); |
|
|
|
System.out.println("接收到的secret:" + secret); |
|
|
|
if(timeStr == null || timeStr.isEmpty()) { |
|
|
|
return AjaxResult.error(HttpStatus.TIMESTAMP_ERROR, "时间戳不正确"); |
|
|
|
} |
|
|
|
long timestamp = 0; |
|
|
|
try { |
|
|
|
timestamp = Long.parseLong(timeStr); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
return AjaxResult.error(HttpStatus.TIMESTAMP_ERROR, "时间戳不正确"); |
|
|
|
} |
|
|
|
long tenTimestamp = timestamp + (10 * 60 * 1000); // 计算10分钟后的时间戳
|
|
|
|
long currentTimestamp = System.currentTimeMillis(); // 获取当前时间戳
|
|
|
|
//过期
|
|
|
|
if(tenTimestamp < currentTimestamp) { |
|
|
|
return AjaxResult.error(HttpStatus.EXPIRE_ERROR, "请求已过期"); |
|
|
|
} |
|
|
|
if(secret == null || !secret.equals("Wenyin@2024")) { |
|
|
|
return AjaxResult.error(HttpStatus.TIMESTAMP_ERROR, "秘钥不正确"); |
|
|
|
} |
|
|
|
//url特殊字符要转换
|
|
|
|
body = body.replace("+", "%2B"); |
|
|
|
body = body.replace("/", "%2F"); |
|
|
|
body = body.replace("?", "%3F"); |
|
|
|
body = body.replace("#", "%23"); |
|
|
|
body = body.replace("&", "%26"); |
|
|
|
body = body.replace("=", "%3D"); |
|
|
|
//处理kettle加密中文有问题
|
|
|
|
body = URLDecoder.decode(body, "UTF-8"); |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(body); |
|
|
|
String key = ""; |
|
|
|
for(String keyTemp : jsonObject.keySet()) { |
|
|
|
jsonObject = JSONObject.parseObject(jsonObject.getString(keyTemp)); |
|
|
|
key = keyTemp; |
|
|
|
} |
|
|
|
String domain = jsonObject.getString("domain"); |
|
|
|
if(domain == null || domain.isEmpty()) { |
|
|
|
return AjaxResult.error(HttpStatus.DOMAIN_ERROR, "域不能为空"); |
|
|
|
} |
|
|
|
String companyCode = jsonObject.getString("company_code"); |
|
|
|
if(companyCode == null || companyCode.isEmpty()) { |
|
|
|
return AjaxResult.error(HttpStatus.COMPANY_CODE_ERROR, "公司编码不能为空"); |
|
|
|
} |
|
|
|
QueryWrapper<LinuxAccess> linuxAccessQueryWrapper = new QueryWrapper<>(); |
|
|
|
linuxAccessQueryWrapper.eq("company_code", companyCode); |
|
|
|
linuxAccessQueryWrapper.eq("uri", interfaceName); |
|
|
|
linuxAccessQueryWrapper.isNull("delete_time"); |
|
|
|
LinuxAccess linuxAccess = linuxAccessService.getOne(linuxAccessQueryWrapper); |
|
|
|
if(linuxAccess == null) { |
|
|
|
return AjaxResult.error(HttpStatus.LINUX_ACCESS_ERROR, "linux访问控制不存在"); |
|
|
|
} |
|
|
|
QueryWrapper<QadAccess> qadAccessQueryWrapper = new QueryWrapper<>(); |
|
|
|
qadAccessQueryWrapper.eq("company_code", companyCode); |
|
|
|
qadAccessQueryWrapper.eq("domain", domain); |
|
|
|
qadAccessQueryWrapper.isNull("delete_time"); |
|
|
|
QadAccess qadAccess = qadAccessService.getOne(qadAccessQueryWrapper); |
|
|
|
if(qadAccess == null) { |
|
|
|
return AjaxResult.error(HttpStatus.QAD_ACCESS_ERROR, "QAD_ACCESS_ERROR"); |
|
|
|
} |
|
|
|
//生成traceid
|
|
|
|
String traceid = jsonObject.getString("traceid"); |
|
|
|
jsonObject.remove("traceid"); |
|
|
|
jsonObject.remove("dataid"); |
|
|
|
jsonObject.remove("company_code"); |
|
|
|
jsonObject.remove("domain"); |
|
|
|
String inJson = "{\"" + key + "\":"+ jsonObject+"}"; |
|
|
|
return linuxAccessService.executeShell(linuxAccess, qadAccess, traceid, inJson, domain); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|