Commit 9380abc7 authored by wujipeng's avatar wujipeng
Browse files

接口扫描

parent 9c51739b
package com.ruzhoukj.sms.controller;
import com.platform.model.resp.Result;
import com.ruzhoukj.sms.model.vo.CustomerProjectVO;
import com.ruzhoukj.sms.service.CustomerProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -8,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* @author : wujipeng
......@@ -25,7 +27,7 @@ public class CustomerProjectController {
@ApiOperation(value = "经管")
@RequestMapping("/jg")
public Result jg() {
public Result<List<CustomerProjectVO>> jg() {
return Result.data(customerProjectService.jg());
}
......
package com.ruzhoukj.sms.model.vo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.checkerframework.checker.lock.qual.NewObject;
/**
* @author : wujipeng
* @date : 2025/11/4 15:59
* @Version: 1.0
* @Desc : 描述信息
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CustomerProjectVO {
private String name;
private String type;
private String url;
private String result;
}
......@@ -2,6 +2,9 @@ package com.ruzhoukj.sms.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruzhoukj.sms.entity.CustomerProjectEntity;
import com.ruzhoukj.sms.model.vo.CustomerProjectVO;
import java.util.List;
/**
* @author : wujipeng
......@@ -10,5 +13,5 @@ import com.ruzhoukj.sms.entity.CustomerProjectEntity;
* @Desc : 描述信息
*/
public interface CustomerProjectService extends IService<CustomerProjectEntity> {
Object jg();
List<CustomerProjectVO> jg();
}
......@@ -4,10 +4,9 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.platform.exception.BusinessException;
import com.ruzhoukj.sms.dao.CustomerProjectMapper;
import com.ruzhoukj.sms.entity.CustomerProjectEntity;
import com.ruzhoukj.sms.model.vo.CustomerProjectVO;
import com.ruzhoukj.sms.service.CustomerProjectService;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
......@@ -18,7 +17,7 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;
import java.util.LinkedHashMap;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -30,21 +29,21 @@ import java.util.List;
@Service
public class CustomerProjectServiceImpl extends ServiceImpl<CustomerProjectMapper, CustomerProjectEntity> implements CustomerProjectService {
@Override
public Object jg() {
LinkedHashMap<String, String> result = Maps.newLinkedHashMap();
public List<CustomerProjectVO> jg() {
List<CustomerProjectVO> result = new ArrayList<>();
//登录获取token
String token = null;
String token;
try {
String loginResponse = postWithApacheHttpClient("http://192.168.10.3:71/api/auth/login",
String loginResponse = postWithApacheHttpClient("http://172.24.33.190/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.put("登录接口", "成功");
result.add(CustomerProjectVO.builder().name("登录接口").type("POST").result("成功").url("http://172.24.33.190/api/auth/login").build());
} else {
result.put("登录接口", "失败");
result.add(CustomerProjectVO.builder().name("登录接口").type("POST").result("失败").url("http://172.24.33.190/api/auth/login").build());
return result;
}
} catch (Exception e) {
......@@ -54,33 +53,35 @@ public class CustomerProjectServiceImpl extends ServiceImpl<CustomerProjectMappe
List<CustomerProjectEntity> customerProjectList = list(new LambdaQueryWrapper<CustomerProjectEntity>().eq(CustomerProjectEntity::getProject, "经管"));
//执行接口调用
for (CustomerProjectEntity customerProjectEntity : customerProjectList) {
String response = null;
//判断请求方式
if ("POST".equals(customerProjectEntity.getType())) {
try {
String response = postWithApacheHttpClient(customerProjectEntity.getUrl(), customerProjectEntity.getParam(), token);
JSONObject jsonObject = JSON.parseObject(response);
int code = jsonObject.getInteger("code");
if (code == 200) {
result.put(customerProjectEntity.getName(), "成功");
}else {
result.put(customerProjectEntity.getName(), "失败");
}
} catch (Exception e) {
throw new BusinessException("调用接口失败");
}
} else if ("GET".equals(customerProjectEntity.getType())) {
try {
String response = getWithApacheHttpClient(customerProjectEntity.getUrl(), token);
JSONObject jsonObject = JSON.parseObject(response);
int code = jsonObject.getInteger("code");
if (code == 200) {
result.put(customerProjectEntity.getName(), "成功");
} else {
result.put(customerProjectEntity.getName(), "失败");
}
} catch (Exception e) {
throw new BusinessException("调用接口失败");
try {
if ("POST".equals(customerProjectEntity.getType())) {
response = postWithApacheHttpClient(customerProjectEntity.getUrl(), customerProjectEntity.getParam(), token);
} else if ("GET".equals(customerProjectEntity.getType())) {
response = getWithApacheHttpClient(customerProjectEntity.getUrl(), token);
}
} catch (Exception e) {
result.add(CustomerProjectVO.builder()
.name(customerProjectEntity.getName())
.type(customerProjectEntity.getType())
.result("失败")
.url(customerProjectEntity.getUrl()).build());
}
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());
}
}
//结果反馈
......
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