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 35d89ec1
authored
Jan 25, 2017
by
HanSon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化console输出
1 parent
08e604aa
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
26 deletions
src/Collections/Message.php
src/Core/Http.php
src/Core/MessageFactory.php
src/Core/MessageHandler.php
src/Core/Server.php
src/Support/Console.php
src/Collections/Message.php
View file @
35d89ec
...
...
@@ -9,7 +9,6 @@
namespace
Hanson\Vbot\Collections
;
use
Hanson\Vbot\Support\Console
;
use
Illuminate\Support\Collection
;
class
Message
extends
Collection
...
...
src/Core/Http.php
View file @
35d89ec
...
...
@@ -9,8 +9,6 @@
namespace
Hanson\Vbot\Core
;
use
GuzzleHttp\Client
as
HttpClient
;
use
GuzzleHttp\Cookie\CookieJar
;
use
GuzzleHttp\Cookie\FileCookieJar
;
use
Hanson\Vbot\Support\Console
;
class
Http
...
...
@@ -92,10 +90,11 @@ class Http
$response
=
$this
->
getClient
()
->
request
(
$method
,
$url
,
$options
);
return
$response
->
getBody
()
->
getContents
();
}
catch
(
\Exception
$e
){
Console
::
log
(
'http链接失败:'
.
$e
->
getMessage
());
Console
::
log
(
'错误URL:'
.
$url
);
Console
::
log
(
'http链接失败:'
.
$e
->
getMessage
()
,
Console
::
ERROR
);
Console
::
log
(
'错误URL:'
.
$url
,
Console
::
ERROR
);
}
return
null
;
}
...
...
src/Core/MessageFactory.php
View file @
35d89ec
...
...
@@ -17,7 +17,6 @@ use Hanson\Vbot\Message\Entity\Recall;
use
Hanson\Vbot\Message\Entity\Recommend
;
use
Hanson\Vbot\Message\Entity\RedPacket
;
use
Hanson\Vbot\Message\Entity\RequestFriend
;
use
Hanson\Vbot\Message\Entity\Share
;
use
Hanson\Vbot\Message\Entity\ShareFactory
;
use
Hanson\Vbot\Message\Entity\Text
;
use
Hanson\Vbot\Message\Entity\Touch
;
...
...
@@ -28,7 +27,7 @@ use Hanson\Vbot\Message\Entity\Voice;
class
MessageFactory
{
public
function
make
(
$
selector
,
$
msg
)
public
function
make
(
$msg
)
{
return
$this
->
handleMessageByType
(
$msg
);
}
...
...
@@ -91,5 +90,6 @@ class MessageFactory
//Unknown
break
;
}
return
null
;
}
}
\ No newline at end of file
src/Core/MessageHandler.php
View file @
35d89ec
...
...
@@ -9,7 +9,6 @@
namespace
Hanson\Vbot\Core
;
use
Closure
;
use
Hanson\Vbot\Collections\Account
;
use
Hanson\Vbot\Message\Entity\Emoticon
;
use
Hanson\Vbot\Message\Entity\Image
;
use
Hanson\Vbot\Message\Entity\Message
;
...
...
@@ -130,7 +129,7 @@ class MessageHandler
list
(
$retCode
,
$selector
)
=
$this
->
sync
->
checkSync
();
if
(
in_array
(
$retCode
,
[
'1100'
,
'1101'
])){
# 微信客户端上登出或者其他设备登录
Console
::
log
(
'
[INFO]
微信客户端正常退出'
);
Console
::
log
(
'微信客户端正常退出'
);
if
(
$this
->
exitHandler
){
call_user_func_array
(
$this
->
exitHandler
,
[]);
}
...
...
@@ -138,7 +137,7 @@ class MessageHandler
}
elseif
(
$retCode
==
0
){
$this
->
handlerMessage
(
$selector
);
}
else
{
Console
::
log
(
'
[INFO]
微信客户端异常退出'
);
Console
::
log
(
'微信客户端异常退出'
);
if
(
$this
->
exceptionHandler
){
call_user_func_array
(
$this
->
exitHandler
,
[]);
}
...
...
@@ -147,7 +146,7 @@ class MessageHandler
$this
->
sync
->
checkTime
(
$time
);
}
Console
::
log
(
'
[INFO]
程序结束'
);
Console
::
log
(
'程序结束'
);
}
/**
...
...
@@ -165,7 +164,7 @@ class MessageHandler
if
(
$message
[
'AddMsgList'
]){
foreach
(
$message
[
'AddMsgList'
]
as
$msg
)
{
$content
=
$this
->
messageFactory
->
make
(
$
selector
,
$
msg
);
$content
=
$this
->
messageFactory
->
make
(
$msg
);
if
(
$content
){
$this
->
addToMessageCollection
(
$content
);
if
(
$this
->
handler
){
...
...
src/Core/Server.php
View file @
35d89ec
...
...
@@ -80,12 +80,12 @@ class Server
{
$this
->
prepare
();
$this
->
init
();
Console
::
log
(
'
[INFO]
初始化成功'
);
Console
::
log
(
'初始化成功'
);
$this
->
statusNotify
();
Console
::
log
(
'
[INFO]
开始初始化联系人'
);
Console
::
log
(
'开始初始化联系人'
);
$this
->
initContact
();
Console
::
log
(
'
[INFO]
初始化联系人成功'
);
Console
::
log
(
'初始化联系人成功'
);
MessageHandler
::
getInstance
()
->
listen
();
}
...
...
@@ -95,11 +95,11 @@ class Server
$this
->
getUuid
();
$this
->
generateQrCode
();
Console
::
showQrCode
(
'https://login.weixin.qq.com/l/'
.
$this
->
uuid
);
Console
::
log
(
'
[INFO]
请扫描二维码登录'
);
Console
::
log
(
'请扫描二维码登录'
);
$this
->
waitForLogin
();
$this
->
login
();
Console
::
log
(
'
[INFO]
登录成功'
);
Console
::
log
(
'登录成功'
);
}
/**
...
...
@@ -120,7 +120,8 @@ class Server
preg_match
(
'/window.QRLogin.code = (\d+); window.QRLogin.uuid = \"(\S+?)\"/'
,
$content
,
$matches
);
if
(
!
$matches
){
throw
new
\Exception
(
'[ERROR] 获取UUID失败'
);
Console
::
log
(
'获取UUID失败'
,
Console
::
ERROR
);
exit
;
}
$this
->
uuid
=
$matches
[
2
];
...
...
@@ -164,7 +165,7 @@ class Server
$code
=
$matches
[
1
];
switch
(
$code
){
case
'201'
:
Console
::
log
(
'
[INFO]
请点击确认登录微信'
);
Console
::
log
(
'请点击确认登录微信'
);
$tip
=
0
;
break
;
case
'200'
:
...
...
@@ -189,13 +190,13 @@ class Server
}
return
;
case
'408'
:
Console
::
log
(
'
[ERROR] 登录超时,请重试'
);
Console
::
log
(
'
登录超时,请重试'
,
Console
::
ERROR
);
$tip
=
1
;
$retryTime
-=
1
;
sleep
(
1
);
break
;
default
:
Console
::
log
(
"
[ERROR] 登录失败,错误码:
$code
。请重试"
);
Console
::
log
(
"
登录失败,错误码:
$code
。请重试"
,
Console
::
ERROR
);
$tip
=
1
;
$retryTime
-=
1
;
sleep
(
1
);
...
...
@@ -203,7 +204,8 @@ class Server
}
}
die
(
'[ERROR] 登录超时,退出应用'
);
Console
::
log
(
'登录超时,退出应用'
,
Console
::
ERROR
);
exit
;
}
/**
...
...
@@ -223,7 +225,8 @@ class Server
$this
->
passTicket
=
$data
[
'pass_ticket'
];
if
(
in_array
(
''
,
[
$this
->
skey
,
$this
->
sid
,
$this
->
uin
,
$this
->
passTicket
])){
throw
new
\Exception
(
'[ERROR] 登录失败'
);
Console
::
log
(
'登录失败'
,
Console
::
ERROR
);
exit
;
}
$this
->
deviceId
=
'e'
.
substr
(
mt_rand
()
.
mt_rand
(),
1
,
15
);
...
...
@@ -254,7 +257,8 @@ class Server
$this
->
initContactList
(
$result
[
'ContactList'
]);
if
(
$result
[
'BaseResponse'
][
'Ret'
]
!=
0
){
throw
new
\Exception
(
'[ERROR] 初始化失败,链接:'
.
$url
);
Console
::
log
(
'初始化失败,链接:'
.
$url
,
Console
::
ERROR
);
exit
;
}
}
...
...
src/Support/Console.php
View file @
35d89ec
...
...
@@ -9,6 +9,7 @@
namespace
Hanson\Vbot\Support
;
use
Carbon\Carbon
;
use
PHPQRCode\QRcode
;
use
Symfony\Component\Console\Formatter\OutputFormatterStyle
;
use
Symfony\Component\Console\Output\ConsoleOutput
;
...
...
@@ -17,14 +18,19 @@ use Symfony\Component\Console\Output\OutputInterface;
class
Console
{
const
INFO
=
'INFO'
;
const
WARNING
=
'WARNING'
;
const
ERROR
=
'ERROR'
;
/**
* 输出字符串
*
* @param $str
* @param string $level
*/
public
static
function
log
(
$str
)
public
static
function
log
(
$str
,
$level
=
'INFO'
)
{
echo
$str
.
PHP_EOL
;
echo
'['
.
Carbon
::
now
()
->
toDateTimeString
()
.
']'
.
"[
{
$level
}
] "
.
$str
.
PHP_EOL
;
}
/**
...
...
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