#1、Java和Js之间的调用时基于ScriptEngineManager类
ScriptEngineManager engine =new ScriptEngineManager();
#2、获取scriptEngine对象
ScriptEngine jsEngine = engine.getEngineByName("JavaScript");
#3、调用eval函数执行脚本
获取js文件的地址
Resource resource =new ClassPathResource("static/cryptojs.js");
jsEngine.eval(new BufferedReader(new InputStreamReader(resource.getInputStream())));
String str = String.format("__a(JSON.stringify({a: '%s',b: '%s',c: '%s'}), __d('%s'))",
"", webSite.getAccount(), webSite.getPassword()
, secretKey);
Object c = jsEngine.eval(str);
网友评论