0.0.1 done

This commit is contained in:
qaiu
2023-04-21 23:30:50 +08:00
parent ca166184ba
commit 1bb2a53511
38 changed files with 296 additions and 145 deletions

View File

@@ -0,0 +1,29 @@
package cn.qaiu.lz;
import cn.qaiu.vx.core.Deploy;
import io.vertx.core.json.JsonObject;
/**
* 程序入口
* <br>Create date 2021-05-08 13:00:01
*
* @author qiu
*/
public class AppMain {
public static void main(String[] args) {
// 注册枚举类型转换器
Deploy.instance().start(args, AppMain::exec);
}
/**
*
* @param jsonObject 配置
*/
private static void exec(JsonObject jsonObject) {
//
}
}

View File

@@ -0,0 +1,22 @@
package cn.qaiu.lz.common;
import io.vertx.core.json.JsonObject;
/**
* lz-web <br>
* 实现此接口 POJO转JSON对象
*
* @author <a href="https://qaiu.top">QAIU</a>
* <br>Create date 2021/8/27 11:40
*/
public interface ToJson {
/**
* POJO转JSON对象
*
* @return Json Object
*/
default JsonObject toJson() {
return JsonObject.mapFrom(this);
}
}

View File

@@ -0,0 +1,29 @@
package cn.qaiu.lz.common.interceptorImpl;
import cn.qaiu.vx.core.base.BaseHttpApi;
import cn.qaiu.vx.core.interceptor.Interceptor;
import cn.qaiu.vx.core.model.JsonResult;
import cn.qaiu.vx.core.util.CommonUtil;
import cn.qaiu.vx.core.util.SharedDataUtil;
import cn.qaiu.vx.core.util.VertxHolder;
import io.vertx.core.json.JsonArray;
import io.vertx.core.shareddata.LocalMap;
import io.vertx.ext.web.RoutingContext;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
/**
* 默认拦截器实现
* 校验用户是否合法 <br>
* TODO 暂时只做简单实现
*/
@Slf4j
public class DefaultInterceptor implements Interceptor, BaseHttpApi {
private final JsonArray ignores = SharedDataUtil.getJsonArrayForCustomConfig("ignoresReg");
@Override
public void handle(RoutingContext ctx) {
ctx.next();
}
}

View File

@@ -0,0 +1,29 @@
package cn.qaiu.lz.common.model;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
*
* @author <a href="https://qaiu.top">QAIU</a>
* <br>Create date 2021/7/22 3:34
*/
@DataObject
@Data
@NoArgsConstructor
public class MyData implements Serializable {
public static final long serialVersionUID = 1L;
private String id;
private String maxSize;
public MyData(JsonObject jsonObject) {
// TODO
}
}

View File

@@ -0,0 +1,35 @@
package cn.qaiu.lz.common.model;
import cn.qaiu.lz.common.ToJson;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* lz-web
*
* @author <a href="https://qaiu.top">QAIU</a>
* <br>Create date 2021/8/10 11:10
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@DataObject
public class UserInfo implements ToJson {
private String username;
private String permission;
private String pwdCrc32;
private String uuid;
public UserInfo(JsonObject jsonObject) {
this.username = jsonObject.getString("username");
this.permission = jsonObject.getString("permission");
this.pwdCrc32 = jsonObject.getString("pwdCrc32");
}
}

View File

@@ -0,0 +1,20 @@
package cn.qaiu.lz.common.util;
public class ArrayUtil {
public static int[] parseIntArray(String[] arr) {
int[] ints = new int[arr.length];
for (int i = 0; i < ints.length; i++) {
ints[i] = Integer.parseInt(arr[i]);
}
return ints;
}
public static float[] parseFloatArray(String[] arr) {
float[] ints = new float[arr.length];
for (int i = 0; i < ints.length; i++) {
ints[i] = Float.parseFloat(arr[i]);
}
return ints;
}
}

View File

@@ -0,0 +1,19 @@
package cn.qaiu.lz.common.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 获取连接
*
* @author <a href="https://qaiu.top">QAIU</a>
*/
public enum ConnectUtil {
// 实现枚举单例
INSTANCE;
private static final Logger LOGGER = LoggerFactory.getLogger(ConnectUtil.class);
}

View File

@@ -0,0 +1,82 @@
package cn.qaiu.lz.common.util;
import cn.qaiu.vx.core.util.CastUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.vertx.core.http.HttpClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import java.io.IOException;
import java.util.Map;
/**
* @author <a href="https://qaiu.top">QAIU</a>
* @date 2023/4/21 21:19
*/
@Slf4j
public class CowTool {
/*
First request:
{
"code": "0000",
"message": "success",
"data": {
"guid": "e4f41b51-b5da-4f60-9312-37aa10c0aad7",
"firstFile": {
"id": "23861191276513345",
}
}
}
Then request:
{
"code": "0000",
"message": "success",
"tn": "TN:DE0E092E8A464521983780FBA21D0CD3",
"data": {
"downloadUrl": "https://download.cowcs.com..."
}
}
*/
public static String parse(String fullUrl) throws IOException {
String uniqueUrl = fullUrl.substring(fullUrl.lastIndexOf('=') + 1);
String baseUrl = "https://cowtransfer.com/core/api/transfer/share";
String result = Jsoup
.connect(baseUrl + "?uniqueUrl=" + uniqueUrl).ignoreContentType(true)
.get()
.text();
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> map = objectMapper.readValue(result, new TypeReference<>() {
});
if ("success".equals(map.get("message")) && map.containsKey("data")) {
Map<String, Object> data = CastUtil.cast(map.get("data"));
String guid = data.get("guid").toString();
Map<String, Object> firstFile = CastUtil.cast(data.get("firstFile"));
String fileId = firstFile.get("id").toString();
String result2 = Jsoup
.connect(baseUrl + "/download?transferGuid=" + guid + "&fileId=" + fileId)
.ignoreContentType(true)
.get()
.text();
Map<String, Object> map2 = objectMapper.readValue(result2, new TypeReference<>() {
});
if ("success".equals(map2.get("message")) && map2.containsKey("data")) {
Map<String, Object> data2 = CastUtil.cast(map2.get("data"));
String downloadUrl = data2.get("downloadUrl").toString();
if (StringUtils.isNotEmpty(downloadUrl)) {
log.info("cow parse success: {}", downloadUrl);
return downloadUrl;
}
}
}
log.info("Cow parse field------------->end");
return null;
}
}

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

@@ -0,0 +1,10 @@
/**
* lz-web
* <br>Create date 2021/7/8 13:29
*
* @author <a href="https://qaiu.top">QAIU</a>
*/
@ModuleGen(name = "proxy", groupPackage = "cn.qaiu.lz", useFutures = true)
package cn.qaiu.lz;
import io.vertx.codegen.annotations.ModuleGen;

View File

@@ -0,0 +1,80 @@
package cn.qaiu.lz.web.http;
import cn.qaiu.lz.common.util.CowTool;
import cn.qaiu.lz.common.util.LzTool;
import cn.qaiu.lz.web.model.RealUser;
import cn.qaiu.lz.web.service.UserService;
import cn.qaiu.vx.core.annotaions.RouteHandler;
import cn.qaiu.vx.core.annotaions.RouteMapping;
import cn.qaiu.vx.core.enums.RouteMethod;
import cn.qaiu.vx.core.model.JsonResult;
import cn.qaiu.vx.core.util.AsyncServiceUtil;
import io.vertx.core.Future;
import io.vertx.core.http.HttpServerResponse;
import lombok.extern.slf4j.Slf4j;
/**
* 服务API
* <br>Create date 2021/4/28 9:15
*
* @author <a href="https://qaiu.top">QAIU</a>
*/
@Slf4j
@RouteHandler("/")
public class ServerApi {
private final UserService userService = AsyncServiceUtil.getAsyncServiceInstance(UserService.class);
@RouteMapping(value = "/login", method = RouteMethod.POST)
public Future<String> login(RealUser user) {
log.info("<------- login: {}", user.getUsername());
return userService.login(user);
}
@RouteMapping(value = "/test2", method = RouteMethod.GET)
public JsonResult<String> test01() {
return JsonResult.data("ok");
}
@RouteMapping(value = "/parse", method = RouteMethod.GET)
public void parse(HttpServerResponse response, String url) throws Exception {
if (url.contains("lanzou")) {
String urlDownload = LzTool.parse(url);
log.info("url = {}", urlDownload);
response.putHeader("location", urlDownload).setStatusCode(302).end();
} else if (url.contains("cowtransfer.com")) {
String urlDownload = CowTool.parse(url);
response.putHeader("location", urlDownload).setStatusCode(302).end();
}
}
@RouteMapping(value = "/lz/:id", method = RouteMethod.GET)
public void lzParse(HttpServerResponse response, String id) throws Exception {
String url = "https://wwa.lanzoux.com/" + id;
String urlDownload = LzTool.parse(url);
log.info("url = {}", urlDownload);
response.putHeader("location", urlDownload).setStatusCode(302).end();
}
@RouteMapping(value = "/cow/:id", method = RouteMethod.GET)
public void cowParse(HttpServerResponse response, String id) throws Exception {
String url = "https://cowtransfer.com/core/api/transfer/share?uniqueUrl=" + id;
String urlDownload = CowTool.parse(url);
response.putHeader("location", urlDownload).setStatusCode(302).end();
}
@RouteMapping(value = "/json/lz/:id", method = RouteMethod.GET)
public JsonResult<String> lzParseJson(HttpServerResponse response, String id) throws Exception {
String url = "https://wwa.lanzoux.com/" + id;
String urlDownload = LzTool.parse(url);
log.info("url = {}", urlDownload);
return JsonResult.data(urlDownload);
}
@RouteMapping(value = "/json/cow/:id", method = RouteMethod.GET)
public JsonResult<String> cowParseJson(HttpServerResponse response, String id) throws Exception {
String url = "https://cowtransfer.com/core/api/transfer/share?uniqueUrl=" + id;
return JsonResult.data(CowTool.parse(url));
}
}

View File

@@ -0,0 +1,22 @@
package cn.qaiu.lz.web.model;
import cn.qaiu.lz.common.ToJson;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
@DataObject
public class RealUser implements ToJson {
private String username;
private String password;
public RealUser(JsonObject json) {
this.username = json.getString("username");
this.password = json.getString("password");
}
}

View File

@@ -0,0 +1,19 @@
package cn.qaiu.lz.web.service;
import cn.qaiu.lz.common.model.UserInfo;
import cn.qaiu.vx.core.base.BaseAsyncService;
import io.vertx.codegen.annotations.ProxyGen;
import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;
/**
* lz-web
* <br>Create date 2021/7/12 17:16
*
* @author <a href="https://qaiu.top">QAIU</a>
*/
@ProxyGen
public interface DbService extends BaseAsyncService {
Future<JsonObject> sayOk(String data);
Future<JsonObject> sayOk2(String data, UserInfo holder);
}

View File

@@ -0,0 +1,18 @@
package cn.qaiu.lz.web.service;
import cn.qaiu.vx.core.util.CastUtil;
import java.lang.reflect.Proxy;
/**
* JDK代理类工厂
*/
public class JdkProxyFactory {
public static <T> T getProxy(T target) {
return CastUtil.cast(Proxy.newProxyInstance(
target.getClass().getClassLoader(),
target.getClass().getInterfaces(),
new ServiceJdkProxy<>(target))
);
}
}

View File

@@ -0,0 +1,29 @@
package cn.qaiu.lz.web.service;
import lombok.extern.slf4j.Slf4j;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* lz-web
* <br>Create date 2021/8/25 14:28
*
* @author <a href="https://qaiu.top">QAIU</a>
*/
@Slf4j
public class ServiceJdkProxy<T> implements InvocationHandler {
private final T target;
public ServiceJdkProxy(T target) {
this.target = target;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
return method.invoke(target, args);
}
}

View File

@@ -0,0 +1,17 @@
package cn.qaiu.lz.web.service;
import cn.qaiu.vx.core.base.BaseAsyncService;
import cn.qaiu.lz.web.model.RealUser;
import io.vertx.codegen.annotations.ProxyGen;
import io.vertx.core.Future;
/**
* lz-web
* <br>Create date 2021/8/27 14:06
*
* @author <a href="https://qaiu.top">QAIU</a>
*/
@ProxyGen
public interface UserService extends BaseAsyncService {
Future<String> login(RealUser user);
}

View File

@@ -0,0 +1,38 @@
package cn.qaiu.lz.web.service.impl;
import cn.qaiu.lz.common.model.UserInfo;
import cn.qaiu.lz.web.service.DbService;
import cn.qaiu.vx.core.annotaions.Service;
import cn.qaiu.vx.core.model.JsonResult;
import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;
import lombok.extern.slf4j.Slf4j;
/**
* lz-web
* <br>Create date 2021/7/12 17:26
*
* @author <a href="https://qaiu.top">QAIU</a>
*/
@Slf4j
@Service
public class DbServiceImpl implements DbService {
@Override
public Future<JsonObject> sayOk(String data) {
log.info("say ok1 -> wait...");
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return Future.succeededFuture(JsonObject.mapFrom(JsonResult.data("Hi: " + data)));
}
@Override
public Future<JsonObject> sayOk2(String data, UserInfo holder) {
// val context = VertxHolder.getVertxInstance().getOrCreateContext();
// log.info("say ok2 -> " + context.get("username"));
// log.info("--> {}", holder.toString());
return Future.succeededFuture(JsonObject.mapFrom(JsonResult.data("Hi: " + data)));
}
}

View File

@@ -0,0 +1,22 @@
package cn.qaiu.lz.web.service.impl;
import cn.qaiu.lz.web.model.RealUser;
import cn.qaiu.lz.web.service.UserService;
import cn.qaiu.vx.core.annotaions.Service;
import io.vertx.core.Future;
/**
* lz-web
* <br>Create date 2021/8/27 14:09
*
* @author <a href="https://qaiu.top">QAIU</a>
*/
@Service
public class UserServiceImpl implements UserService {
@Override
public Future<String> login(RealUser user) {
return Future.succeededFuture("111");
}
}

View File

@@ -0,0 +1,31 @@
###
GET http://127.0.0.1:6400/api/serverApi/test3?fullUrl=https://wwp.lanzoux.com/iNvid035jgcb
###
# @no-redirect
GET http://127.0.0.1:6400/parse?url=https://lanzoux.com/ia2cntg
###
# @no-redirect
GET http://127.0.0.1:6400/parse?url=https://cowtransfer.com/core/api/transfer/share?uniqueUrl=9a644fe3e3a748
###
# @no-redirect
GET http://127.0.0.1:6400/cow/9a644fe3e3a748
###
GET http://127.0.0.1:6400/lz/ia2cntg
###
GET http://127.0.0.1:6400/json/lz/ia2cntg
###
https://cowtransfer.com/core/api/transfer/share?uniqueUrl=9a644fe3e3a748
###
https://cowtransfer.com/core/api/transfer/share?uniqueUrl=e4f41b51b5da4f
###
https://cowtransfer.com/core/api/transfer/share/download?transferGuid=e4f41b51-b5da-4f60-9312-37aa10c0aad7&fileId=23861191276513345
//https://download.cowcs.com/cowtransfer/cowtransfer/29188/db32e132e69f490eb4a343b398990f4b.docx?auth_key=1682111861-7b9579fbebb84aaba6bca368d083ab12-0-cbf009f3ffbcbb86191b8cdbc103abce&biz_type=1&business_code=COW_TRANSFER&channel_code=COW_CN_WEB&response-content-disposition=attachment%3B%20filename%3D05-CGB-DB-MENU-V1.02.docx%3Bfilename*%3Dutf-8%27%2705-CGB-DB-MENU-V1.02.docx&user_id=1023860921943729188&x-verify=1

View File

@@ -0,0 +1,47 @@
###
http://127.0.0.1:8088/real/test
###
POST http://127.0.0.1:8088/real/serverApi/login
Content-Type: application/x-www-form-urlencoded
username=sa&password=sinoreal
###
POST http://47.114.185.111:8070/real/serverApi/login
Content-Type: application/x-www-form-urlencoded
username=sa&password=sinoreal
###
http://127.0.0.1:8088/real/serverApi/hello2/ok2
token: 11f1a7ad9dd907bf1fa6a9e79277d053
###
http://127.0.0.1:8088/real/test2
###
POST http://127.0.0.1:8088/real/serverApi/getConnections
token: 370ba165d3164049b7704e8b3d595930
###
POST http://127.0.0.1:8085/real/serverApi/getConnectionInfo
token: 21f99c6080074ae79cda2e988ab2bdb8
###
http://127.0.0.1:7070/demo/foo
###
http://127.0.0.1:8085/api/foo
###
http://127.0.0.1:8085/real/serverApi/thread-test
token: c1b89b3193bd4498be77b6e782e0df38
###
http://127.0.0.1:8085/
Accept: application/json

View File

@@ -0,0 +1,32 @@
# 服务配置
server:
port: 6400
contextPath: /
enableStaticHtmlService: false
staticResourcePath: webroot/
# 反向代理服务器配置路径(不用加后缀)
proxyConf: server-proxy
vertx:
eventLoopPoolSize: 8
workerPoolSize: 20
custom:
asyncServiceInstances: 8
routerLocations: cn.qaiu.lz.web.http
interceptorClassPath: cn.qaiu.lz.common.interceptorImpl.DefaultInterceptor
handlerLocations: cn.qaiu.lz.web.service
ignoresReg:
- .*/login$
- .*/test.*$
entityPackagesReg:
- ^cn\.qaiu\.lz\.web\.model\..*
otherConfig:
- dictionaries.json
errorPage404: /index.html
indexPage: /test2
sharedLogin: true
lzConfig:
config: '111'
cowConfig:
config: '111'

View File

@@ -0,0 +1,7 @@
# 要激活的配置: dev--连接本地数据库; prod连接线上数据库
active: dev
# 框架版本号 和主版本号
version_vertx: 4.1.3
version_app: 0.0.1
# 公司名称 -> LOGO版权文字
copyright: QAIU

View File

@@ -0,0 +1,3 @@
{
}

View File

@@ -0,0 +1,3 @@
curl -F "file=@C:\Users\qaiu\Desktop\real\lz-web\web\src\main\resources\logback.xml" -i -XPOST 127.0.0.1:8088/demo/basePointApi/importTags
curl -F "file=@C:\Users\qaiu\Desktop\3.csv" -i -XPOST 127.0.0.1:8088/demo/basePointApi/importTags

View File

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