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 f3a35a0e
authored
Jan 18, 2017
by
HanSon
Committed by
GitHub
Jan 18, 2017
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge pull request #1 from HanSon/dev
一点优化
2 parents
7906730c
00ada02d
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
96 additions
and
114 deletions
README.md
composer.json
example/index.php
src/Core/Http.php
src/Core/MessageFactory.php
src/Core/Server.php
README.md
View file @
f3a35a0
...
@@ -61,19 +61,8 @@ $robot->server->run();
...
@@ -61,19 +61,8 @@ $robot->server->run();
# 特别感谢
# 特别感谢
感谢以上两位作者曾对本人耐心解答
感谢以上两位作者曾对本人耐心解答
## 参考项目
[
lbbniu/WebWechat
](
https://github.com/lbbniu/WebWechat
)
[
littlecodersh/ItChat
](
https://github.com/littlecodersh/ItChat
)
感谢楼上两位作者曾对本人耐心解答
[
liuwons/wxBot
](
https://github.com/liuwons/wxBot
)
参考了整个微信的登录流程与消息处理
# to do list
# to do list
-
[
]
消息处理
-
[
]
消息处理
...
@@ -119,6 +108,22 @@ $robot->server->run();
...
@@ -119,6 +108,22 @@ $robot->server->run();
-
[
]
命令行操作信息发送
-
[
]
命令行操作信息发送
# 待修复bug
## 参考项目
[
lbbniu/WebWechat
](
https://github.com/lbbniu/WebWechat
)
[
littlecodersh/ItChat
](
https://github.com/littlecodersh/ItChat
)
感谢楼上两位作者曾对本人耐心解答
[
liuwons/wxBot
](
https://github.com/liuwons/wxBot
)
参考了整个微信的登录流程与消息处理
## 待修复bug
*
30% 的几率初始化失败(暂时无解,如清楚问题欢迎PR)
*
30% 的几率初始化失败(暂时无解,如清楚问题欢迎PR)
## 问题和建议
有问题或者建议都可以提issue
或者加入我新建的QQ群:492548647
\ No newline at end of file
\ No newline at end of file
composer.json
View file @
f3a35a0
...
@@ -10,7 +10,6 @@
...
@@ -10,7 +10,6 @@
],
],
"require"
:
{
"require"
:
{
"guzzlehttp/guzzle"
:
"^6.2"
,
"guzzlehttp/guzzle"
:
"^6.2"
,
"querypath/QueryPath"
:
"^3.0"
,
"symfony/dom-crawler"
:
"^3.2"
,
"symfony/dom-crawler"
:
"^3.2"
,
"endroid/qrcode"
:
"^1.7"
,
"endroid/qrcode"
:
"^1.7"
,
"symfony/css-selector"
:
"^3.2"
,
"symfony/css-selector"
:
"^3.2"
,
...
...
example/index.php
View file @
f3a35a0
...
@@ -32,20 +32,17 @@ $robot = new Vbot([
...
@@ -32,20 +32,17 @@ $robot = new Vbot([
$robot
->
server
->
setMessageHandler
(
function
(
$message
)
use
(
$path
)
{
$robot
->
server
->
setMessageHandler
(
function
(
$message
)
use
(
$path
)
{
/** @var $message Message */
/** @var $message Message */
print_r
(
$message
);
// if($message){
// print_r($message->msg);
// }
// 位置信息 返回位置文字
// 位置信息 返回位置文字
// if ($message instanceof Location) {
if
(
$message
instanceof
Location
)
{
// Text::send('地图链接:'.$message->from['UserName'], $message->url);
/** @var $message Location */
// return '位置:'.$message;
Text
::
send
(
'地图链接:'
.
$message
->
from
[
'UserName'
],
$message
->
url
);
// }
return
'位置:'
.
$message
;
}
// 文字信息
// 文字信息
if
(
$message
instanceof
Text
)
{
if
(
$message
instanceof
Text
)
{
/** @var $message Text */
// 联系人自动回复
// 联系人自动回复
if
(
$message
->
fromType
===
'Contact'
)
{
if
(
$message
->
fromType
===
'Contact'
)
{
...
@@ -63,75 +60,75 @@ $robot->server->setMessageHandler(function ($message) use ($path) {
...
@@ -63,75 +60,75 @@ $robot->server->setMessageHandler(function ($message) use ($path) {
}
}
// 图片信息 返回接收到的图片
// 图片信息 返回接收到的图片
//
if ($message instanceof Image) {
if
(
$message
instanceof
Image
)
{
//
return $message;
return
$message
;
//
}
}
// 视频信息 返回接收到的视频
// 视频信息 返回接收到的视频
//
if ($message instanceof Video) {
if
(
$message
instanceof
Video
)
{
//
return $message;
return
$message
;
//
}
}
// 表情信息 返回接收到的表情
// 表情信息 返回接收到的表情
//
if ($message instanceof Emoticon) {
if
(
$message
instanceof
Emoticon
)
{
//
return $message;
return
$message
;
//
}
}
// 语音消息
// 语音消息
//
if($message instanceof Voice){
if
(
$message
instanceof
Voice
){
//
/** @var $message Voice */
/** @var $message Voice */
//
return '收到一条语音并下载在' . $message->getPath($message::$folder) . "/{$message->msg['MsgId']}.mp3";
return
'收到一条语音并下载在'
.
$message
->
getPath
(
$message
::
$folder
)
.
"/
{
$message
->
msg
[
'MsgId'
]
}
.mp3"
;
//
}
}
// 撤回信息
// 撤回信息
//
if ($message instanceof Recall && $message->msg['FromUserName'] !== myself()->username) {
if
(
$message
instanceof
Recall
&&
$message
->
msg
[
'FromUserName'
]
!==
myself
()
->
username
)
{
//
/** @var $message Recall */
/** @var $message Recall */
//
if($message->origin instanceof Image){
if
(
$message
->
origin
instanceof
Image
){
//
Text::send($message->msg['FromUserName'], "{$message->nickname} 撤回了一张照片");
Text
::
send
(
$message
->
msg
[
'FromUserName'
],
"
{
$message
->
nickname
}
撤回了一张照片"
);
//
Image::sendByMsgId($message->msg['FromUserName'], $message->origin->msg['MsgId']);
Image
::
sendByMsgId
(
$message
->
msg
[
'FromUserName'
],
$message
->
origin
->
msg
[
'MsgId'
]);
//
}elseif($message->origin instanceof Emoticon){
}
elseif
(
$message
->
origin
instanceof
Emoticon
){
//
Text::send($message->msg['FromUserName'], "{$message->nickname} 撤回了一个表情");
Text
::
send
(
$message
->
msg
[
'FromUserName'
],
"
{
$message
->
nickname
}
撤回了一个表情"
);
//
Emoticon::sendByMsgId($message->msg['FromUserName'], $message->origin->msg['MsgId']);
Emoticon
::
sendByMsgId
(
$message
->
msg
[
'FromUserName'
],
$message
->
origin
->
msg
[
'MsgId'
]);
//
}elseif($message->origin instanceof Video){
}
elseif
(
$message
->
origin
instanceof
Video
){
//
Text::send($message->msg['FromUserName'], "{$message->nickname} 撤回了一个视频");
Text
::
send
(
$message
->
msg
[
'FromUserName'
],
"
{
$message
->
nickname
}
撤回了一个视频"
);
//
Video::sendByMsgId($message->msg['FromUserName'], $message->origin->msg['MsgId']);
Video
::
sendByMsgId
(
$message
->
msg
[
'FromUserName'
],
$message
->
origin
->
msg
[
'MsgId'
]);
//
}elseif($message->origin instanceof Voice){
}
elseif
(
$message
->
origin
instanceof
Voice
){
//
Text::send($message->msg['FromUserName'], "{$message->nickname} 撤回了一条语音");
Text
::
send
(
$message
->
msg
[
'FromUserName'
],
"
{
$message
->
nickname
}
撤回了一条语音"
);
//
}else{
}
else
{
//
Text::send($message->msg['FromUserName'], "{$message->nickname} 撤回了一条信息 \"{$message->origin->msg['Content']}\"");
Text
::
send
(
$message
->
msg
[
'FromUserName'
],
"
{
$message
->
nickname
}
撤回了一条信息
\"
{
$message
->
origin
->
msg
[
'Content'
]
}
\"
"
);
//
}
}
//
}
}
//
//
// 红包信息
// 红包信息
//
if($message instanceof RedPacket){
if
(
$message
instanceof
RedPacket
){
//
// do something to notify if you want ...
// do something to notify if you want ...
//
return $message->content . ' 来自 ' .$message->from['NickName'];
return
$message
->
content
.
' 来自 '
.
$message
->
from
[
'NickName'
];
//
}
}
//
//
// 转账信息
// 转账信息
//
if($message instanceof Transfer){
if
(
$message
instanceof
Transfer
){
//
/** @var $message Transfer */
/** @var $message Transfer */
//
return $message->content . ' 收到金额 ' . $message->fee;
return
$message
->
content
.
' 收到金额 '
.
$message
->
fee
;
//
}
}
//
//
// 推荐名片信息
// 推荐名片信息
//
if($message instanceof Recommend){
if
(
$message
instanceof
Recommend
){
//
/** @var $message Recommend */
/** @var $message Recommend */
//
if($message->isOfficial){
if
(
$message
->
isOfficial
){
//
return $message->from['NickName'] . ' 向你推荐了公众号 ' . $message->province . $message->city .
return
$message
->
from
[
'NickName'
]
.
' 向你推荐了公众号 '
.
$message
->
province
.
$message
->
city
.
//
" {$message->info['NickName']} 公众号信息: {$message->description}";
"
{
$message
->
info
[
'NickName'
]
}
公众号信息:
{
$message
->
description
}
"
;
//
}else{
}
else
{
//
return $message->from['NickName'] . ' 向你推荐了 ' . $message->province . $message->city .
return
$message
->
from
[
'NickName'
]
.
' 向你推荐了 '
.
$message
->
province
.
$message
->
city
.
//
" {$message->info['NickName']} 头像链接: {$message->bigAvatar}";
"
{
$message
->
info
[
'NickName'
]
}
头像链接:
{
$message
->
bigAvatar
}
"
;
//
}
}
//
}
}
//
// 请求添加信息
// 请求添加信息
if
(
$message
instanceof
RequestFriend
){
if
(
$message
instanceof
RequestFriend
){
/** @var $message RequestFriend */
/** @var $message RequestFriend */
$groupUsername
=
group
()
->
getGroupsByNickname
(
'芬芬'
,
true
)
->
first
()[
'UserName'
];
$groupUsername
=
group
()
->
getGroupsByNickname
(
'芬芬'
,
true
)
->
first
()[
'UserName'
];
Text
::
send
(
$groupUsername
,
"
{
$message
->
province
}{
$message
->
city
}
的
{
$message
->
info
[
'NickName'
]
}
请求添加好友
\"
{
$message
->
info
[
'Content'
]
}
\"
"
);
Text
::
send
(
$groupUsername
,
"
{
$message
->
info
[
'NickName'
]
}
请求添加好友
\"
{
$message
->
info
[
'Content'
]
}
\"
"
);
if
(
$message
->
info
[
'Content'
]
===
'上山打老虎'
){
if
(
$message
->
info
[
'Content'
]
===
'上山打老虎'
){
Text
::
send
(
$groupUsername
,
'暗号正确'
);
Text
::
send
(
$groupUsername
,
'暗号正确'
);
...
@@ -140,21 +137,20 @@ $robot->server->setMessageHandler(function ($message) use ($path) {
...
@@ -140,21 +137,20 @@ $robot->server->setMessageHandler(function ($message) use ($path) {
Text
::
send
(
$groupUsername
,
'暗号错误'
);
Text
::
send
(
$groupUsername
,
'暗号错误'
);
}
}
}
}
//
//
// 分享信息
// 分享信息
//
if($message instanceof Share){
if
(
$message
instanceof
Share
){
//
/** @var $message Share */
/** @var $message Share */
//
$reply = "收到分享\n标题:{$message->title}\n描述:{$message->description}\n链接:{$message->url}";
$reply
=
"收到分享
\n
标题:
{
$message
->
title
}
\n
描述:
{
$message
->
description
}
\n
链接:
{
$message
->
url
}
"
;
//
if($message->app){
if
(
$message
->
app
){
//
$reply .= "\n来源APP:{$message->app}";
$reply
.=
"
\n
来源APP:
{
$message
->
app
}
"
;
//
}
}
//
return $reply;
return
$reply
;
//
}
}
//
// 手机点击聊天事件
// 手机点击聊天事件
if
(
$message
instanceof
Touch
){
if
(
$message
instanceof
Touch
){
print_r
(
$message
);
Text
::
send
(
$message
->
msg
[
'ToUserName'
],
"我点击了此聊天"
);
Text
::
send
(
$message
->
to
[
'UserName'
],
"我点击了此群"
);
}
}
return
false
;
return
false
;
...
...
src/Core/Http.php
View file @
f3a35a0
...
@@ -21,13 +21,6 @@ class Http
...
@@ -21,13 +21,6 @@ class Http
protected
$client
;
protected
$client
;
/**
/**
* @var FileCookieJar
*/
private
$cookieJar
;
private
$cookieFile
;
/**
* @return Http
* @return Http
*/
*/
public
static
function
getInstance
()
public
static
function
getInstance
()
...
@@ -77,9 +70,6 @@ class Http
...
@@ -77,9 +70,6 @@ class Http
public
function
getClient
()
public
function
getClient
()
{
{
if
(
!
(
$this
->
client
instanceof
HttpClient
))
{
if
(
!
(
$this
->
client
instanceof
HttpClient
))
{
// $this->cookieFile = realpath(server()->config['tmp']) . '/cookie.txt';
// $this->cookieJar = new FileCookieJar($this->cookieFile);
// $this->client = new HttpClient(['cookies' => $this->cookieJar]);
$this
->
client
=
new
HttpClient
([
'cookies'
=>
true
]);
$this
->
client
=
new
HttpClient
([
'cookies'
=>
true
]);
}
}
...
@@ -96,7 +86,6 @@ class Http
...
@@ -96,7 +86,6 @@ class Http
{
{
try
{
try
{
$response
=
$this
->
getClient
()
->
request
(
$method
,
$url
,
$options
);
$response
=
$this
->
getClient
()
->
request
(
$method
,
$url
,
$options
);
// $this->cookieJar->save($this->cookieFile);
return
$response
->
getBody
()
->
getContents
();
return
$response
->
getBody
()
->
getContents
();
}
catch
(
\Exception
$e
){
}
catch
(
\Exception
$e
){
Console
::
log
(
'http链接失败:'
.
$e
->
getMessage
());
Console
::
log
(
'http链接失败:'
.
$e
->
getMessage
());
...
...
src/Core/MessageFactory.php
View file @
f3a35a0
...
@@ -40,7 +40,6 @@ class MessageFactory
...
@@ -40,7 +40,6 @@ class MessageFactory
*/
*/
private
function
handleMessageByType
(
$msg
)
private
function
handleMessageByType
(
$msg
)
{
{
print_r
(
$msg
);
switch
(
$msg
[
'MsgType'
]){
switch
(
$msg
[
'MsgType'
]){
case
1
:
//文本消息
case
1
:
//文本消息
if
(
Location
::
isLocation
(
$msg
)){
if
(
Location
::
isLocation
(
$msg
)){
...
@@ -62,12 +61,9 @@ class MessageFactory
...
@@ -62,12 +61,9 @@ class MessageFactory
if
(
str_contains
(
$msg
[
'Content'
],
'利是'
)
||
str_contains
(
$msg
[
'Content'
],
'红包'
)
||
str_contains
(
$msg
[
'Content'
],
'Red Packet'
)){
if
(
str_contains
(
$msg
[
'Content'
],
'利是'
)
||
str_contains
(
$msg
[
'Content'
],
'红包'
)
||
str_contains
(
$msg
[
'Content'
],
'Red Packet'
)){
return
new
RedPacket
(
$msg
);
return
new
RedPacket
(
$msg
);
}
}
// else if(str_contains($msg['Content'], '好友') || str_contains($msg['Content'], 'friend')){
else
if
(
str_contains
(
$msg
[
'Content'
],
'添加'
)
||
str_contains
(
$msg
[
'Content'
],
'have added'
)){
// print_r($msg);
# 添加好友
// }
}
// else{
// print_r($msg);
// }
break
;
break
;
case
49
:
case
49
:
if
(
$msg
[
'Status'
]
==
3
&&
$msg
[
'FileName'
]
===
'微信转账'
){
if
(
$msg
[
'Status'
]
==
3
&&
$msg
[
'FileName'
]
===
'微信转账'
){
...
...
src/Core/Server.php
View file @
f3a35a0
...
@@ -137,7 +137,7 @@ class Server
...
@@ -137,7 +137,7 @@ class Server
$qrCode
=
new
QrCode
(
$url
);
$qrCode
=
new
QrCode
(
$url
);
$file
=
$this
->
config
[
'tmp'
]
.
'
login_qr_code
.png'
;
$file
=
$this
->
config
[
'tmp'
]
.
'
qr
.png'
;
$qrCode
->
save
(
$file
);
$qrCode
->
save
(
$file
);
...
@@ -258,10 +258,7 @@ class Server
...
@@ -258,10 +258,7 @@ class Server
$this
->
initContactList
(
$result
[
'ContactList'
]);
$this
->
initContactList
(
$result
[
'ContactList'
]);
if
(
$result
[
'BaseResponse'
][
'Ret'
]
!=
0
){
if
(
$result
[
'BaseResponse'
][
'Ret'
]
!=
0
){
// print_r($this->baseRequest);
throw
new
\Exception
(
'[ERROR] 初始化失败,链接:'
.
$url
);
Console
::
log
(
'init URL:'
.
$url
);
throw
new
\Exception
(
'[ERROR] 初始化失败'
);
}
}
}
}
...
...
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