蓝奏云API BUG修复

This commit is contained in:
QAIU
2023-04-21 17:39:09 +08:00
parent f089d050b1
commit ca166184ba
7 changed files with 148 additions and 236 deletions

View File

@@ -4,14 +4,16 @@ import cn.qaiu.vx.core.annotaions.DateFormat;
import cn.qaiu.vx.core.annotaions.RouteHandler; import cn.qaiu.vx.core.annotaions.RouteHandler;
import cn.qaiu.vx.core.annotaions.RouteMapping; import cn.qaiu.vx.core.annotaions.RouteMapping;
import cn.qaiu.vx.core.annotaions.SockRouteMapper; import cn.qaiu.vx.core.annotaions.SockRouteMapper;
import cn.qaiu.vx.core.base.BaseHttpApi;
import cn.qaiu.vx.core.enums.MIMEType; import cn.qaiu.vx.core.enums.MIMEType;
import cn.qaiu.vx.core.model.JsonResult; import cn.qaiu.vx.core.model.JsonResult;
import cn.qaiu.vx.core.base.BaseHttpApi;
import cn.qaiu.vx.core.util.*; import cn.qaiu.vx.core.util.*;
import io.vertx.core.Future; import io.vertx.core.Future;
import io.vertx.core.Handler; import io.vertx.core.Handler;
import io.vertx.core.MultiMap; import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpMethod; import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject; import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.Route; import io.vertx.ext.web.Route;
@@ -46,7 +48,7 @@ import static io.vertx.core.http.HttpHeaders.*;
public class RouterHandlerFactory implements BaseHttpApi { public class RouterHandlerFactory implements BaseHttpApi {
private static final Logger LOGGER = LoggerFactory.getLogger(RouterHandlerFactory.class); private static final Logger LOGGER = LoggerFactory.getLogger(RouterHandlerFactory.class);
private static final Set<HttpMethod> httpMethods = new HashSet<HttpMethod>() {{ private static final Set<HttpMethod> httpMethods = new HashSet<>() {{
add(HttpMethod.GET); add(HttpMethod.GET);
add(HttpMethod.POST); add(HttpMethod.POST);
add(HttpMethod.OPTIONS); add(HttpMethod.OPTIONS);
@@ -95,7 +97,7 @@ public class RouterHandlerFactory implements BaseHttpApi {
return Integer.compare(routeHandler2.order(), routeHandler1.order()); return Integer.compare(routeHandler2.order(), routeHandler1.order());
}; };
// 获取处理器类列表 // 获取处理器类列表
List<Class<?>> sortedHandlers = handlers.stream().sorted(comparator).collect(Collectors.toList()); List<Class<?>> sortedHandlers = handlers.stream().sorted(comparator).toList();
for (Class<?> handler : sortedHandlers) { for (Class<?> handler : sortedHandlers) {
try { try {
// 注册请求处理方法 // 注册请求处理方法
@@ -292,11 +294,11 @@ public class RouterHandlerFactory implements BaseHttpApi {
String fmt = getFmt(v.getLeft(), v.getRight()); String fmt = getFmt(v.getLeft(), v.getRight());
String value = queryParams.get(k); String value = queryParams.get(k);
parameterValueList.put(k, ReflectionUtil.conversion(v.getRight(), value, fmt)); parameterValueList.put(k, ReflectionUtil.conversion(v.getRight(), value, fmt));
} else if ("io.vertx.ext.web.RoutingContext".equals(v.getRight().getName())) { } else if (RoutingContext.class.getName().equals(v.getRight().getName())) {
parameterValueList.put(k, ctx); parameterValueList.put(k, ctx);
} else if ("io.vertx.core.http.HttpServerRequest".equals(v.getRight().getName())) { } else if (HttpServerRequest.class.getName().equals(v.getRight().getName())) {
parameterValueList.put(k, ctx.request()); parameterValueList.put(k, ctx.request());
} else if ("io.vertx.core.http.HttpServerResponse".equals(v.getRight().getName())) { } else if (HttpServerResponse.class.getName().equals(v.getRight().getName())) {
parameterValueList.put(k, ctx.response()); parameterValueList.put(k, ctx.response());
} else if (CommonUtil.matchRegList(entityPackagesReg.getList(), v.getRight().getName())) { } else if (CommonUtil.matchRegList(entityPackagesReg.getList(), v.getRight().getName())) {
// 绑定实体类 // 绑定实体类
@@ -371,7 +373,7 @@ public class RouterHandlerFactory implements BaseHttpApi {
*/ */
private String getFmt(Annotation[] parameterAnnotations, CtClass v) { private String getFmt(Annotation[] parameterAnnotations, CtClass v) {
String fmt = ""; String fmt = "";
if ("java.util.Date".equals(v.getName())) { if (Date.class.getName().equals(v.getName())) {
for (Annotation annotation : parameterAnnotations) { for (Annotation annotation : parameterAnnotations) {
if (annotation instanceof DateFormat) { if (annotation instanceof DateFormat) {
fmt = ((DateFormat) annotation).value(); fmt = ((DateFormat) annotation).value();

View File

@@ -60,12 +60,13 @@ public class ReverseProxyVerticle extends AbstractVerticle {
private void handleProxyConfList(JsonObject config) { private void handleProxyConfList(JsonObject config) {
serverName = config.getString("server-name"); serverName = config.getString("server-name");
JsonArray proxyConfList = config.getJsonArray("proxy"); JsonArray proxyConfList = config.getJsonArray("proxy");
if (proxyConfList != null) {
proxyConfList.forEach(proxyConf -> { proxyConfList.forEach(proxyConf -> {
if (proxyConf instanceof JsonObject) { if (proxyConf instanceof JsonObject) {
handleProxyConf((JsonObject) proxyConf); handleProxyConf((JsonObject) proxyConf);
} }
}); });
}
} }
/** /**

View File

@@ -48,6 +48,11 @@
<version>4.13.2</version> <version>4.13.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.15.4</version>
</dependency>
</dependencies> </dependencies>

View File

@@ -0,0 +1,93 @@
package cn.qaiu.lz.common.util;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.jsoup.Jsoup;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author QAIU
* @version 1.0 update 2021/5/16 10:39
*/
public class LzTool {
public static String parse(String fullUrl) throws Exception {
String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.3";
String url = fullUrl.substring(0, fullUrl.lastIndexOf('/') + 1);
String id = fullUrl.substring(fullUrl.lastIndexOf('/') + 1);
Map<String, String> header = new HashMap<>();
header.put("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2");
header.put("referer", url);
/*
// 部分链接需要设置安卓UA
sec-ch-ua: "Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"
sec-ch-ua-mobile: ?1
sec-ch-ua-platform: "Android"
*/
String userAgent2 = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Mobile Safari/537.36";
Map<String, String> header2 = new HashMap<>();
header2.put("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2");
header2.put("sec-ch-ua-mobile", "sec-ch-ua-mobile");
header2.put("sec-ch-ua-platform", "Android");
header2.put("referer", url);
//第一次请求获取iframe的地址
String result = Jsoup.connect(url + id)
.userAgent(userAgent)
.get()
.select(".ifr2")
.attr("src");
//第二次请求得到js里的json数据里的sign
result = Jsoup.connect(url + result)
.headers(header)
.userAgent(userAgent)
.get()
.html();
System.out.println(result);
Matcher matcher = Pattern.compile("'[\\w]+_c_c'").matcher(result);
Map<String, String> params = new LinkedHashMap<>();
if (matcher.find()) {
String sn = matcher.group().replace("'", "");
params.put("action", "downprocess");
params.put("sign", sn);
params.put("ves", "1");
System.out.println(sn);
} else {
throw new IOException();
}
//第三次请求 通过参数发起post请求,返回json数据
result = Jsoup
.connect(url + "ajaxm.php")
.headers(header)
.userAgent(userAgent)
.data(params)
.post()
.text()
.replace("\\", "");
//json转为map
params = new ObjectMapper().readValue(result, new TypeReference<Map<String, String>>() {});
System.out.println(params);
//通过json的数据拼接出最终的URL发起第最终请求,并得到响应信息头
url = params.get("dom") + "/file/" + params.get("url");
Map<String, String> headers = Jsoup.connect(url)
.ignoreContentType(true)
.userAgent(userAgent2)
.headers(header2)
.followRedirects(false)
.execute()
.headers();
//得到重定向的地址进行重定向
url = headers.get("Location");
return url;
}
}

View File

@@ -1,17 +1,15 @@
package cn.qaiu.lz.web.http; package cn.qaiu.lz.web.http;
import cn.qaiu.lz.common.util.LzTool;
import cn.qaiu.lz.web.model.RealUser;
import cn.qaiu.lz.web.service.UserService; import cn.qaiu.lz.web.service.UserService;
import cn.qaiu.vx.core.annotaions.RouteHandler; import cn.qaiu.vx.core.annotaions.RouteHandler;
import cn.qaiu.vx.core.annotaions.RouteMapping; import cn.qaiu.vx.core.annotaions.RouteMapping;
import cn.qaiu.vx.core.annotaions.SockRouteMapper;
import cn.qaiu.vx.core.enums.RouteMethod; import cn.qaiu.vx.core.enums.RouteMethod;
import cn.qaiu.vx.core.model.JsonResult; import cn.qaiu.vx.core.model.JsonResult;
import cn.qaiu.vx.core.util.AsyncServiceUtil; import cn.qaiu.vx.core.util.AsyncServiceUtil;
import cn.qaiu.vx.core.util.SnowflakeIdWorker;
import cn.qaiu.vx.core.util.VertxHolder;
import cn.qaiu.lz.web.model.RealUser;
import io.vertx.core.Future; import io.vertx.core.Future;
import io.vertx.ext.web.handler.sockjs.SockJSSocket; import io.vertx.core.http.HttpServerResponse;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
/** /**
@@ -32,45 +30,17 @@ public class ServerApi {
return userService.login(user); return userService.login(user);
} }
long sid = 0;
@SockRouteMapper(value = "/test")
public void test02(SockJSSocket sock) {
String s = sock.writeHandlerID();
System.out.println("客户端连接 --> " + s);
sock.handler(sock::write);
sock.endHandler(v -> System.out.println("客户端断开"));
String id = sock.writeHandlerID();
System.out.println("客户端连接 --> " + id);
// sock.handler(sock::write);
sock.handler(buffer -> {
sock.write("服务端开始处理------->");
final String msg = buffer.toString();
if ("1".equals(msg)) {
sid = VertxHolder.getVertxInstance().setPeriodic(1000, v ->
sock.write(v + "-->" + SnowflakeIdWorker.idWorker().nextId()));
} else {
if (sid != 0) {
if (VertxHolder.getVertxInstance().cancelTimer(sid)) {
sock.write(sid + " -----> 定时推送取消");
}
} else {
sock.write(msg + "----- ok");
}
}
});
sock.endHandler(v -> {
System.out.println("客户端断开");
if (VertxHolder.getVertxInstance().cancelTimer(sid)) {
sock.write(sid + " -----> 定时推送取消");
}
});
}
@RouteMapping(value = "/test2", method = RouteMethod.GET) @RouteMapping(value = "/test2", method = RouteMethod.GET)
public JsonResult<String> test01() { public JsonResult<String> test01() {
return JsonResult.data("ok"); return JsonResult.data("ok");
} }
@RouteMapping(value = "/test3", method = RouteMethod.GET)
public void test03(HttpServerResponse response, String fullUrl) throws Exception {
String url = LzTool.parse(fullUrl);
log.info("url = {}", url);
response.putHeader("location", "http://baidu.com").setStatusCode(302).end();
}
} }

View File

@@ -1,163 +1,4 @@
### ###
POST http://127.0.0.1:8088/real/serverApi/login GET http://127.0.0.1:6400/api/serverApi/test3?fullUrl=https://wwp.lanzoux.com/iNvid035jgcb
Content-Type: application/x-www-form-urlencoded
username=sa&password=sinoreal
### ###
POST http://47.114.185.111:8088/real/serverApi/login GET http://127.0.0.1:6400/api/serverApi/test3?fullUrl=https://lanzoux.com/ia2cntg
Content-Type: application/x-www-form-urlencoded
username=sa&password=sinoreal
###
GET http://127.0.0.1:8088/real/basePointApi/getTables
token: cab5bcd2fc250f27c3984205fbffc46e
Content-Type: application/json
###
GET http://127.0.0.1:8088/real/basePointApi/getTags?tablemask=JTdevice
token: 7670b1a3da5e22ffc42a1e738ea4f0f6
###
GET http://127.0.0.1:8088/real/basePointApi/getSnapshotDataByTag/adasd?aaa=3
token: 7670b1a3da5e22ffc42a1e738ea4f0f6
###
POST http://127.0.0.1:8088/real/serverApi/login
Content-Type: application/json
{
"username": "sa",
"password": "sinoreal"
}
###
POST http://127.0.0.1:8088/real/basePointApi/updateTag
token: cab5bcd2fc250f27c3984205fbffc46e
Content-Type: application/json
{
"userints": [123223,35356],
"id": 123,
"equation": "asd",
"trigger": "RTDB_EVENT_TRIGGER",
"shutdown": true
}
###
GET http://127.0.0.1:8088/real/basePointApi/getTagById/753
token: eb7d391ad89d4bb4a81897af8829f0e8
###
GET http://127.0.0.1:8088/real/basePointApi/aaaa
token: cab5bcd2fc250f27c3984205fbffc46e
###
GET http://127.0.0.1:8088/real/serverApi/test
###
POST http://127.0.0.1:8088/real/serverApi/addUser
Content-Type: application/x-www-form-urlencoded
token: 2b4769b63c90adb6490cfe6e449da90b
username=sa1&password=sinoreal&permission=3
###
POST http://127.0.0.1:8088/real/serverApi/removeUser
Content-Type: application/x-www-form-urlencoded
token: 2b4769b63c90adb6490cfe6e449da90b
username=sa1
###
POST http://127.0.0.1:8088/real/serverApi/updatePassword
Content-Type: application/x-www-form-urlencoded
token: 33c21f7cf053b90a713f1f9e124d0335
oldPassword=sinoreal1&newPassword=sinoreal
###
POST http://127.0.0.1:8088/real/serverApi/changePriv
Content-Type: application/x-www-form-urlencoded
token: 2b4769b63c90adb6490cfe6e449da90b
username=sa1&permission=3
###
POST http://127.0.0.1:8088/real/serverApi/addAuthorization
Content-Type: application/x-www-form-urlencoded
token: 2b4769b63c90adb6490cfe6e449da90b
addr=192.168.1.56&mask=255.255.255.255&permission=3&description=测试信任666111
###
POST http://127.0.0.1:8088/real/serverApi/removeAuthorization
Content-Type: application/x-www-form-urlencoded
token: 2b4769b63c90adb6490cfe6e449da90b
addr=192.168.1.56&mask=255.255.255.255
###
POST http://127.0.0.1:8088/real/historyApi/getHistory
Content-Type: application/x-www-form-urlencoded
token: 2b4769b63c90adb6490cfe6e449da90b
startDate=2021-05-17 11:03&endDate=2021-05-17 11:04&interval=3
###
POST http://127.0.0.1:8088/real/historyApi/getHistory
Content-Type: application/x-www-form-urlencoded
token: 2b4769b63c90adb6490cfe6e449da90b
startDate=2021-05-17 11:03
###
GET http://127.0.0.1:8088/real/dict/getDictByName?name=dict2
token: 7670b1a3da5e22ffc42a1e738ea4f0f6
###
tagmask=*&desc=*&_PointType=Every&_ValueTypeString=*&_TimeAccuracy=-1&_SearchCondition=SEARCH_NULL&SearchMaskValue=*&source=*&instrument=*&
###
http://127.0.0.1:8088/real/basePointApi/getTags?tablemask=demo02&tagmask=*&desc=*&_PointType=Every&_ValueTypeString=*&_TimeAccuracy=-1&_SearchCondition=SEARCH_NULL&SearchMaskValue=*&source=*&instrument=*&pageNumber=1&pageSize=10
token: eb7d391ad89d4bb4a81897af8829f0e8
###
http://127.0.0.1:8088/real/serverApi/getFile?path=D:
token: 7670b1a3da5e22ffc42a1e738ea4f0f6
###
#http://127.0.0.1:8088/real/serverApi/hello1/:msg
http://127.0.0.1:8088/real/serverApi/hello1/ok1
token: a3cada4c97be40d3bc35cfe6ec1288ab
###
http://127.0.0.1:8088/real/serverApi/hello2/ok2
token: a3cada4c97be40d3bc35cfe6ec1288ab
###
http://127.0.0.1:8085/real/basePointApi/getTags?tablemask=demo02&tagmask=*&desc=*&unit=*&pointType=Every&valueTypeString=*&timeAccuracy=-1&searchCondition=SEARCH_NULL&SearchMaskValue=*&source=*&instrument=*&pageNumber=1&pageSize=10&accurateSearch=
token: c423c04a55964571bd34aaa1683229e8

View File

@@ -1,27 +1,27 @@
# 反向代理 # 反向代理
server-name: Vert.x-proxy-server(v4.1.2) server-name: Vert.x-proxy-server(v4.1.2)
proxy: #proxy:
- listen: 8085 # - listen: 8085
# 404的路径 # # 404的路径
404: webroot/real-html/index.html # 404: webroot/real-html/index.html
static: # static:
path: / # path: /
# add-headers: ## add-headers:
# x-token: ABC ## x-token: ABC
root: webroot/real-html/ # root: webroot/real-html/
index: realIndex # index: realIndex
location: # location:
- path: /real/ # - path: /real/
origin: 127.0.0.1:8088 # origin: 127.0.0.1:8088
- path: /api/ # - path: /api/
origin: 127.0.0.1:7070/demo/ # origin: 127.0.0.1:7070/demo/
#
- listen: 8086 # - listen: 8086
static: # static:
path: /t2/ # path: /t2/
root: webroot/test/ # root: webroot/test/
index: sockTest.html # index: sockTest.html
# location: # location:
# - path: /real/ # - path: /real/
# origin: 127.0.0.1:8088 # origin: 127.0.0.1:8088