Commit 6cab8c20 by HanSon

修改文档

1 parent f470b80f
...@@ -36,22 +36,33 @@ require_once __DIR__ . './../vendor/autoload.php'; ...@@ -36,22 +36,33 @@ require_once __DIR__ . './../vendor/autoload.php';
use Hanson\Vbot\Foundation\Vbot; use Hanson\Vbot\Foundation\Vbot;
use Hanson\Robot\Message\Message; use Hanson\Robot\Message\Message;
use Hanson\Robot\Message\Text;
$robot = new Vbot([ $robot = new Vbot([
'tmp' => '/path/to/tmp/', # 用于生成登录二维码以及文件保存 'tmp' => '/path/to/tmp/', # 用于生成登录二维码以及文件保存
'debug' => true # 用于是否输出用户组的json 'debug' => true # 用于是否输出用户组的json
]); ]);
$robot->server->setMessageHandler(function($message){ // 图灵自动回复
if($message->type === 'Text'){ function reply($str){
$url = 'http://www.tuling123.com/openapi/api'; return http()->post('http://www.tuling123.com/openapi/api', [
'key' => '1dce02aef026258eff69635a06b0ab7d',
'info' => $str
], true)['text'];
$result = http()->post($url, [ }
'key' => 'your tuling api key',
'info' => $message->content
], true);
return $result['text']; $robot->server->setMessageHandler(function($message){
// 文字信息
if ($message instanceof Text) {
/** @var $message Text */
// 联系人自动回复
if ($message->fromType === 'Contact') {
return reply($message->content);
// 群组@我回复
} elseif ($message->fromType === 'Group' && $message->isAt) {
return reply($message->content);
}
} }
}); });
......
...@@ -30,6 +30,15 @@ $robot = new Vbot([ ...@@ -30,6 +30,15 @@ $robot = new Vbot([
'debug' => true 'debug' => true
]); ]);
// 图灵自动回复
function reply($str){
return http()->post('http://www.tuling123.com/openapi/api', [
'key' => '1dce02aef026258eff69635a06b0ab7d',
'info' => $str
], true)['text'];
}
$robot->server->setMessageHandler(function ($message) use ($path) { $robot->server->setMessageHandler(function ($message) use ($path) {
/** @var $message Message */ /** @var $message Message */
...@@ -45,17 +54,10 @@ $robot->server->setMessageHandler(function ($message) use ($path) { ...@@ -45,17 +54,10 @@ $robot->server->setMessageHandler(function ($message) use ($path) {
/** @var $message Text */ /** @var $message Text */
// 联系人自动回复 // 联系人自动回复
if ($message->fromType === 'Contact') { if ($message->fromType === 'Contact') {
return reply($message->content);
return http()->post('http://www.tuling123.com/openapi/api', [
'key' => '1dce02aef026258eff69635a06b0ab7d',
'info' => $message->content
], true)['text'];
// 群组@我回复 // 群组@我回复
} elseif ($message->fromType === 'Group' && $message->isAt) { } elseif ($message->fromType === 'Group' && $message->isAt) {
return http()->post('http://www.tuling123.com/openapi/api', [ return reply($message->content);
'key' => '1dce02aef026258eff69635a06b0ab7d',
'info' => $message->content
], true)['text'];
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!