日期:2014-05-16  浏览次数:20429 次

PHP识别任何类型的验证码图片
本帖最后由 xiaoxiaoa2 于 2013-06-15 12:45:48 编辑


<?php
/**
说明:此类函数是基于优优云图片识别平台的API接口,调用类中的函数可以进行图片识别


类中的公有函数:
 setSoftInfo($softID,$softKey); //设置软件ID和KEY
 userLogin($userName,$passWord); //用户登录,登录成功返回用户的ID
 getPoint($userName,$passWord); //获取用户剩余题分
 upload($imagePath,$codeType); //根据图片路径上传,返回验证码在服务器的ID,$codeType取值查看:http://www.uuwise.com/price.html
 getResult($codeID); //根据验证码ID获取识别结果
 autoRecognition($imagePath,$codeType); //将upload和getResult放到一个函数来执行,返回验证码识别结果
 reportError($codeID); //识别结果不正确报错误
 regUser($userName,$userPassword) //注册新用户,注册成功返回新用户的ID
 pay($userName,$Card); //充值题分,充值成功返回用户当前题分

类中的公有变量:
 $macAddress='00e021ac7d'; //客户机的mac地址,服务器暂时没有用,后期准备用于绑定mac地址 赋值方法: $obj->macAddress='00e021ac7d'; 
 $timeOut='60000'; //超时时间,建议不要改动此值 赋值方法: $obj->timeOut=60000;
 
函数调用方法:
 需要先new一个对象
 $obj=new uuApi;
 $obj->setSoftInfo('2097','b7ee76f547e34516bc30f6eb6c67c7db'); //如何获取这两个值?请查看这个页面:http://dll.uuwise.com/index.php?n=ApiDoc.GetSoftIDandKEY
 $obj->userLogin('userName','userPassword');
 $result=autoRecognition($imagePath,$codeType);

*/

class uuApi{

private $softID;
private $softKEY;
private $userName;
private $userPassword;

private $uid;
private $userKey;
private $softContentKEY;

private $uuUrl;
private $uhash;
private $uuVersion='1.1.0.1';
private $userAgent;
private $gkey;

public $macAddress='00e021ac7d'; //客户机的mac地址,服务器暂时没有用,后期准备用于绑定mac地址 赋值方法: $obj->macAddress='00e021ac7d'; 
public $timeOut=60000; //超时时间,建议不要改动此值 赋值方法: $obj->timeOut=60000;

public function setSoftInfo($id,$key)
{
if($id&&$key){
$this->softID=$id;
$this->softKEY=$key;
$this->uhash=md5($id.strtoupper($key));
return 'YES';
}
return 'NO';
}
private function getServerUrl($Server)
{
$url = "http://common.taskok.com:9000/Service/ServerConfig.aspx";
$result=$this->uuGetUrl($url,array(),$postData=false);
preg_match_all("/\,(.*?)\:101\,(.*?)\:102\,(.*?)\:103/", $result, $match_index);
$arr=array_filter($match_index);
if(empty($arr)){return '-1001';}
switch($Server)
{
case 'service':
return 'http://'.$match_index[1][0];
break;
case 'upload':
return 'http://'.$match_index[2][0];
break;
case 'code':
return 'http://'.$match_index[3][0];
break;
default:
return 'parameter error';
}
curl_close($this->uuUrl);
}
public function userLogin($userName,$passWord)
{
if(!($this->softID&&$this->softKEY))
{
return 'sorry,SoftID or softKey is not set! Please use the setSoftInfo(id,key) function to set!';
}
if(!($userName&&$passWord)){ return 'userName or passWord is empty!';}
$this->userName=$userName;
$this->userPassword=$passWord;
$this->userAgent=md5(strtoupper($this->softKEY).strtoupper($this->userName)).$this->macAddress;