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 e0cd8283
authored
Jan 09, 2017
by
hanccc
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
增加文档和增加消息分类
1 parent
01f92cf9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
19 deletions
README.md
src/Core/Server.php
src/Message/Message.php
README.md
View file @
e0cd828
...
...
@@ -303,8 +303,12 @@ $robot->server->setCustomHandler(function(){
# to do list
-
[
]
命令行操作信息发送
-
[
]
增加消息集合存储
-
[
x
]
增加消息集合存储
-
[
]
消息发送
-
[
]
发送图片
-
[
]
发送表情
-
[
]
消息处理
-
[
x
]
防撤回
# 已知bug
...
...
src/Core/Server.php
View file @
e0cd828
...
...
@@ -218,7 +218,7 @@ class Server
return
true
;
}
protected
function
init
()
protected
function
init
(
$first
=
true
)
{
$url
=
sprintf
(
self
::
BASE_URI
.
'/webwxinit?r=%i&lang=en_US&pass_ticket=%s'
,
time
(),
$this
->
passTicket
);
...
...
@@ -227,7 +227,7 @@ class Server
]);
$result
=
json_decode
(
$content
,
true
);
$this
->
generateSyncKey
(
$result
);
$this
->
generateSyncKey
(
$result
,
$first
);
myself
()
->
init
(
$result
[
'User'
]);
...
...
@@ -271,14 +271,18 @@ class Server
]);
}
protected
function
generateSyncKey
(
$result
)
protected
function
generateSyncKey
(
$result
,
$first
)
{
$this
->
syncKey
=
$result
[
'SyncKey'
];
$syncKey
=
[];
foreach
(
$this
->
syncKey
[
'List'
]
as
$item
)
{
$syncKey
[]
=
$item
[
'Key'
]
.
'_'
.
$item
[
'Val'
];
if
(
is_array
(
$this
->
syncKey
[
'List'
])){
foreach
(
$this
->
syncKey
[
'List'
]
as
$item
)
{
$syncKey
[]
=
$item
[
'Key'
]
.
'_'
.
$item
[
'Val'
];
}
}
elseif
(
$first
){
$this
->
init
(
false
);
}
$this
->
syncKeyStr
=
implode
(
'|'
,
$syncKey
);
...
...
src/Message/Message.php
View file @
e0cd828
...
...
@@ -157,7 +157,7 @@ class Message
{
print_r
(
$this
->
rawMsg
);
switch
(
$this
->
rawMsg
[
'MsgType'
]){
case
1
:
case
1
:
//文本消息
if
(
Location
::
isLocation
(
$this
->
rawMsg
)){
$this
->
type
=
'Location'
;
$this
->
content
=
Location
::
getLocationText
(
$this
->
rawMsg
[
'Content'
]);
...
...
@@ -166,26 +166,29 @@ class Message
$this
->
content
=
$this
->
rawMsg
[
'Content'
];
}
break
;
case
3
:
case
3
:
// 图片消息
$this
->
type
=
'Image'
;
$this
->
content
=
Server
::
BASE_URI
.
sprintf
(
'/webwxgetmsgimg?MsgID=%s&skey=%s'
,
$this
->
rawMsg
[
'MsgId'
],
server
()
->
skey
);
$content
=
http
()
->
get
(
$this
->
content
);
FileManager
::
download
(
$this
->
rawMsg
[
'MsgId'
]
.
'.jpg'
,
$content
,
'jpg'
);
break
;
case
34
:
case
34
:
// 语音消息
$this
->
type
=
'Voice'
;
$this
->
content
=
Server
::
BASE_URI
.
sprintf
(
'/webwxgetvoice?msgid=%s&skey=%s'
,
$this
->
rawMsg
[
'MsgId'
],
server
()
->
skey
);
$content
=
http
()
->
get
(
$this
->
content
);
FileManager
::
download
(
$this
->
rawMsg
[
'MsgId'
]
.
'.mp3'
,
$content
,
'mp3'
);
break
;
case
37
:
case
37
:
// 好友验证
$this
->
type
=
'AddUser'
;
break
;
case
42
:
case
42
:
//共享名片
$this
->
type
=
'Recommend'
;
$this
->
content
=
(
object
)
$this
->
rawMsg
[
'RecommendInfo'
];
break
;
case
47
:
case
43
:
$this
->
type
=
'VideoCall'
;
break
;
case
47
:
// 动画表情
$this
->
type
=
'Animation'
;
break
;
case
49
:
...
...
@@ -194,9 +197,19 @@ class Message
case
62
:
$this
->
type
=
'Video'
;
break
;
case
51
:
$this
->
type
=
'Init'
;
break
;
case
53
:
$this
->
type
=
'VideoCall'
;
break
;
case
10000
:
if
(
$this
->
rawMsg
[
'Status'
]
==
4
){
$this
->
type
=
'RedPacket'
;
// 红包
}
else
{
$this
->
type
=
'Unknown'
;
}
break
;
case
10002
:
$this
->
type
=
'Recall'
;
// 撤回
$msgId
=
$this
->
parseMsgId
(
$this
->
rawMsg
[
'Content'
]);
...
...
@@ -206,13 +219,6 @@ class Message
Console
::
log
(
'nickname:'
.
$nickname
);
$this
->
content
=
"
{
$nickname
}
刚撤回了消息
\"
{
$message
[
'content'
]
}
\"
"
;
break
;
case
10000
:
if
(
$this
->
rawMsg
[
'Status'
]
==
4
){
$this
->
type
=
'RedPacket'
;
// 红包
}
else
{
$this
->
type
=
'Unknown'
;
}
break
;
default
:
$this
->
type
=
'Unknown'
;
break
;
...
...
@@ -308,4 +314,33 @@ class Message
return
true
;
}
public
static
function
sendImg
(
$username
,
$mediaId
)
{
$url
=
sprintf
(
Server
::
BASE_URI
.
'/webwxsendmsgimg?fun=async&f=json&pass_ticket=%s'
,
server
()
->
passTicket
);
$clientMsgId
=
(
time
()
*
1000
)
.
substr
(
uniqid
(),
0
,
5
);
$data
=
[
'BaseRequest'
=>
server
()
->
baseRequest
,
'Msg'
=>
[
'Type'
=>
3
,
'MediaId'
=>
$mediaId
,
'FromUserName'
=>
myself
()
->
username
,
'ToUserName'
=>
$username
,
'LocalID'
=>
$clientMsgId
,
'ClientMsgId'
=>
$clientMsgId
]
];
$result
=
http
()
->
post
(
$url
,
json_encode
(
$data
,
JSON_UNESCAPED_UNICODE
),
true
);
if
(
$result
[
'BaseResponse'
][
'Ret'
]
!=
0
){
Console
::
log
(
'发送消息失败'
);
return
false
;
}
return
true
;
}
// pri
}
\ No newline at end of file
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