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 00ada02d
authored
Jan 19, 2017
by
HanSon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
一点优化
1 parent
7906730c
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 @
00ada02
...
...
@@ -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
-
[
]
消息处理
...
...
@@ -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)
## 问题和建议
有问题或者建议都可以提issue
或者加入我新建的QQ群:492548647
\ No newline at end of file
composer.json
View file @
00ada02
...
...
@@ -10,7 +10,6 @@
],
"require"
:
{
"guzzlehttp/guzzle"
:
"^6.2"
,
"querypath/QueryPath"
:
"^3.0"
,
"symfony/dom-crawler"
:
"^3.2"
,
"endroid/qrcode"
:
"^1.7"
,
"symfony/css-selector"
:
"^3.2"
,
...
...
example/index.php
View file @
00ada02
...
...
@@ -32,20 +32,17 @@ $robot = new Vbot([
$robot
->
server
->
setMessageHandler
(
function
(
$message
)
use
(
$path
)
{
/** @var $message Message */
print_r
(
$message
);
// if($message){
// print_r($message->msg);
// }
// 位置信息 返回位置文字
// if ($message instanceof Location) {
// Text::send('地图链接:'.$message->from['UserName'], $message->url);
// return '位置:'.$message;
// }
if
(
$message
instanceof
Location
)
{
/** @var $message Location */
Text
::
send
(
'地图链接:'
.
$message
->
from
[
'UserName'
],
$message
->
url
);
return
'位置:'
.
$message
;
}
// 文字信息
if
(
$message
instanceof
Text
)
{
/** @var $message Text */
// 联系人自动回复
if
(
$message
->
fromType
===
'Contact'
)
{
...
...
@@ -63,75 +60,75 @@ $robot->server->setMessageHandler(function ($message) use ($path) {
}
// 图片信息 返回接收到的图片
//
if ($message instanceof Image) {
//
return $message;
//
}
if
(
$message
instanceof
Image
)
{
return
$message
;
}
// 视频信息 返回接收到的视频
//
if ($message instanceof Video) {
//
return $message;
//
}
if
(
$message
instanceof
Video
)
{
return
$message
;
}
// 表情信息 返回接收到的表情
//
if ($message instanceof Emoticon) {
//
return $message;
//
}
if
(
$message
instanceof
Emoticon
)
{
return
$message
;
}
// 语音消息
//
if($message instanceof Voice){
//
/** @var $message Voice */
//
return '收到一条语音并下载在' . $message->getPath($message::$folder) . "/{$message->msg['MsgId']}.mp3";
//
}
if
(
$message
instanceof
Voice
){
/** @var $message Voice */
return
'收到一条语音并下载在'
.
$message
->
getPath
(
$message
::
$folder
)
.
"/
{
$message
->
msg
[
'MsgId'
]
}
.mp3"
;
}
// 撤回信息
//
if ($message instanceof Recall && $message->msg['FromUserName'] !== myself()->username) {
//
/** @var $message Recall */
//
if($message->origin instanceof Image){
//
Text::send($message->msg['FromUserName'], "{$message->nickname} 撤回了一张照片");
//
Image::sendByMsgId($message->msg['FromUserName'], $message->origin->msg['MsgId']);
//
}elseif($message->origin instanceof Emoticon){
//
Text::send($message->msg['FromUserName'], "{$message->nickname} 撤回了一个表情");
//
Emoticon::sendByMsgId($message->msg['FromUserName'], $message->origin->msg['MsgId']);
//
}elseif($message->origin instanceof Video){
//
Text::send($message->msg['FromUserName'], "{$message->nickname} 撤回了一个视频");
//
Video::sendByMsgId($message->msg['FromUserName'], $message->origin->msg['MsgId']);
//
}elseif($message->origin instanceof Voice){
//
Text::send($message->msg['FromUserName'], "{$message->nickname} 撤回了一条语音");
//
}else{
//
Text::send($message->msg['FromUserName'], "{$message->nickname} 撤回了一条信息 \"{$message->origin->msg['Content']}\"");
//
}
//
}
//
//
// 红包信息
//
if($message instanceof RedPacket){
//
// do something to notify if you want ...
//
return $message->content . ' 来自 ' .$message->from['NickName'];
//
}
//
//
// 转账信息
//
if($message instanceof Transfer){
//
/** @var $message Transfer */
//
return $message->content . ' 收到金额 ' . $message->fee;
//
}
//
//
// 推荐名片信息
//
if($message instanceof Recommend){
//
/** @var $message Recommend */
//
if($message->isOfficial){
//
return $message->from['NickName'] . ' 向你推荐了公众号 ' . $message->province . $message->city .
//
" {$message->info['NickName']} 公众号信息: {$message->description}";
//
}else{
//
return $message->from['NickName'] . ' 向你推荐了 ' . $message->province . $message->city .
//
" {$message->info['NickName']} 头像链接: {$message->bigAvatar}";
//
}
//
}
//
if
(
$message
instanceof
Recall
&&
$message
->
msg
[
'FromUserName'
]
!==
myself
()
->
username
)
{
/** @var $message Recall */
if
(
$message
->
origin
instanceof
Image
){
Text
::
send
(
$message
->
msg
[
'FromUserName'
],
"
{
$message
->
nickname
}
撤回了一张照片"
);
Image
::
sendByMsgId
(
$message
->
msg
[
'FromUserName'
],
$message
->
origin
->
msg
[
'MsgId'
]);
}
elseif
(
$message
->
origin
instanceof
Emoticon
){
Text
::
send
(
$message
->
msg
[
'FromUserName'
],
"
{
$message
->
nickname
}
撤回了一个表情"
);
Emoticon
::
sendByMsgId
(
$message
->
msg
[
'FromUserName'
],
$message
->
origin
->
msg
[
'MsgId'
]);
}
elseif
(
$message
->
origin
instanceof
Video
){
Text
::
send
(
$message
->
msg
[
'FromUserName'
],
"
{
$message
->
nickname
}
撤回了一个视频"
);
Video
::
sendByMsgId
(
$message
->
msg
[
'FromUserName'
],
$message
->
origin
->
msg
[
'MsgId'
]);
}
elseif
(
$message
->
origin
instanceof
Voice
){
Text
::
send
(
$message
->
msg
[
'FromUserName'
],
"
{
$message
->
nickname
}
撤回了一条语音"
);
}
else
{
Text
::
send
(
$message
->
msg
[
'FromUserName'
],
"
{
$message
->
nickname
}
撤回了一条信息
\"
{
$message
->
origin
->
msg
[
'Content'
]
}
\"
"
);
}
}
// 红包信息
if
(
$message
instanceof
RedPacket
){
// do something to notify if you want ...
return
$message
->
content
.
' 来自 '
.
$message
->
from
[
'NickName'
];
}
// 转账信息
if
(
$message
instanceof
Transfer
){
/** @var $message Transfer */
return
$message
->
content
.
' 收到金额 '
.
$message
->
fee
;
}
// 推荐名片信息
if
(
$message
instanceof
Recommend
){
/** @var $message Recommend */
if
(
$message
->
isOfficial
){
return
$message
->
from
[
'NickName'
]
.
' 向你推荐了公众号 '
.
$message
->
province
.
$message
->
city
.
"
{
$message
->
info
[
'NickName'
]
}
公众号信息:
{
$message
->
description
}
"
;
}
else
{
return
$message
->
from
[
'NickName'
]
.
' 向你推荐了 '
.
$message
->
province
.
$message
->
city
.
"
{
$message
->
info
[
'NickName'
]
}
头像链接:
{
$message
->
bigAvatar
}
"
;
}
}
// 请求添加信息
if
(
$message
instanceof
RequestFriend
){
/** @var $message RequestFriend */
$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'
]
===
'上山打老虎'
){
Text
::
send
(
$groupUsername
,
'暗号正确'
);
...
...
@@ -140,21 +137,20 @@ $robot->server->setMessageHandler(function ($message) use ($path) {
Text
::
send
(
$groupUsername
,
'暗号错误'
);
}
}
//
//
// 分享信息
//
if($message instanceof Share){
//
/** @var $message Share */
//
$reply = "收到分享\n标题:{$message->title}\n描述:{$message->description}\n链接:{$message->url}";
//
if($message->app){
//
$reply .= "\n来源APP:{$message->app}";
//
}
//
return $reply;
//
}
//
// 分享信息
if
(
$message
instanceof
Share
){
/** @var $message Share */
$reply
=
"收到分享
\n
标题:
{
$message
->
title
}
\n
描述:
{
$message
->
description
}
\n
链接:
{
$message
->
url
}
"
;
if
(
$message
->
app
){
$reply
.=
"
\n
来源APP:
{
$message
->
app
}
"
;
}
return
$reply
;
}
// 手机点击聊天事件
if
(
$message
instanceof
Touch
){
print_r
(
$message
);
Text
::
send
(
$message
->
to
[
'UserName'
],
"我点击了此群"
);
Text
::
send
(
$message
->
msg
[
'ToUserName'
],
"我点击了此聊天"
);
}
return
false
;
...
...
src/Core/Http.php
View file @
00ada02
...
...
@@ -21,13 +21,6 @@ class Http
protected
$client
;
/**
* @var FileCookieJar
*/
private
$cookieJar
;
private
$cookieFile
;
/**
* @return Http
*/
public
static
function
getInstance
()
...
...
@@ -77,9 +70,6 @@ class Http
public
function
getClient
()
{
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
]);
}
...
...
@@ -96,7 +86,6 @@ class Http
{
try
{
$response
=
$this
->
getClient
()
->
request
(
$method
,
$url
,
$options
);
// $this->cookieJar->save($this->cookieFile);
return
$response
->
getBody
()
->
getContents
();
}
catch
(
\Exception
$e
){
Console
::
log
(
'http链接失败:'
.
$e
->
getMessage
());
...
...
src/Core/MessageFactory.php
View file @
00ada02
...
...
@@ -40,7 +40,6 @@ class MessageFactory
*/
private
function
handleMessageByType
(
$msg
)
{
print_r
(
$msg
);
switch
(
$msg
[
'MsgType'
]){
case
1
:
//文本消息
if
(
Location
::
isLocation
(
$msg
)){
...
...
@@ -62,12 +61,9 @@ class MessageFactory
if
(
str_contains
(
$msg
[
'Content'
],
'利是'
)
||
str_contains
(
$msg
[
'Content'
],
'红包'
)
||
str_contains
(
$msg
[
'Content'
],
'Red Packet'
)){
return
new
RedPacket
(
$msg
);
}
// else if(str_contains($msg['Content'], '好友') || str_contains($msg['Content'], 'friend')){
// print_r($msg);
// }
// else{
// print_r($msg);
// }
else
if
(
str_contains
(
$msg
[
'Content'
],
'添加'
)
||
str_contains
(
$msg
[
'Content'
],
'have added'
)){
# 添加好友
}
break
;
case
49
:
if
(
$msg
[
'Status'
]
==
3
&&
$msg
[
'FileName'
]
===
'微信转账'
){
...
...
src/Core/Server.php
View file @
00ada02
...
...
@@ -137,7 +137,7 @@ class Server
$qrCode
=
new
QrCode
(
$url
);
$file
=
$this
->
config
[
'tmp'
]
.
'
login_qr_code
.png'
;
$file
=
$this
->
config
[
'tmp'
]
.
'
qr
.png'
;
$qrCode
->
save
(
$file
);
...
...
@@ -258,10 +258,7 @@ class Server
$this
->
initContactList
(
$result
[
'ContactList'
]);
if
(
$result
[
'BaseResponse'
][
'Ret'
]
!=
0
){
// print_r($this->baseRequest);
Console
::
log
(
'init URL:'
.
$url
);
throw
new
\Exception
(
'[ERROR] 初始化失败'
);
throw
new
\Exception
(
'[ERROR] 初始化失败,链接:'
.
$url
);
}
}
...
...
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