0

0

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

php中文网

php中文网

发布时间:2016-06-13 11:53:03

|

1164人浏览过

|

来源于php中文网

原创

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

本帖最后由 xiaoxiaoa2 于 2013-06-15 12:45:48 编辑


/**
说明:此类函数是基于优优云图片识别平台的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;

$url = $this->getServerUrl('service').'/Upload/Login.aspx?U='.$this->userName.'&P='.md5($this->userPassword).'&R='.mktime();
$result=$this->uuGetUrl($url);

if($result>0)
{
$this->userKey=$result;
$this->uid=explode("_",$this->userKey);
$this->uid=$this->uid[0];
$this->softContentKEY=md5(strtolower($this->userKey.$this->softID.$this->softKEY));
$this->gkey=md5(strtoupper($this->softKEY.$this->userName)).$this->macAddress;
return $this->uid;
}
return $result;

}
public function getPoint($userName,$passWord)
{
if(!($userName&&$passWord)){ return 'userName or passWord is empty!';}
$url = $this->getServerUrl('service').'/Upload/GetScore.aspx?U='.$userName.'&P='.md5($passWord).'&R='.mktime();
$result=$this->uuGetUrl($url);
return $result;
}
public function upload($imagePath,$codeType,$auth=false)
{
if(!file_exists($imagePath)){return '-1003';}
if(!is_numeric($codeType)){return '-3004';}
$data=array(
'img'=>'@'.$imagePath,
'key'=>$this->userKey,
'sid'=>$this->softID,
'skey'=>$this->softContentKEY,
'TimeOut'=>$this->timeOut,
'Type'=>$codeType
);
$ver=array(
'Version'=>'100',
);
if($auth){$data=$data+$ver;}
$url = $this->getServerUrl('upload').'/Upload/Processing.aspx?R='.mktime();
return $this->uuGetUrl($url,$data);
}
public function getResult($codeID)
{
if(!is_numeric($codeID)){return '-1009|The codeID is not number';}
$url = $this->getServerUrl('code').'/Upload/GetResult.aspx?KEY='.$this->userKey.'&ID='.$codeID.'&Random='.mktime();
$result='-3';
$timer=0;
while($result=='-3'&&($timertimeOut))

相关文章

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
Word 字间距调整方法汇总
Word 字间距调整方法汇总

本专题整合了Word字间距调整方法,阅读下面的文章了解更详细操作。

2

2025.12.24

任务管理器教程
任务管理器教程

本专题整合了任务管理器相关教程,阅读下面的文章了解更多详细操作。

2

2025.12.24

AppleID格式
AppleID格式

本专题整合了AppleID相关内容,阅读专题下面的文章了解更多详细教程。

0

2025.12.24

csgo视频观看入口合集
csgo视频观看入口合集

本专题整合了csgo观看入口合集,阅读下面的文章了知道更多入口地址。

29

2025.12.24

yandex外贸入口合集
yandex外贸入口合集

本专题汇总了yandex外贸入口地址,阅读下面的文章了解更多内容。

58

2025.12.24

添加脚注通用方法
添加脚注通用方法

本专题整合了添加脚注方法合集,阅读专题下面的文章了解更多内容。

1

2025.12.24

重启电脑教程汇总
重启电脑教程汇总

本专题整合了重启电脑操作教程,阅读下面的文章了解更多详细教程。

3

2025.12.24

纸张尺寸汇总
纸张尺寸汇总

本专题整合了纸张尺寸相关内容,阅读专题下面的文章了解更多内容。

5

2025.12.24

Java Spring Boot 微服务实战
Java Spring Boot 微服务实战

本专题深入讲解 Java Spring Boot 在微服务架构中的应用,内容涵盖服务注册与发现、REST API开发、配置中心、负载均衡、熔断与限流、日志与监控。通过实际项目案例(如电商订单系统),帮助开发者掌握 从单体应用迁移到高可用微服务系统的完整流程与实战能力。

1

2025.12.24

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
JavaScript高级框架设计视频教程
JavaScript高级框架设计视频教程

共22课时 | 3.5万人学习

AngularJS教程
AngularJS教程

共24课时 | 2万人学习

CSS3实现按钮特效视频教程
CSS3实现按钮特效视频教程

共15课时 | 3.2万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号