Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
hfpp2012
/
vbot
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 6cab8c20
authored
Jan 19, 2017
by
HanSon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改文档
1 parent
f470b80f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
17 deletions
README.md
example/index.php
README.md
View file @
6cab8c2
...
@@ -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);
}
}
}
});
});
...
...
example/index.php
View file @
6cab8c2
...
@@ -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'
];
}
}
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment