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 ebfb9d7f
authored
Dec 16, 2016
by
HanSon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
处理content
1 parent
1889119d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
119 additions
and
8 deletions
README.md
src/Core/MessageHandler.php
src/Message/Message.php
src/Models/ContactAccount.php
src/Models/OfficialAccount.php
README.md
View file @
ebfb9d7
...
...
@@ -18,6 +18,18 @@ Robot->special
Robot->contact
Robot->group
# API
## Message
### sender
*
user 发送者
> * uid 发送者ID
> *
*
gid 群聊ID
*
type 消息发送者类型
# what can wx-robot do?
*
转发消息
...
...
src/Core/MessageHandler.php
View file @
ebfb9d7
...
...
@@ -90,10 +90,16 @@ class MessageHandler
}
$message
=
$this
->
sync
();
// Message::make($selector, $message);
// print_r($message);
foreach
(
$message
[
'AddMsgList'
]
as
$msg
)
{
}
Log
::
echo
(
json_encode
(
$message
));
// $messages = (new Message)->make($selector, $message);
//
// foreach ($messages as $message) {
// call_user_func_array($this->handler, [$message]);
// }
}
/**
...
...
src/Message/Message.php
View file @
ebfb9d7
...
...
@@ -11,10 +11,16 @@ namespace Hanson\Robot\Message;
use
Hanson\Robot\Core\Server
;
use
Hanson\Robot\Models\Account
;
use
Hanson\Robot\Models\ContactAccount
;
use
Hanson\Robot\Models\OfficialAccount
;
use
Hanson\Robot\Models\SpecialAccount
;
class
Message
{
/**
* @
*/
public
$sender
;
public
$receiver
;
...
...
@@ -27,7 +33,7 @@ class Message
static
$message
=
[];
const
USER_
MAP
=
[
const
USER_
TYPE
=
[
0
=>
'Init'
,
1
=>
'Self'
,
2
=>
'FileHelper'
,
...
...
@@ -38,9 +44,16 @@ class Message
99
=>
'UnKnown'
,
];
public
function
make
(
$selector
,
$message
)
public
$rawMsg
;
// const MESSAGE_TYPE = [
// 0 => 'Text',
// ]
public
function
make
(
$selector
,
$msg
)
{
$msg
=
$message
[
'AddMsgList'
][
0
];
$this
->
rawMsg
=
$msg
;
if
(
$msg
[
'MsgType'
]
==
51
)
{
$this
->
sender
->
name
=
'system'
;
...
...
@@ -53,10 +66,74 @@ class Message
}
elseif
(
$msg
[
'ToUserName'
]
===
'filehelper'
)
{
$this
->
sender
->
name
=
'file_helper'
;
$this
->
sender
->
type
=
2
;
}
elseif
(
substr
(
$msg
[
'FromUserName'
],
0
,
2
)
===
'@@'
){
$this
->
sender
->
name
=
Account
::
getInstance
()
->
getContactName
(
$msg
[
'FromUserName'
],
Account
::
GROUP
_MEMBER
,
true
);
}
elseif
(
substr
(
$msg
[
'FromUserName'
],
0
,
2
)
===
'@@'
)
{
$this
->
sender
->
name
=
Account
::
getInstance
()
->
getContactName
(
$msg
[
'FromUserName'
],
Account
::
NORMAL
_MEMBER
,
true
);
$this
->
sender
->
type
=
3
;
}
elseif
(
ContactAccount
::
getInstance
()
->
isContact
(
$msg
[
'FromUserName'
]))
{
$this
->
sender
->
name
=
Account
::
getInstance
()
->
getContactName
(
$msg
[
'FromUserName'
],
Account
::
NORMAL_MEMBER
,
true
);
$this
->
sender
->
type
=
4
;
}
elseif
(
OfficialAccount
::
getInstance
()
->
isPublic
(
$msg
[
'FromUserName'
]))
{
$this
->
sender
->
name
=
Account
::
getInstance
()
->
getContactName
(
$msg
[
'FromUserName'
],
Account
::
NORMAL_MEMBER
,
true
);
$this
->
sender
->
type
=
5
;
}
elseif
(
SpecialAccount
::
getInstance
()
->
get
(
$msg
[
'FromUserName'
],
false
))
{
$this
->
sender
->
name
=
Account
::
getInstance
()
->
getContactName
(
$msg
[
'FromUserName'
],
Account
::
NORMAL_MEMBER
,
true
);
$this
->
sender
->
type
=
6
;
}
else
{
$this
->
sender
->
name
=
'unknown'
;
$this
->
sender
->
type
=
99
;
}
$this
->
sender
->
name
=
html_entity_decode
(
$this
->
sender
->
name
);
$this
->
handleContent
();
}
private
function
handleContent
()
{
// $msgType = $msg['MsgType'];
$content
=
html_entity_decode
(
$this
->
rawMsg
[
'Content'
]);
// $msgId = $msg['MsgId'];
$this
->
handleContentByType
(
$content
);
$this
->
handleMessageByType
();
}
private
function
handleContentByType
(
$content
)
{
if
(
$this
->
sender
->
type
===
0
){
$this
->
type
=
'Empty'
;
}
elseif
(
$this
->
sender
->
type
===
2
){
$this
->
type
=
'Text'
;
$this
->
content
=
$this
->
formatContent
(
$content
);
}
elseif
(
$this
->
sender
->
type
===
3
){
$this
->
handleGroupContent
(
$content
);
}
}
private
function
handleMessageByType
()
{
if
(
$this
->
rawMsg
[
'MsgType'
]
==
1
){
}
}
/**
* handle group content
*
* @param $content
*/
private
function
handleGroupContent
(
$content
)
{
list
(
$uid
,
$content
)
=
explode
(
'<br/>'
,
$content
,
2
);
$this
->
sender
->
user
=
Account
::
getInstance
()
->
get
(
'normalMember'
)[
substr
(
$uid
,
0
,
-
1
)];
$this
->
content
=
$this
->
formatContent
(
$content
);
}
private
function
formatContent
(
$content
)
{
return
str_replace
(
'<br/>'
,
'\n'
,
$content
);
}
}
\ No newline at end of file
src/Models/ContactAccount.php
View file @
ebfb9d7
...
...
@@ -14,6 +14,9 @@ use Illuminate\Support\Collection;
class
ContactAccount
extends
Collection
{
/**
* @var ContactAccount
*/
static
$instance
=
null
;
/**
...
...
@@ -30,4 +33,9 @@ class ContactAccount extends Collection
return
static
::
$instance
;
}
public
function
isContact
(
$id
)
{
return
static
::
$instance
->
get
(
$id
,
false
);
}
}
\ No newline at end of file
src/Models/OfficialAccount.php
View file @
ebfb9d7
...
...
@@ -14,6 +14,9 @@ use Illuminate\Support\Collection;
class
OfficialAccount
extends
Collection
{
/**
* @var OfficialAccount
*/
static
$instance
=
null
;
/**
...
...
@@ -30,4 +33,9 @@ class OfficialAccount extends Collection
return
static
::
$instance
;
}
public
function
isPublic
(
$id
)
{
return
static
::
$instance
->
get
(
$id
,
false
);
}
}
\ 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