问题描述
文件1code.php:<?phpheader("Content-type:text/html;charset=utf-8");include_once('conn/funcs.php');//自定义函数include('conn/Valite.php');$confirmId=$_GET['confirmId'];$data=getcurl("http://wap.cmgame.com:8080/portalone/WebGameQueryPicVcode?confirmId=".$confirmId);$path="code/".date("Ymd")."/";$fname=date("His").rand(1,9999).'.jpg';loginlog($path,$data,$fname);$valite=newValite();$valite->setImage($path.$fname);$valite->getHec();$ert=$valite->run();//$ert="1234";print_r($ert);@unlink($path.$fname);?>
解决方案
解决方案二:
============================================================================================文件二codeWENDA.php:<?phpheader("Content-type:text/html;charset=utf-8");include_once('conn/funcs.php');//自定义函数$Keys=array('0'=>'11111111111110000000001111111111111111111111110000000000000111111111111111111111000111111111000111111111111111111100111111111111100111111111111111111011111111111111101111111111111111110111111111111111011111111111111111100111111111111100111111111111111111100011111111100011111111111111111111100000000000001111111111111111111111110000000001111111111111','1'=>'1111111111101111111111111011111111111111111111011111111111110111111111111111111110111111111111101111111111111111111000000000000000011111111111111111100000000000000000111111111111111111111111111111111001111111111111111111111111111111111011111111111111111111111111111111110111111111','2'=>'111111111110000111111111001111111111111111111011001111111010011111111111111111101111111111101100111111111111111111011111111110111001111111111111111110111111111011110011111111111111111101111111101111100111111111111111111001111100111111001111111111111111111000000011111100011111111111111111111000011111100000111111111','3'=>'111111111110001111111000111111111111111111111000011111110000111111111111111111101111111111111110111111111111111111011111101111111101111111111111111110111111011111111011111111111111111100111100011111110111111111111111111100000010011110011111111111111111111100001110000000111111111111111111111111111110000111111111111','4'=>'11111111111111111110011111111111111111111111111111110010111111111111111111111111111111011101111111111111111111111111111001111011111111111111111111111111101111110111101111111111111111111101111111101111011111111111111111110000000000000000111111111111111111000000000000000001111111111111111111111111111101111011111111111111111111111111111011110111111111','5'=>'111111111111111111111000111111111111111111110000000001110010111111111111111111100111111111111110111111111111111111001111011111111101111111111111111110011110111111111011111111111111111100111101111111110111111111111111111001111001111110001111111111111111110011111000000000111111111111111111100111111000000111111111111','6'=>'11111111111111000000001111111111111111111111111000000000000111111111111111111111000111101111000111111111111111111110111110111111100111111111111111111011111011111111101111111111111111110111110111111111011111111111111111101111101111111110111111111111111111000111000111110011111111111111111111001111000000000111111111111111111111111111100000111111111111','7'=>'111111111100001111111111111111111111111111110001111111111111111111111111111111100111111111111111111111111111111111001111111111000001111111111111111110011111110000000011111111111111111100111110011111111111111111111111111001111111111111111111111111111111110011111111111111111111111111111111100111111111111111111111111','8'=>'11111111111000011110000011111111111111111111100000011000000011111111111111111110011100000111110111111111111111111101111100011111110111111111111111111011111100111111101111111111111111110111111001111111011111111111111111101111110001111110111111111111111111001111000001111011111111111111111111000000110000000111111111111111111111000011111000011111111111','9'=>'11111111111100000011111111111111111111111111100000000011110011111111111111111111001111100011100011111111111111111101111111110111110111111111111111111011111111101111101111111111111111110111111111011111011111111111111111100111111101111101111111111111111111100111110111000011111111111111111111100000000000011111111111111111111111110000000011111111111111','-'=>'1111111111111111101111111111111111111111111111111111011111111111111111111111111111111110111111111111111111111111111111111101111111111111111111111111111111111011111111111111111111111111111111110111111111111111111111111111111111101111111111111111111111111111111111011111111111111111111111111111111110111111111111111111111111111111111101111111111111111111111111111111111011111111111111111','+'=>'1111111111111111101111111111111111111111111111111111011111111111111111111111111111111110111111111111111111111111111111111101111111111111111111111111111111111011111111111111111111111111110000000000000111111111111111111111111111101111111111111111111111111111111111011111111111111111111111111111111110111111111111111
111111111111111111101111111111111111111111111111111111011111111111111111','='=>'1111111111111101111011111111111111111111111111111011110111111111111111111111111111110111101111111111111111111111111111101111011111111111111111111111111111011110111111111111111111111111111110111101111111111111111111111111111101111011111111111111111111111111111011110111111111111111111111111111110111101111111111111111111111111111101111011111111111111111111111111111011110111111111111111','?'=>'11111111110000111111111111111111111111111111001001111111111111111111111111111110111111111111111111111111111111111011111111111111000111111111111111110111111110000110001111111111111111101111111001111100011111111111111111011111110111111111111111111111111110011110011111111111111111111111111110000000111111111111111111111111111110000011111111111111111111');functioncodeWENDA($path,$Keys){$data=array();//保存所有字符的完整特征码$flag=false;//每个字符结束的标识$str='';//保存单个字符特征码$result='';//保存匹配结果$max=98;//准确率$num="";$res=imagecreatefromgif($path);$size=getimagesize($path);if($size[1]!=35||$size[0]!=188){return99999;}//从上往下按列获取每个像素点for($i=0;$i<$size[0];++$i)//宽{$temp='';//每一列特征码for($j=0;$j<$size[1];++$j)//高{$rgb=imagecolorat($res,$i,$j);$rgbarray=imagecolorsforindex($res,$rgb);$ld=0.3*$rgbarray['red']+0.59*$rgbarray['green']+0.11*$rgbarray['blue'];if($ld>=135)$temp.="1";else$temp.="0";}if(strstr($temp,"0")){//如果这列出现了黑色表示一个字符开始$flag=true;$str.=$temp;}if(!strstr($temp,"0")&&$flag){//如果这列全是白色表示一个字符结束$flag=false;$data[]=$str;$str='';}if(count($data)==5)//如果已经获取了5个字符12+34break;}//循环匹配foreach($dataas$numString){foreach($Keysas$key=>$value)//特征码{$percent=0.0;similar_text($value,$numString,$percent);if(intval($percent)>=$max){$num=$key;break;}}if($num==="=")break;$result.=$num;}imagedestroy($res);returneval("return$result;");}$confirmId=$_GET['confirmId'];$data=getcurl("http://wap.cmgame.com:8080/portalone/WebGameQueryPicVcode?confirmId=".$confirmId);$path="code/".date("YmdH")."/";$fname=date("His").rand(1,9999).'.gif';loginlog($path,$data,$fname);$r=codeWENDA($path.$fname,$Keys);if($r==99999){//高度或宽度改变记录日志loginlog("code/","1","picERR.log");@unlink($path.$fname);echo"nokey";die;}echo$r;@unlink($path.$fname);?>
解决方案三:
=================================================================================文件三Valite.php:<?phpdefine('WORD_WIDTH',13);define('WORD_HIGHT',16);define('OFFSET_X',6);define('OFFSET_Y',4);define('WORD_SPACING',1);classvalite{publicfunctionsetImage($Image){$this->ImagePath=$Image;}publicfunctiongetData(){return$data;}publicfunctiongetResult(){return$DataArray;}publicfunctiongetHec(){$im=imagecreate(80,25);$white=imagecolorallocate($im,255,255,255);$black=imagecolorallocate($im,0,0,0);$res=imagecreatefromjpeg($this->ImagePath);$size=getimagesize($this->ImagePath);//print_r($size);$data=array();for($i=0;$i<$size[1];++$i){for($j=0;$j<$size[0];++$j){$rgb=imagecolorat($res,$j,$i);$rgbarray=imagecolorsforindex($res,$rgb);$ld=0.3*$rgbarray['red']+0.59*$rgbarray['green']+0.11*$rgbarray['blue'];//if($this->DataArray[$h][$w]==0)//elseif($ld>=135){$data[$i][$j]=0;imagesetpixel($im,$j,$i,$white);//echo"1";}else{$data[$i][$j]=1;imagesetpixel($im,$j,$i,$black);//echo"0";}}//echo"nn";}$this->DataArray=$data;$this->ImageSize=$size;}publicfunctionrun(){$result="";//查找5个数字$data=array("","","","");for($i=0;$i<4;++$i){$im=imagecreate(80,25);$white=imagecolorallocate($im,255,255,255);$black=imagecolorallocate($im,0,0,0);$x=($i*(WORD_WIDTH+WORD_SPACING))+OFFSET_X;$y=OFFSET_Y;for($h=$y;$h<(OFFSET_Y+WORD_HIGHT);++$h){for($w=$x;$w<($x+WORD_WIDTH);++$w){$data[$i].=$this->DataArray[$h][$w];if($this->DataArray[$h][$w]=='0'){imagesetpixel($im,$w,$h,$white);//echo'0';}else{imagesetpixel($im,$w,$h,$black);//echo'1';}}}}//进行关键字匹配foreach($dataas$numKey=>$numString){//echo$numString."<br/>";$max=0.0;$num=0;foreach($this->Keysas$key=>$value){$percent=0.0;similar_text($value,$numString,$percent);if(intval($percent)>$max){$max=$percent;$num=$key;if(intval($percent)>95)break;}}$result.=$num;}$this->data=$result;//查找最佳匹配数字return$result;}publicfunctionDraw(){for($i=0;$i<$this->ImageSize[1];++$i){for($j=0;$j<$this->ImageSize[0];++$j){echo$this->DataArray[$i][$j];}echo"n";}}publicfunction__construct(){$this->Keys=array('0'=>'0000000000000000011111000000011111110000011100011100001110001110001110000011100111000001110011100000111001110000011100111000001110011100000111001111111111111111100011100001110001110000011111110000000111110000','1'=>'1111110000000000001111110000111111000110011111100000000001110000000000111000000000011100000000001110000000000111000000000011100000000001110000011111111111110000011100000000001110000000111111111000011111111100','2'=>'1111110000000001111111110001111111110110100000111100000000001110000000000111000000000011100000000011100000000011100000000011100000000011100000011111111111110011100000000011100000000001111111111000111111111100','3'=>'1111110000000000111111110000111111110110010000111100000000001110000000000111000000000111000000111111000000011111100000000000111000000000001110011111111111110000000011100001000011110000111111110000001111100000','4'=>'0000000000000000000011100000000011110001111111111111000011011100000001101110000001100111000001100011100001100001110001100000111000111111111111011111111111101100000111000001111111100000000001111110000000111000','5'=>'0000000000000001111111110000111111111001111111111111001100000000000110000000000011111000000001111111000000000011110000000000111100000000001110000000000111001100000011100001111111100000111111111110001111100000','6'=>'0000000000000000001111100011111111111000011110111111001110000000001110000000000111001111000011111111110001111000111100111000001110011100000111011111100011100011001111111001110001110000011111111000000111110000','7'=>'0000000000000001111111111011111111111100000000111111000000000110000000000110000000000111000000000011000000000011100000000001100000000001110000011111110000000000111111111000011000000000011100000000001110000000','8'=>'0000000000000000011111000000011111110000011100011100001110001110000111000111000001111011000000111111000000011111110000011100111100011100001111001111111111111111000001110011110001111000111111111000000111110000','9'=>'0000000000000000011111000000111111110000011100011100011100000110001110000011100111000001110011100000111000111000111100011111111110000111110111000011111111111110000011100001000011110000111111110000001111100000',);}protected$ImagePath;protected$DataArray;protected$ImageSize;protected$data;protected$Keys;protected$NumStringArray;}?>
解决方案四:
=======================================================================================文件4funcs.php:<?phpheader('Content-type:text/html;charset=UTF-8');functionloginlog($file,$str,$type){if(!is_dir($file))mkdir($file);$fp=fopen($file.$type,"a+");fwrite($fp,$str);fclose($fp);}functiongetcurl($url){$ch=curl_init($url);curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);//获取数据返回curl_setopt($ch,CURLOPT_BINARYTRANSFER,true);//在启用CURLOPT_RETURNTRANSFER时候将获取数据返回$r=curl_exec($ch);curl_close($ch);return$r;}//CURL不要返回值执行1秒functiongetcurlNoReturn($url){$ch=curl_init($url);curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);//curl_setopt($ch,CURLOPT_BINARYTRANSFER,true);curl_setopt($ch,CURLOPT_TIMEOUT,1);curl_exec($ch);curl_close($ch);}?>