本人用的是网上的Java版本,经过本人的改良只剩下验证码识别。

有人运行出现了4个#,解决方法如下:

1、如果是单独运行imagepreprocess.java则把srcpath和trainpath改成你此项目的具体路径+字典路径,如下:

	public  static String srcPath = "C:\\Users\\liujin\\Workspaces\\MyEclipse 10\\WhxyJw\\WebRoot\\images\\ctrackcode\\srcimg\\";
	public  static String trainPath ="C:\\Users\\liujin\\Workspaces\\MyEclipse 10\\WhxyJw\\WebRoot\\images\\ctrackcode\\trainimg\\";

2、如果是jsp运行,则修改项目里面的basepath.jsp

点击下载

将此工程导入myeclipse

	ImagePreProcess.srcPath = ctrackcode_srcimg;
	ImagePreProcess.trainPath = ctrackcode_trainimg;
	String name = request.getParameter("c").toString();      //给图片加个缓存名称
        String checkcodeUrl = request.getParameter("url").toString();  //此图片的地址

	String checkCodeImg="a";
	String secretcode = "";
			try{
				 checkCodeImg = ImagePreProcess.downloadImage(checkcodeUrl+"?", name+".png");				 
			}catch(Exception e){
			}
			if (checkCodeImg != "a" ||checkCodeImg != null ) {
					secretcode = ImagePreProcess.getAllOcr(checkCodeImg);
					File ml =new File(checkCodeImg);
					ml.delete();
					out.print(secretcode);
			}

测试地址:

http://www.unique-liu.com:8080/WhxyJw/yzm.jsp?c=312fz&url=http://61.142.33.204/CheckCode.aspx

若非正方教务平台的请改这里的值:

----非正方区----

QQ截图20160222140817.jpg

修改那两个值

----非正方结束----

由于众所周知,验证码需要加入cookie去获取

所以我单独写了一个php的请求验证码:

$url = "http://61.142.33.204/CheckCode.aspx";  
$curl = curl_init();
if($_POST){
$cookie=$_POST['c'];
}else{
	$cookie=$_GET['c'];
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($curl);
curl_close($curl);
$filename=substr($cookie,-10);
$a="./yzm/2".$filename.".png";  //将其保存为图片放在服务器
$fp = fopen($a,"wb");
fwrite($fp, $data);
fclose($fp);

然后用保存在服务器的图片,用PHP请求识别:

//大众性
$login_url="http://www.kejibu.org:8080/WhxyJw/yzm.jsp";
$l=$login_url."?c={$filename}&url=http://www.kejibu.org/cx/yzm/2{$filename}.png";
//部分PHP传值会出现问题则用下面的
/*
$login_url="http://www.kejibu.org:8080/WhxyJw/yzm.jsp";
$fileurl="http://www.kejibu.org/cx/yzm/2{$filename}.png";
$fileurl=urlencode($fileurl);
$l=$login_url."?c={$filename}&url={$fileurl}";
*/
		$ch=curl_init();
		curl_setopt($ch, CURLOPT_URL,$l);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_TIMEOUT, 10);
	        $yyy=curl_exec($ch);
		curl_close($ch);
		echo substr($yyy,-4);

整合出来:

$url = "http://61.142.33.204/CheckCode.aspx";  
$curl = curl_init();
if($_POST){
$cookie=$_POST['c'];
}else{
	$cookie=$_GET['c'];
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($curl);
curl_close($curl);
$filename=substr($cookie,-10);
$a="./yzm/2".$filename.".png";
$fp = fopen($a,"wb");
fwrite($fp, $data);
fclose($fp);

$login_url="http://www.kejibu.org:8080/WhxyJw/yzm.jsp";
$l=$login_url."?c={$filename}&url=http://www.kejibu.org/cx/yzm/2{$filename}.png";
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL,$l);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$yyy=curl_exec($ch);
curl_close($ch);
echo substr($yyy,-4);
unlink($a);             //删除服务器保存的验证码图片

返回的直接是识别出来的验证码。

正确率比对地址:

http://www.unique-liu.cn/sj/index.php