zhouc 增加转发接口
This commit is contained in:
parent
3ce85b2874
commit
9b3db92c12
@ -0,0 +1,80 @@
|
|||||||
|
package com.wmyun.module.system.controller.admin.forward;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.wmyun.framework.common.pojo.CommonResult;
|
||||||
|
import com.wmyun.module.system.controller.admin.forward.vo.ForwardReqVO;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
|
import org.apache.http.HttpEntity;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.wmyun.framework.common.pojo.CommonResult.error;
|
||||||
|
import static com.wmyun.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhouc
|
||||||
|
* @date 2025/3/3 15:05
|
||||||
|
* @className ForwardController
|
||||||
|
* @description
|
||||||
|
*/
|
||||||
|
@Tag(name = "管理后台 -接口转发")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/forward")
|
||||||
|
@Validated
|
||||||
|
@Transactional
|
||||||
|
public class ForwardController {
|
||||||
|
|
||||||
|
@PostMapping("/interface")
|
||||||
|
@Operation(summary = "接口转发")
|
||||||
|
@PreAuthorize("@ss.hasPermission('system:forward:interface')")
|
||||||
|
public CommonResult<String> Project(@Valid @RequestBody ForwardReqVO forwardReqVO) {
|
||||||
|
try {
|
||||||
|
JSONObject jsonObject = JSON.parseObject(JSONObject.toJSONString(forwardReqVO));
|
||||||
|
String url = jsonObject.getString("url");
|
||||||
|
Map<String, String> headers = new HashMap<>();
|
||||||
|
JSONObject headparameter = jsonObject.getJSONObject("headparameter");
|
||||||
|
for (Map.Entry<String, Object> entry : headparameter.entrySet()) {
|
||||||
|
headers.put(entry.getKey(), entry.getValue().toString());
|
||||||
|
}
|
||||||
|
String body = jsonObject.getString("bodyparameter");
|
||||||
|
HttpClient httpClient = HttpClients.createDefault();
|
||||||
|
HttpPost httpPost = new HttpPost(url);
|
||||||
|
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
||||||
|
httpPost.setHeader(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
StringEntity entity = new StringEntity(body);
|
||||||
|
httpPost.setEntity(entity);
|
||||||
|
HttpResponse response = httpClient.execute(httpPost);
|
||||||
|
HttpEntity responseEntity = response.getEntity();
|
||||||
|
if (responseEntity != null) {
|
||||||
|
String responseBody = EntityUtils.toString(responseEntity);
|
||||||
|
return success(responseBody);
|
||||||
|
} else {
|
||||||
|
return error(411, "调用第三方接口返回为空!");
|
||||||
|
}
|
||||||
|
} catch (Exception exception) {
|
||||||
|
String message = exception.getMessage();
|
||||||
|
return error(411, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.wmyun.module.system.controller.admin.forward.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhouc
|
||||||
|
* @date 2025/3/3 15:06
|
||||||
|
* @className ForwardReqVO
|
||||||
|
* @description
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Schema(description = "管理后台 - 接口转发 Request VO")
|
||||||
|
public class ForwardReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "转发地址", example = "https://XXXXXX/login")
|
||||||
|
private String url;
|
||||||
|
@Schema(description = "头部入参(Json格式)", example = "{\"Content-Type\":\"application/json\",\"Authorization\":\"XXXXX\"}")
|
||||||
|
private String headparameter;
|
||||||
|
@Schema(description = "Body入参(Json格式)", example = "{\"Content-Type\":\"application/json\",\"Authorization\":\"XXXXX\"}")
|
||||||
|
private String bodyparameter;
|
||||||
|
|
||||||
|
}
|
@ -3,6 +3,7 @@ package com.wmyun.module.system.controller.admin.pdf.vo;
|
|||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zhouc
|
* @author zhouc
|
||||||
@ -12,6 +13,8 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Schema(description = "管理后台 - PDF拆分 Request VO")
|
||||||
public class PdfResultVO {
|
public class PdfResultVO {
|
||||||
@Schema(description = "拆分后文件名称", example = "page_1.pdf")
|
@Schema(description = "拆分后文件名称", example = "page_1.pdf")
|
||||||
private String fileName; // 拆分后的文件名
|
private String fileName; // 拆分后的文件名
|
||||||
|
Loading…
Reference in New Issue
Block a user