Commit 58e3a977 authored by 赵啸非's avatar 赵啸非

修改配置文件

parent 93cb23e1
package com.mortals.xhx.busiz.web;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
......@@ -116,35 +117,17 @@ public class ProxyController {
log.info("proxyPost params: {}, body: {}, headers: {}", params, body, headers);
ApiResp<String> rsp = new ApiResp<>();
// String path = params.getOrDefault("path", "");
JSONObject req = JSON.parseObject(body);
String method = req.getString("method");
String path = req.getString("path");
if (ObjectUtils.isEmpty(path)) {
rsp.setCode(ApiRespCodeEnum.FAILED.getValue());
rsp.setMsg("path is empty!");
return Rest.fail(rsp.getMsg());
// return ResponseEntity.ok().body(JSON.toJSONString(rsp));
}
/* String method = params.getOrDefault("method", "post");
params.remove("method");
params.remove("path");*/
req.remove("method");
req.remove("path");
String targetUrl = "http://127.0.0.1:11078/basics_api" + path; // 目标 URL
String targetUrl = "http://127.0.0.1:11078" + path; // 目标 URL
// 拼接 Query 参数
HttpUrl.Builder urlBuilder = HttpUrl.parse(targetUrl).newBuilder();
params.forEach(urlBuilder::addQueryParameter);
......@@ -160,19 +143,16 @@ public class ProxyController {
Request.Builder requestBuilder = new Request.Builder()
.url(url)
.post(requestBody);
// 透传 Headers(过滤掉 Host 避免冲突)
headers.forEach((key, value) -> {
if (!key.equalsIgnoreCase("host")) {
requestBuilder.addHeader(key, value);
}
});
// 发送请求
try (Response response = client.newCall(requestBuilder.build()).execute()) {
if (!response.isSuccessful()) {
return Rest.fail(response.code(), response.message());
// return ResponseEntity.status(response.code()).body(response.message());
}
if ("/base/matter/channel/interlist".equals(path)) {
......@@ -182,64 +162,54 @@ public class ProxyController {
for (int i = 0; i < dataJSONArray.size(); i++) {
JSONObject jsonObject = dataJSONArray.getJSONObject(i);
String icon = jsonObject.getString("icon");
if (!ObjectUtils.isEmpty(icon) && icon.startsWith("/file")) {
String filePath = uploadService.getFilePath(icon);
String base64Str = Base64.encode(new File(filePath));
log.info("base64Str:{}", base64Str);
jsonObject.put("icon", base64Str);
boolean empty = FileUtil.isEmpty(new File(filePath));
if (!empty) {
String base64Str = Base64.encode(new File(filePath));
//log.info("base64Str:{}", base64Str);
jsonObject.put("icon", base64Str);
}
}
String qrCode = jsonObject.getString("qrCode");
if (!ObjectUtils.isEmpty(qrCode) && qrCode.startsWith("/file")) {
String filePath = uploadService.getFilePath(qrCode);
String base64Str = Base64.encode(new File(filePath));
log.info("base64Str:{}", base64Str);
jsonObject.put("qrCode", base64Str);
//log.info("base64Str:{}", base64Str);
boolean empty = FileUtil.isEmpty(new File(filePath));
if (!empty) {
jsonObject.put("qrCode", base64Str);
}
}
}
return Rest.ok("透传请求成功!", rspJson.toJSONString());
}
return Rest.ok("透传请求成功!", response.body().string());
// return ResponseEntity.status(response.code()).body(response.body().string());
} catch (IOException e) {
rsp.setCode(ApiRespCodeEnum.FAILED.getValue());
rsp.setMsg("Proxy error: " + e.getMessage());
return Rest.fail(rsp.getMsg());
// return ResponseEntity.ok().body(JSON.toJSONString(rsp));
}
} else if ("get".equalsIgnoreCase(method)) {
Map<String, Object> map = req.toJavaObject(Map.class);
/* String bodyParams = getBodyParams(map);
log.info(bodyParams);*/
// String urlGet = HttpUtil.urlWithForm(url.toString(), map, Charset.forName("utf-8"), false);
try {
String resp = HttpUtil.get(url.toString(), map, 30 * 1000);
//todo 将文件转换成base64
if ("/base/matter/interinfo".equals(path)) {
JSONObject rspJson = JSON.parseObject(resp);
JSONObject data = rspJson.getJSONObject("data");
String tid = data.getString("tid");
if (!ObjectUtils.isEmpty(tid) && tid.startsWith("/file")) {
String filePath = uploadService.getFilePath(tid);
String base64Str = Base64.encode(new File(filePath));
log.info("base64Str:{}", base64Str);
data.put("tid", base64Str);
return Rest.ok("透传请求成功!", rspJson.toJSONString());
boolean empty = FileUtil.isEmpty(new File(filePath));
if (!empty) {
String base64Str = Base64.encode(new File(filePath));
//log.info("base64Str:{}", base64Str);
data.put("tid", base64Str);
}
}
return Rest.ok("透传请求成功!", rspJson.toJSONString());
}
......
......@@ -68,7 +68,7 @@ Content-Type: application/json
{"page": 1,
"size": 10,
"path": "/entservice/ent/life/cycle/interlist",
"path": "/base/matter/channel/interlist",
"method": "post"
}
......
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