暑假的时候做的识别验证码的API,做出来了,不过后来有发现可以绕过验证码,
只上代码
发现过程详见 原博客地址:http://blog.csdn.net/away_d/article/details/47613829
博客已转移至现网易博客。
- <?php
- header("Content-Type: text/html; charset=utf-8");
- function login_get($url, $cookie) {
- $curl = curl_init();//初始化curl模块
- curl_setopt($curl, CURLOPT_URL, $url);//登录提交的地址
- curl_setopt($curl, CURLOPT_HEADER, 0);//是否显示头信息
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);//是否自动显示返回的信息
- curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie); //设置Cookie信息保存在指定的文件中
- curl_setopt($curl, CURLOPT_GET, 1);//提交方式
- $rs=curl_exec($curl);//执行
- curl_close($curl);
- <span style="white-space:pre"> </span>return $rs;
- }
- function get_content($url, $cookie) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); //读取cookie
- $rs = curl_exec($ch); //执行cURL抓取页面内容
- curl_close($ch);
- return $rs;
- }
- //设置cookie保存路径
- $cookie = dirname(__FILE__) . '/cookie.txt';
- //登录地址
- $id='学号';
- $psw='密码';
- $pswd=strtoupper(md5($psw));//密码md5加密且转为全大写
- $url = "http://202.119.81.112:9080/njlgdx/xk/LoginToXk?method=verify&USERNAME=$id&PASSWORD=$pswd";
- //登录
- login_get($url, $cookie);
- //登录后要获取信息的地址 ,获取登录页的信息
- $url2='http://202.119.81.112:9080/njlgdx/xskb/xskb_list.do?Ves632DSdyV=NEW_XSD_PYGL';//课表地址
- $content=get_content($url2, $cookie);
- //删除cookie文件
- @ unlink($cookie);
- echo $content;
- ?>
function _http($url,$data='',$cookiefile='',$cookiejar=''){
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if($cookiefile){
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
}
curl_setopt($ch, CURLOPT_REFERER, $url);
if($data){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect'));
}
if($cookiejar){
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 500);
$str=curl_exec($ch);
curl_close($ch);
return $str;
}