Commit 55efc423 authored by wujipeng's avatar wujipeng
Browse files

接口扫描

parent 41c818b0
......@@ -32,4 +32,9 @@ public class CustomerProjectController {
return Result.data(customerProjectService.jg());
}
@ApiOperation(value = "生产")
@GetMapping("/sc")
public Result<List<CustomerProjectVO>> sc() {
return Result.data(customerProjectService.sc());
}
}
......@@ -2,8 +2,11 @@ package com.ruzhoukj.sms.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruzhoukj.sms.entity.CustomerProjectEntity;
import com.ruzhoukj.sms.model.vo.CustomerProjectVO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @author : wujipeng
* @date : 2025/11/4 13:49
......@@ -12,4 +15,9 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface CustomerProjectMapper extends BaseMapper<CustomerProjectEntity> {
List<CustomerProjectVO> jg();
List<CustomerProjectVO> sc();
}
......@@ -14,4 +14,5 @@ import java.util.List;
*/
public interface CustomerProjectService extends IService<CustomerProjectEntity> {
List<CustomerProjectVO> jg();
List<CustomerProjectVO> sc();
}
......@@ -16,6 +16,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.List;
......@@ -34,16 +35,20 @@ public class CustomerProjectServiceImpl extends ServiceImpl<CustomerProjectMappe
//登录获取token
String token;
try {
String loginResponse = postWithApacheHttpClient("http://172.24.33.190/api/auth/login",
"{\"username\":\"wsadmin\",\"password\":\"cced9dbff1f6b878702a7c9bc60dd125\"}", null);
// String loginResponse = postWithApacheHttpClient("http://172.24.33.190/api/auth/login",
// "{\"username\":\"wsadmin\",\"password\":\"cced9dbff1f6b878702a7c9bc60dd125\"}", null);
String loginResponse = postWithApacheHttpClient("http://192.168.10.3:71/api/auth/login",
"{\"username\":\"wsadmin\",\"password\":\"cd2350c714eb2cf9b4eacde8d4834823\"}", null);
JSONObject jsonObject = JSON.parseObject(loginResponse);
int loginCode = jsonObject.getInteger("code");
if (loginCode == 200) {
JSONObject jsonObject1 = jsonObject.getJSONObject("data");
token = jsonObject1.getString("access_token");
result.add(CustomerProjectVO.builder().name("登录接口").type("POST").result("成功").url("http://172.24.33.190/api/auth/login").build());
// result.add(CustomerProjectVO.builder().name("登录接口").type("POST").result("成功").url("http://172.24.33.190/api/auth/login").build());
result.add(CustomerProjectVO.builder().name("登录接口").type("POST").result("成功").url("http://192.168.10.3:71/api/auth/login").build());
} else {
result.add(CustomerProjectVO.builder().name("登录接口").type("POST").result("失败").url("http://172.24.33.190/api/auth/login").build());
// result.add(CustomerProjectVO.builder().name("登录接口").type("POST").result("失败").url("http://172.24.33.190/api/auth/login").build());
result.add(CustomerProjectVO.builder().name("登录接口").type("POST").result("失败").url("http://192.168.10.3/api/auth/login").build());
return result;
}
} catch (Exception e) {
......@@ -88,6 +93,86 @@ public class CustomerProjectServiceImpl extends ServiceImpl<CustomerProjectMappe
return result;
}
@Override
public List<CustomerProjectVO> sc() {
List<CustomerProjectVO> result = new ArrayList<>();
//登录获取token
String token;
try {
// String loginResponse = postWithApacheHttpClient("http://172.24.33.190/api/auth/login",
// "{\"username\":\"wsadmin\",\"password\":\"cced9dbff1f6b878702a7c9bc60dd125\"}", null);
String loginResponse = postWithApacheHttpClient("http://192.168.10.3:76/api/business/sys/user/userLogin",
"{\"userName\":\"admin\",\"password\":\"Ruzhoukj@2025\"}", null);
JSONObject jsonObject = JSON.parseObject(loginResponse);
int loginCode = jsonObject.getInteger("code");
if (loginCode == 200) {
JSONObject jsonObject1 = jsonObject.getJSONObject("data");
token = jsonObject1.getString("token");
// result.add(CustomerProjectVO.builder().name("登录接口").type("POST").result("成功").url("http://172.24.33.190/api/auth/login").build());
result.add(CustomerProjectVO.builder().name("登录接口").type("POST").result("成功").url("http://192.168.10.3:76/api/business/sys/user/userLogin").build());
} else {
// result.add(CustomerProjectVO.builder().name("登录接口").type("POST").result("失败").url("http://172.24.33.190/api/auth/login").build());
result.add(CustomerProjectVO.builder().name("登录接口").type("POST").result("失败").url("http://192.168.10.3:76/api/business/sys/user/userLogin").build());
return result;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
//查询接口列表
List<CustomerProjectEntity> customerProjectList = list(new LambdaQueryWrapper<CustomerProjectEntity>().eq(CustomerProjectEntity::getProject, "生产"));
//执行接口调用
for (CustomerProjectEntity customerProjectEntity : customerProjectList) {
String response = null;
//判断请求方式
try {
if ("POST".equals(customerProjectEntity.getType())) {
response = postWithApacheHttpClient(customerProjectEntity.getUrl(), customerProjectEntity.getParam(), "Bearer " + token);
} else if ("GET".equals(customerProjectEntity.getType())) {
response = getWithApacheHttpClient(customerProjectEntity.getUrl(), "Bearer " + token);
}
} catch (Exception e) {
result.add(CustomerProjectVO.builder()
.name(customerProjectEntity.getName())
.type(customerProjectEntity.getType())
.result("失败")
.url(customerProjectEntity.getUrl()).build());
}
if (ObjectUtils.isEmpty(response)) {
result.add(CustomerProjectVO.builder()
.name(customerProjectEntity.getName())
.type(customerProjectEntity.getType())
.result("响应体为空")
.url(customerProjectEntity.getUrl()).build());
continue;
}
try {
JSONObject jsonObject = JSON.parseObject(response);
int code = jsonObject.getInteger("code");
if (code == 200) {
result.add(CustomerProjectVO.builder()
.name(customerProjectEntity.getName())
.type(customerProjectEntity.getType())
.result("成功")
.url(customerProjectEntity.getUrl()).build());
} else {
result.add(CustomerProjectVO.builder()
.name(customerProjectEntity.getName())
.type(customerProjectEntity.getType())
.result("失败")
.url(customerProjectEntity.getUrl()).build());
}
} catch (Exception e) {
result.add(CustomerProjectVO.builder()
.name(customerProjectEntity.getName())
.type(customerProjectEntity.getType())
.result("失败")
.url(customerProjectEntity.getUrl()).build());
}
}
//结果反馈
return result;
}
/**
* 使用 Apache HttpClient 发送 GET 请求
*/
......
......@@ -3,4 +3,32 @@
<mapper namespace="com.ruzhoukj.sms.dao.CustomerProjectMapper">
<select id="jg" resultType="com.ruzhoukj.sms.model.vo.CustomerProjectVO">
select
id,
project,
name,
url,
type,
param
from
customer_project
where
project = '经管'
limit 10;
</select>
<select id="sc" resultType="com.ruzhoukj.sms.model.vo.CustomerProjectVO">
select
id,
project,
name,
url,
type,
param
from
customer_project
where
project = '生产'
limit 10;
</select>
</mapper>
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