"...service/git@gitlab.ruzhoukj.com:wujipeng/relation.git" did not exist on "df6466baecb3e90b900614ffd3e9869087676405"
Commit 9c51739b authored by wujipeng's avatar wujipeng
Browse files

接口扫描

parent 82745edf
package com.ruzhoukj.sms.controller;
import com.platform.model.resp.Result;
import com.ruzhoukj.sms.service.CustomerProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* @author : wujipeng
* @date : 2025/11/4 10:00
* @Version: 1.0
* @Desc : 描述信息
*/
@Api(tags = "客户项目管理")
@RestController
@RequestMapping("/customer/project")
public class CustomerProjectController {
@Resource
private CustomerProjectService customerProjectService;
@ApiOperation(value = "经管")
@RequestMapping("/jg")
public Result jg() {
return Result.data(customerProjectService.jg());
}
}
package com.ruzhoukj.sms.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruzhoukj.sms.entity.CustomerProjectEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* @author : wujipeng
* @date : 2025/11/4 13:49
* @Version: 1.0
* @Desc : 描述信息
*/
@Mapper
public interface CustomerProjectMapper extends BaseMapper<CustomerProjectEntity> {
}
package com.ruzhoukj.sms.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
/**
* @author : wujipeng
* @date : 2025/11/4 13:47
* @Version: 1.0
* @Desc : 描述信息
*/
@Data
@TableName("customer_project")
public class CustomerProjectEntity {
@TableId(type = IdType.ASSIGN_ID)
private Integer id;
private String project;
private String name;
private String url;
private String type;
private String param;
}
package com.ruzhoukj.sms.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruzhoukj.sms.entity.CustomerProjectEntity;
/**
* @author : wujipeng
* @date : 2025/11/4 10:03
* @Version: 1.0
* @Desc : 描述信息
*/
public interface CustomerProjectService extends IService<CustomerProjectEntity> {
Object jg();
}
package com.ruzhoukj.sms.service.impl;
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.service.CustomerProjectService;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
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 java.util.LinkedHashMap;
import java.util.List;
/**
* @author : wujipeng
* @date : 2025/11/4 10:03
* @Version: 1.0
* @Desc : 描述信息
*/
@Service
public class CustomerProjectServiceImpl extends ServiceImpl<CustomerProjectMapper, CustomerProjectEntity> implements CustomerProjectService {
@Override
public Object jg() {
LinkedHashMap<String, String> result = Maps.newLinkedHashMap();
//登录获取token
String token = null;
try {
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.put("登录接口", "成功");
} else {
result.put("登录接口", "失败");
return result;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
//查询接口列表
List<CustomerProjectEntity> customerProjectList = list(new LambdaQueryWrapper<CustomerProjectEntity>().eq(CustomerProjectEntity::getProject, "经管"));
//执行接口调用
for (CustomerProjectEntity customerProjectEntity : customerProjectList) {
//判断请求方式
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("调用接口失败");
}
}
}
//结果反馈
return result;
}
/**
* 使用 Apache HttpClient 发送 GET 请求
*/
public static String getWithApacheHttpClient(String url, String token) throws Exception {
// 创建可关闭的HttpClient实例
try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpGet request = new HttpGet(url);
request.setHeader("authorization", token);
try (CloseableHttpResponse response = client.execute(request)) {
return EntityUtils.toString(response.getEntity());
}
}
}
/**
* 使用 Apache HttpClient 发送 POST 请求
*/
public static String postWithApacheHttpClient(String url, String jsonBody, String token) throws Exception {
try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpPost request = new HttpPost(url);
request.setHeader("authorization", token);
// 设置请求体
StringEntity entity = new StringEntity(jsonBody);
entity.setContentType("application/json");
request.setEntity(entity);
try (CloseableHttpResponse response = client.execute(request)) {
return EntityUtils.toString(response.getEntity());
}
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruzhoukj.sms.dao.CustomerProjectMapper">
</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