如何调试你的应用
本帖最后由 weixinhost 于 2015-3-5 13:30 编辑 _
实际上,应用**给侯斯特的是一个PHP类。侯斯特根据应用的设置,收到不同的消息去调用不同的类方法。 因此,我们调试应用只需要模拟应用接收的消息即可。
**本地调试**
你可以直接new这个类,并调用不同的方法进行测试。
_/********** WechatApplication.class.php ***********/_
class WechatApplication
{
**public** function text($accountInfo,$wechatMessage,$params = array()){
$content = $wechatMessage;
**if**($content == 'hello'){
**return** $this->send('text','hello,world');
}
}
**public** function send($type,$message){
**return** **array**(
'action'=>'reply',
'data'=>**array**(
'type'=>$type,
'message'=>$message
),
'log'=>1,
'exit'=>1
);
}
}
?>
_/************** weixin.php *********************/_
**require_once** "WechatApplication.class.php";
$server = **new** Yar_Server(**new** WechatApplication());
$server->handle();
?>
_/************** test.php **********************/_
**require_once** "WechatApplication.class.php"
$handle = **new** WechatApplication();
$account = **array**( 'id'=>1,
'name'=>'模拟测试帐号');
$message = **array**(
'FromUserName'=>'o2_******x',
'ToUserName'=>'gh_asad****xx',
'Event'=>'text',
'Content'=>'hello',
'CreateTime'=>time()
);
?>
_//这样就实现了本地模拟消息进行测试_
$result = $handle->text($account,$message);
**模拟远程调用测试**
本地测试毕竟不是真实网络环境,并不能完全模拟真实网络情况。
因此,我们还需要进行远程调用调试。
我们可以借助Yar的Client端进行调用测试
_/********** WechatApplication.class.php ***********/_
class WechatApplication
{
**public** function text($accountInfo,$wechatMessage,$params = array()){
$content = $wechatMessage;
**if**($content == 'hello'){
**return** $this->send('text','hello,world');
}
}
**public** function send($type,$message){
**return** **array**(
'action'=>'reply',
'data'=>**array**(
'type'=>$type,
'message'=>$message
),
'log'=>1,
'exit'=>1
);
}
}
?>
_/************** weixin.php *********************/_
/
**require_once** "WechatApplication.class.php";
$server = **new** Yar_Server(**new** WechatApplication());
$server->handle();
?>
_/************** test.php **********************/_
_// 这里,我们假定test.php部署在不同的weixin.php的机器上。_
$yarClient = **new** Yar_Client('http://**.com/weixin.php') _//Yar_Client的构造函数为weixin.php的uri_
$account = **array**(
'id'=>1,
'name'=>'模拟测试帐号' );
$message = **array**(
'FromUserName'=>'o2_******x',
'ToUserName'=>'gh_asad****xx',
'Event'=>'text',
'Content'=>'hello',
'CreateTime'=>time()
);
_//这样就实现了真实网络模拟消息进行测试_
$result = $yarClient->text($account,$message);
?>
**使用侯斯特应用模拟器****进行测试**
开发中....
实际上,应用**给侯斯特的是一个PHP类。侯斯特根据应用的设置,收到不同的消息去调用不同的类方法。 因此,我们调试应用只需要模拟应用接收的消息即可。
**本地调试**
你可以直接new这个类,并调用不同的方法进行测试。
_/********** WechatApplication.class.php ***********/_
class WechatApplication
{
**public** function text($accountInfo,$wechatMessage,$params = array()){
$content = $wechatMessage;
**if**($content == 'hello'){
**return** $this->send('text','hello,world');
}
}
**public** function send($type,$message){
**return** **array**(
'action'=>'reply',
'data'=>**array**(
'type'=>$type,
'message'=>$message
),
'log'=>1,
'exit'=>1
);
}
}
?>
_/************** weixin.php *********************/_
**require_once** "WechatApplication.class.php";
$server = **new** Yar_Server(**new** WechatApplication());
$server->handle();
?>
_/************** test.php **********************/_
**require_once** "WechatApplication.class.php"
$handle = **new** WechatApplication();
$account = **array**( 'id'=>1,
'name'=>'模拟测试帐号');
$message = **array**(
'FromUserName'=>'o2_******x',
'ToUserName'=>'gh_asad****xx',
'Event'=>'text',
'Content'=>'hello',
'CreateTime'=>time()
);
?>
_//这样就实现了本地模拟消息进行测试_
$result = $handle->text($account,$message);
**模拟远程调用测试**
本地测试毕竟不是真实网络环境,并不能完全模拟真实网络情况。
因此,我们还需要进行远程调用调试。
我们可以借助Yar的Client端进行调用测试
_/********** WechatApplication.class.php ***********/_
class WechatApplication
{
**public** function text($accountInfo,$wechatMessage,$params = array()){
$content = $wechatMessage;
**if**($content == 'hello'){
**return** $this->send('text','hello,world');
}
}
**public** function send($type,$message){
**return** **array**(
'action'=>'reply',
'data'=>**array**(
'type'=>$type,
'message'=>$message
),
'log'=>1,
'exit'=>1
);
}
}
?>
_/************** weixin.php *********************/_
/
**require_once** "WechatApplication.class.php";
$server = **new** Yar_Server(**new** WechatApplication());
$server->handle();
?>
_/************** test.php **********************/_
_// 这里,我们假定test.php部署在不同的weixin.php的机器上。_
$yarClient = **new** Yar_Client('http://**.com/weixin.php') _//Yar_Client的构造函数为weixin.php的uri_
$account = **array**(
'id'=>1,
'name'=>'模拟测试帐号' );
$message = **array**(
'FromUserName'=>'o2_******x',
'ToUserName'=>'gh_asad****xx',
'Event'=>'text',
'Content'=>'hello',
'CreateTime'=>time()
);
_//这样就实现了真实网络模拟消息进行测试_
$result = $yarClient->text($account,$message);
?>
**使用侯斯特应用模拟器****进行测试**
开发中....
没有找到相关结果
已邀请:
1 个回复
h建非凡
static/image/common/sigline.gif
90%打工小伙一生都不可能知道的秘密 http://67177.miyue999.com/