mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2025-12-17 21:03:03 +00:00
添加 通过JS文件获取123pan签名
This commit is contained in:
47
web-service/src/test/java/cn/qaiu/web/test/TestJs.java
Normal file
47
web-service/src/test/java/cn/qaiu/web/test/TestJs.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package cn.qaiu.web.test;
|
||||
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
* @date 2023/7/29 17:15
|
||||
*/
|
||||
public class TestJs {
|
||||
|
||||
/**
|
||||
* 调用js文件获取url
|
||||
*
|
||||
*/
|
||||
private static String excuteJs() throws ScriptException,
|
||||
IOException, NoSuchMethodException {
|
||||
ScriptEngineManager engineManager = new ScriptEngineManager();
|
||||
ScriptEngine engine = engineManager.getEngineByName("JavaScript"); // 得到脚本引擎
|
||||
String reader = null;
|
||||
//获取文件所在的相对路径
|
||||
//String text = System.getProperty("user.dir");
|
||||
//reader = text + "\\src\\main\\resources\\test.js";
|
||||
|
||||
String path = TestJs.class.getResource("/").getPath();
|
||||
System.out.println(path);
|
||||
reader = path + "/test.js";
|
||||
FileReader fReader = new FileReader(reader);
|
||||
engine.eval(fReader);
|
||||
|
||||
Invocable inv = (Invocable) engine;
|
||||
//调用js中的方法
|
||||
Object test2 = inv.invokeFunction("add", 1, 2);
|
||||
String url = test2.toString();
|
||||
fReader.close();
|
||||
return url;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws ScriptException, IOException, NoSuchMethodException {
|
||||
String s = excuteJs();
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
3
web-service/src/test/resources/test.js
Normal file
3
web-service/src/test/resources/test.js
Normal file
@@ -0,0 +1,3 @@
|
||||
function add(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
Reference in New Issue
Block a user