<?php
set_time_limit(0);
error_reporting(E_ALL);
$url = "http://www.ems.com.cn/qcgzOutQueryAction.do?reqCode=gotoSearch";
$url2 = "http://www.ems.com.cn/qcgzOutQueryAction.do";
$cookie_jar= dirname(__FILE__) ."/test.cookie";
if(isset($_POST)&&$_POST){
$mailNum= $_POST["mailNum"];
$myEmsbarCode = $_POST["myEmsbarCode"];
$imgpost = $_POST["$imgname"];
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL,$url2);
$post="reqCode=browseBASE&myEmsbarCode=$myEmsbarCode&mailNum=$mailNum&$imgname=$imgpost";
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS,$post); curl_setopt($ch2,CURLOPT_REFERER,$url);
curl_setopt($ch2, CURLOPT_HEADER, false);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_jar);
$content2 = curl_exec($ch2);
curl_close($ch2);
preg_match('/td class="txt-main" align="left">(.*)<form name="form1"/isU',$content2,$res); echo $res[1];
}else{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
<HEAD>
<title>快递查询</title>
<script>
<!--function checkdata(v){
if(v){
var dzzmailnum = this.document.form1.DzzmailNum.value;
if(''==dzzmailnum){
alert("请输入查询单证照号!");
form1.DzzmailNum.focus();
return false;
}else{
trackagainform.style.display = "none";
progress.style.display = "";
return true;
}
}
var bool;
var str;
var len;
var i;
var charsets;
bool="true";
charnum="0123456789";
charsets="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
str=this.document.form1.mailNum.value;
len=str.length;
if (str=="") {
bool="false1";
}
else{
if (len!=13) {
bool="false2";
}
else {
if ((charsets.indexOf(str.substring(0,1))==-1)||(charsets.indexOf(str.substring(1,2))==-1)) {bool="false3";}
for(i=2;i<11;i++) {
//alert(charnum.indexOf(ch,0));
if (charnum.indexOf(str.substring(i,i+1),0)<0) {bool="false4";}
}
if ((charsets.indexOf(str.substring(11,12))==-1)||(charsets.indexOf(str.substring(12,13))==-1)) {bool="false5";}
// if(4!=document.form1.checknumone.value.length) {bool="false6";}
}
}
if (bool!="true") {
if (bool=="false1") {alert("用户查询的输入值不能为空!");bool="true";return false;}
if (bool=="false2") {alert("输入值必须为13位!");bool="true";return false;}
if (bool=="false3") {alert("输入值前两位必须为字符!");bool="true";return false;}
if (bool=="false4") {alert("输入值第3位至第11位必须为数字123456789!");bool="true";return false;}
if (bool=="false5") {alert("输入值后两位必须为字符!");bool="true";return false;}
// if (bool=="false6") {alert("请输入4位查询验证码!");return false;}
}
else {
form1.submit();
}
}
-->
</script>
</head>
<base ><BODY>
<DIV class=col>
<form name="form1" method="post" action=""
onSubmit="return checkdata(false);">
<table border="0" cellpadding="0" cellspacing="0" width="450" align="center">
<td height=25 colspan="3" align="center"><strong>请输入验证码</strong>
</td>
<tr>
<td height=25>
您的单号:
</td> <td colspan="2" align="left">
<input type="text" name="mailNum" value="EH135844022CN"/>
<input type="hidden" name="reqCode" value="browseBASE"/>
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($ch,CURLOPT_COOKIE,$cookie_jar);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch,CURLOPT_REFERER,$url);
$content=curl_exec($ch);
preg_match('/name="myEmsbarCode" value="(.*)"/i',$content,$myEmsbarCode);
curl_close($ch);
$myEmsbarCode=$myEmsbarCode[1];
?>
<input type="" name="myEmsbarCode" value="<?php echo $myEmsbarCode ?>"/>
</td>
</tr>
<tr>
<td height=25>
验证码:
</td>
<td align="left">
<?php
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, "http://www.ems.com.cn/servlet/ImageCapServlet");
curl_setopt($ch1,CURLOPT_REFERER,$url);
curl_setopt($ch1, CURLOPT_HEADER, false);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch1, CURLOPT_COOKIEFILE, $cookie_jar);
$img=curl_exec($ch1);
curl_close($ch1);
preg_match('/<input name="(.*)" type="text" maxlength="5"/i',$content,$imgname);
$imgname = $imgname[1];
?>
<INPUT type="text" name="<?php echo $imgname?>" maxlength="5"/>
</td>
<td>
<input type="submit" name="Submit2" value=" 查 询 ">
</td>
</tR>
</table>
</form>
</DIV></BODY></HTML>
<?php
}
?>
set_time_limit(0);
error_reporting(E_ALL);
$url = "http://www.ems.com.cn/qcgzOutQueryAction.do?reqCode=gotoSearch";
$url2 = "http://www.ems.com.cn/qcgzOutQueryAction.do";
$cookie_jar= dirname(__FILE__) ."/test.cookie";
if(isset($_POST)&&$_POST){
$mailNum= $_POST["mailNum"];
$myEmsbarCode = $_POST["myEmsbarCode"];
$imgpost = $_POST["$imgname"];
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL,$url2);
$post="reqCode=browseBASE&myEmsbarCode=$myEmsbarCode&mailNum=$mailNum&$imgname=$imgpost";
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS,$post); curl_setopt($ch2,CURLOPT_REFERER,$url);
curl_setopt($ch2, CURLOPT_HEADER, false);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_jar);
$content2 = curl_exec($ch2);
curl_close($ch2);
preg_match('/td class="txt-main" align="left">(.*)<form name="form1"/isU',$content2,$res); echo $res[1];
}else{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
<HEAD>
<title>快递查询</title>
<script>
<!--function checkdata(v){
if(v){
var dzzmailnum = this.document.form1.DzzmailNum.value;
if(''==dzzmailnum){
alert("请输入查询单证照号!");
form1.DzzmailNum.focus();
return false;
}else{
trackagainform.style.display = "none";
progress.style.display = "";
return true;
}
}
var bool;
var str;
var len;
var i;
var charsets;
bool="true";
charnum="0123456789";
charsets="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
str=this.document.form1.mailNum.value;
len=str.length;
if (str=="") {
bool="false1";
}
else{
if (len!=13) {
bool="false2";
}
else {
if ((charsets.indexOf(str.substring(0,1))==-1)||(charsets.indexOf(str.substring(1,2))==-1)) {bool="false3";}
for(i=2;i<11;i++) {
//alert(charnum.indexOf(ch,0));
if (charnum.indexOf(str.substring(i,i+1),0)<0) {bool="false4";}
}
if ((charsets.indexOf(str.substring(11,12))==-1)||(charsets.indexOf(str.substring(12,13))==-1)) {bool="false5";}
// if(4!=document.form1.checknumone.value.length) {bool="false6";}
}
}
if (bool!="true") {
if (bool=="false1") {alert("用户查询的输入值不能为空!");bool="true";return false;}
if (bool=="false2") {alert("输入值必须为13位!");bool="true";return false;}
if (bool=="false3") {alert("输入值前两位必须为字符!");bool="true";return false;}
if (bool=="false4") {alert("输入值第3位至第11位必须为数字123456789!");bool="true";return false;}
if (bool=="false5") {alert("输入值后两位必须为字符!");bool="true";return false;}
// if (bool=="false6") {alert("请输入4位查询验证码!");return false;}
}
else {
form1.submit();
}
}
-->
</script>
</head>
<base ><BODY>
<DIV class=col>
<form name="form1" method="post" action=""
onSubmit="return checkdata(false);">
<table border="0" cellpadding="0" cellspacing="0" width="450" align="center">
<td height=25 colspan="3" align="center"><strong>请输入验证码</strong>
</td>
<tr>
<td height=25>
您的单号:
</td> <td colspan="2" align="left">
<input type="text" name="mailNum" value="EH135844022CN"/>
<input type="hidden" name="reqCode" value="browseBASE"/>
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($ch,CURLOPT_COOKIE,$cookie_jar);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch,CURLOPT_REFERER,$url);
$content=curl_exec($ch);
preg_match('/name="myEmsbarCode" value="(.*)"/i',$content,$myEmsbarCode);
curl_close($ch);
$myEmsbarCode=$myEmsbarCode[1];
?>
<input type="" name="myEmsbarCode" value="<?php echo $myEmsbarCode ?>"/>
</td>
</tr>
<tr>
<td height=25>
验证码:
</td>
<td align="left">
<?php
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, "http://www.ems.com.cn/servlet/ImageCapServlet");
curl_setopt($ch1,CURLOPT_REFERER,$url);
curl_setopt($ch1, CURLOPT_HEADER, false);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch1, CURLOPT_COOKIEFILE, $cookie_jar);
$img=curl_exec($ch1);
curl_close($ch1);
preg_match('/<input name="(.*)" type="text" maxlength="5"/i',$content,$imgname);
$imgname = $imgname[1];
?>
<INPUT type="text" name="<?php echo $imgname?>" maxlength="5"/>
</td>
<td>
<input type="submit" name="Submit2" value=" 查 询 ">
</td>
</tR>
</table>
</form>
</DIV></BODY></HTML>
<?php
}
?>
set_time_limit(0);
error_reporting(E_ALL);
$url = "http://www.ems.com.cn/qcgzOutQueryAction.do?reqCode=gotoSearch";
$url2 = "http://www.ems.com.cn/qcgzOutQueryAction.do";
$cookie_jar= dirname(__FILE__) ."/test.cookie";
if(isset($_POST)&&$_POST){
$mailNum= $_POST["mailNum"];
$myEmsbarCode = $_POST["myEmsbarCode"];
$imgpost = $_POST["$imgname"];
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL,$url2);
$post="reqCode=browseBASE&myEmsbarCode=$myEmsbarCode&mailNum=$mailNum&$imgname=$imgpost";
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS,$post); curl_setopt($ch2,CURLOPT_REFERER,$url);
curl_setopt($ch2, CURLOPT_HEADER, false);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_jar);
$content2 = curl_exec($ch2);
curl_close($ch2);
preg_match('/td class="txt-main" align="left">(.*)<form name="form1"/isU',$content2,$res); echo $res[1];
}else{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
<HEAD>
<title></title>
</head>
<base ><BODY>
<DIV class=col>
<form name="form1" method="post" action=""
onSubmit="return checkdata(false);">
<table border="0" cellpadding="0" cellspacing="0" width="450" align="center">
<td height=25 colspan="3" align="center"><strong>请输入验证码</strong>
</td>
<tr>
<td height=25>
您的单号:
</td> <td colspan="2" align="left">
<input type="text" name="mailNum" value="EH135844022CN"/>
<input type="hidden" name="reqCode" value="browseBASE"/>
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($ch,CURLOPT_COOKIE,$cookie_jar);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch,CURLOPT_REFERER,$url);
$content=curl_exec($ch);
preg_match('/name="myEmsbarCode" value="(.*)"/i',$content,$myEmsbarCode);
curl_close($ch);
$myEmsbarCode=$myEmsbarCode[1];
?>
<input type="" name="myEmsbarCode" value="<?php echo $myEmsbarCode ?>"/>
</td>
</tr>
<tr>
<td height=25>
验证码:
</td>
<td align="left">
</td>
<td>
<input type="submit" name="Submit2" value=" 查 询 ">
</td>
</tR>
</table>
</form>
</DIV></BODY></HTML>
<?php
}
?>
只说一下思路:
1.用curl把图片保存下来,同时要保存cookie
2.验证码识别(机器识别也好,手工识别也好)
3.用第一步的cookie,提交登录数据
curl_setopt($ch1, CURLOPT_URL, "http://www.ems.com.cn/servlet/ImageCapServlet");
curl_setopt($ch1,CURLOPT_REFERER,$url);
curl_setopt($ch1, CURLOPT_HEADER, false);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1, CURLOPT_COOKIEFILE, $cookie_jar);
$img = curl_exec($ch1);
curl_close($ch1);
file_put_contents('img.tmp', $img);
(能验证EMS,有C#代码)
官方卖2600,这里吐血价只卖299!有意请Q->34477240,注明“亦思”http://www.cnblogs.com/robinli/archive/2010/04/19/1715328.html