我正在开发一个基于第三方的程序,我编写了一个类并使用__autoload()加载这个类。该程序运行如下:
1.我将脚本上传到远程服务器。
2.第三方服务器将请求我的脚本与一些get param。
3.我的脚本返回str,第三方服务器将检查str,如果str与get param相同,则它是有效的,如果不是,则无效。
现在的问题是:
当我使用()时,它会引发一些错误,当我用__autoload /__autoload替换__autoload时,它将准确地运行。
守则如下:
wechat.class.php
public function __construct($options){
$this->_token=isset($options['token'])?$options['token']:'';
}
public function test(){
var_dump($this->_token);
}
private function checkSignature(){
$signature = isset($_GET["signature"])?$_GET["signature"]:'';
$timestamp = isset($_GET["timestamp"])?$_GET["timestamp"]:'';
$nonce = isset($_GET["nonce"])?$_GET["nonce"]:'';
$token = $this->_token;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
public function valid($return=false){
$echostr=isset($_GET['echostr'])?$_GET['echostr']:'';
if($return){
if($echostr){
if($this->checkSignature()){
return $echostr;
}else{
return false;
}
}else{
return $this->checkSignature();
}
}else{
if($echostr){
if($this->checkSignature()){
die($echostr);
}else{
die('no access');
}
}else{
if($this->checkSignature()){
return true;
}else{
die('no access');
}
}
}
}
}
?>wechat.php
<?php
function __autoload($classname){
include "./wechat/".$classname.".class.php";
}
$options=array(
'token'=>'tudouya',
);
$wechat=new Wechat($options);
$wechat->valid();
?>此外,我的php版本是5.4.I对这个脚本进行了很长时间的测试,并找到了__autoload()和include将在php5.2中正常工作,而不是在php5.4中工作。
我甚至认为php中是否存在bug,但我无法决定。
希望我能清楚地描述我的问题,并为我糟糕的英语感到抱歉。
发布于 2014-09-19 08:56:59
答案是:
include "./wechat/".strtolower($classname).".class.php";否则,它将尝试包含Wechat.class.php (大写w,它不作为文件存在)。
https://stackoverflow.com/questions/25929994
复制相似问题