Home  >  Article  >  Backend Development  >  PHP判别任何类型的验证码图片

PHP判别任何类型的验证码图片

WBOY
WBOYOriginal
2016-06-13 11:53:03893browse

PHP识别任何类型的验证码图片

本帖最后由 xiaoxiaoa2 于 2013-06-15 12:45:48 编辑
<br><br><?php <br />/**<br>	说明:此类函数是基于优优云图片识别平台的API接口,调用类中的函数可以进行图片识别<br><br>	<br>	类中的公有函数:<br>		 setSoftInfo($softID,$softKey);				//设置软件ID和KEY<br>		 userLogin($userName,$passWord);			//用户登录,登录成功返回用户的ID<br>		 getPoint($userName,$passWord);				//获取用户剩余题分<br>		 upload($imagePath,$codeType);				//根据图片路径上传,返回验证码在服务器的ID,$codeType取值查看:http://www.uuwise.com/price.html<br>		 getResult($codeID);						//根据验证码ID获取识别结果<br>		 autoRecognition($imagePath,$codeType);		//将upload和getResult放到一个函数来执行,返回验证码识别结果<br>		 reportError($codeID);						//识别结果不正确报错误<br>		 regUser($userName,$userPassword)			//注册新用户,注册成功返回新用户的ID<br>		 pay($userName,$Card);						//充值题分,充值成功返回用户当前题分<br>	<br>	类中的公有变量:<br>		 $macAddress='00e021ac7d';					//客户机的mac地址,服务器暂时没有用,后期准备用于绑定mac地址		赋值方法: $obj->macAddress='00e021ac7d'; <br>		 $timeOut='60000';							//超时时间,建议不要改动此值									赋值方法: $obj->timeOut=60000;<br>		 <br>	函数调用方法:<br>		 需要先new一个对象<br>		 $obj=new uuApi;<br>		 $obj->setSoftInfo('2097','b7ee76f547e34516bc30f6eb6c67c7db');	//如何获取这两个值?请查看这个页面:http://dll.uuwise.com/index.php?n=ApiDoc.GetSoftIDandKEY<br>		 $obj->userLogin('userName','userPassword');<br>		 $result=autoRecognition($imagePath,$codeType);<br>		<br>*/<br><br>class uuApi{<br>	<br>	private $softID;<br>	private $softKEY;<br>	private $userName;<br>	private $userPassword;<br>	<br>	private $uid;<br>	private $userKey;<br>	private $softContentKEY;<br>	<br>	private $uuUrl;<br>	private $uhash;<br>	private $uuVersion='1.1.0.1';<br>	private $userAgent;<br>	private $gkey;<br>	<br>	public $macAddress='00e021ac7d';	//客户机的mac地址,服务器暂时没有用,后期准备用于绑定mac地址		赋值方法: $obj->macAddress='00e021ac7d'; <br>	public $timeOut=60000;				//超时时间,建议不要改动此值									赋值方法: $obj->timeOut=60000;<br>	<br>	public function setSoftInfo($id,$key)<br>	{<br>		if($id&&$key){<br>			$this->softID=$id;<br>			$this->softKEY=$key;<br>			$this->uhash=md5($id.strtoupper($key));<br>			return 'YES';<br>		}<br>		return 'NO';<br>	}<br>	private function getServerUrl($Server)<br>	{<br>		$url = "http://common.taskok.com:9000/Service/ServerConfig.aspx";<br>		$result=$this->uuGetUrl($url,array(),$postData=false);<br>		preg_match_all("/\,(.*?)\:101\,(.*?)\:102\,(.*?)\:103/", $result, $match_index);<br>		$arr=array_filter($match_index);<br>		if(empty($arr)){return '-1001';}<br>		switch($Server)<br>		{<br>			case 'service':<br>				return 'http://'.$match_index[1][0];<br>				break;<br>			case 'upload':<br>				return 'http://'.$match_index[2][0];<br>				break;<br>			case 'code':<br>				return 'http://'.$match_index[3][0];<br>				break;<br>			default:<br>				return 'parameter error';<br>		}<br>		curl_close($this->uuUrl);<br>	}<br>	public function userLogin($userName,$passWord)<br>	{<br>		if(!($this->softID&&$this->softKEY))<br>		{<br>			return 'sorry,SoftID or softKey is not set! Please use the setSoftInfo(id,key) function to set!';<br>		}<br>		if(!($userName&&$passWord)){ return 'userName or passWord is empty!';}<br>		$this->userName=$userName;<br>		$this->userPassword=$passWord;<br>		$this->userAgent=md5(strtoupper($this->softKEY).strtoupper($this->userName)).$this->macAddress;<br>		<br>		$url = $this->getServerUrl('service').'/Upload/Login.aspx?U='.$this->userName.'&P='.md5($this->userPassword).'&R='.mktime();<br>		$result=$this->uuGetUrl($url);<br>		<br>		if($result>0)<br>		{<br>			$this->userKey=$result;<br>			$this->uid=explode("_",$this->userKey);<br>			$this->uid=$this->uid[0];<br>			$this->softContentKEY=md5(strtolower($this->userKey.$this->softID.$this->softKEY));<br>			$this->gkey=md5(strtoupper($this->softKEY.$this->userName)).$this->macAddress;<br>			return $this->uid;<br>		}<br>		return $result;<br><br>	}<br>	public function getPoint($userName,$passWord)<br>	{<br>		if(!($userName&&$passWord)){ return 'userName or passWord is empty!';}<br>		$url = $this->getServerUrl('service').'/Upload/GetScore.aspx?U='.$userName.'&P='.md5($passWord).'&R='.mktime();<br>		$result=$this->uuGetUrl($url);<br>		return $result;<br>	}<br>	public function upload($imagePath,$codeType,$auth=false)<br>	{<br>		if(!file_exists($imagePath)){return '-1003';}<br>		if(!is_numeric($codeType)){return '-3004';}<br>		$data=array(<br>			'img'=>'@'.$imagePath,<br>			'key'=>$this->userKey,<br>			'sid'=>$this->softID,<br>			'skey'=>$this->softContentKEY,<br>			'TimeOut'=>$this->timeOut,<br>			'Type'=>$codeType<br>		);<br>		$ver=array(<br>			'Version'=>'100',<br>		);<br>		if($auth){$data=$data+$ver;}<br>		$url = $this->getServerUrl('upload').'/Upload/Processing.aspx?R='.mktime();<br>		return $this->uuGetUrl($url,$data);<br>	}<br>	public function getResult($codeID)<br>	{<br>		if(!is_numeric($codeID)){return '-1009|The codeID is not number';}<br>		$url = $this->getServerUrl('code').'/Upload/GetResult.aspx?KEY='.$this->userKey.'&ID='.$codeID.'&Random='.mktime();<br>		$result='-3';<br>		$timer=0;<br>		while($result=='-3'&&($timertimeOut))<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn