极验验证码流程-4字段加密
总共有2个字段需要加密
String url="http://api.geetest.com/ajax.php?challenge="+challenge+"&userresponse="+userresponse+"&passtime="+passtime+"&imgload=112&a="+a+"&callback=geetest_"+t; //59929742
日记写的有点晚了 印象有点浅了 基本就是调js 模拟这2个参数
import java.io.FileNotFoundException;
import java.io.FileReader;
import javax.script.Invocable;
import javax.script.ScriptException;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
/** * Java调用并执行js文件,传递参数,并活动返回值 * * @author manjushri */
public class ScriptEngineTest {
public static String userresponse(int move,String chanllenge) throws NoSuchMethodException, ScriptException{
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("javascript");
String s="function test(a, b) {for (var c = b.slice(32), d = [], e = 0; e < c.length; e++) { var f = c.charCodeAt(e); d[e] = f > 57 ? f - 87 : f - 48}c = 36 * d[0] + d[1];var g = Math.round(a) + c;b = b.slice(0, 32);var h, i = [[], [], [], [], []], j = {}, k = 0;e = 0;for (var l = b.length; l > e; e++)h = b.charAt(e),j[h] || (j[h] = 1,i[k].push(h),k++,k = 5 == k ? 0 : k);for (var m, n = g, o = 4, p = '', q = [1, 2, 5, 10, 50]; n > 0; )n - q[o] >= 0 ? (m = parseInt(Math.random() * i[o].length, 10),p += i[o][m],n -= q[o]) : (i.splice(o, 1),q.splice(o, 1),o -= 1);return p}";
engine.eval(s);
if(engine instanceof Invocable) {
Invocable invoke = (Invocable)engine; // 调用merge方法,并传入两个参数
String user = (String)invoke.invokeFunction("test",move,chanllenge);
//System.out.println("userresponse = " + user);
return user;
}
return "error";
}
public static String getencode(String time,int move,int usetime) throws NoSuchMethodException, ScriptException, FileNotFoundException{
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("javascript");
String jsFileName = "C:\\Users\\Administrator\\Desktop\\move.js"; // 读取js文件
FileReader reader = new FileReader(jsFileName);
engine.eval( reader);
if(engine instanceof Invocable) {
Invocable invoke = (Invocable)engine; // 调用merge方法,并传入两个参数
String user = (String)invoke.invokeFunction("encode",time,move,usetime);
//System.out.println("userresponse = " + user);
return user;
}
return "error";
}
public static String userresponse2(int move,String chanllenge) throws NoSuchMethodException, ScriptException, FileNotFoundException{
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("javascript");
String jsFileName = "C:\\Users\\Administrator\\Desktop\\userresponse.js"; // 读取js文件
FileReader reader = new FileReader(jsFileName);
engine.eval( reader);
if(engine instanceof Invocable) {
Invocable invoke = (Invocable)engine; // 调用merge方法,并传入两个参数
String user = (String)invoke.invokeFunction("aa",move,chanllenge);
//System.out.println("userresponse = " + user);
return user;
}
return "error";
}
}
move.js