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 1889119d
authored
Dec 16, 2016
by
hanccc
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
完善account保存
1 parent
65fb54d2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
6 deletions
src/Core/MessageHandler.php
src/Message/Message.php
src/Models/Account.php
src/Models/ContactFactory.php
src/Core/MessageHandler.php
View file @
1889119
...
...
@@ -91,7 +91,7 @@ class MessageHandler
$message
=
$this
->
sync
();
Message
::
make
(
$selector
,
$message
);
//
Message::make($selector, $message);
// print_r($message);
Log
::
echo
(
json_encode
(
$message
));
}
...
...
src/Message/Message.php
View file @
1889119
...
...
@@ -10,6 +10,7 @@ namespace Hanson\Robot\Message;
use
Hanson\Robot\Core\Server
;
use
Hanson\Robot\Models\Account
;
class
Message
{
...
...
@@ -41,13 +42,20 @@ class Message
{
$msg
=
$message
[
'AddMsgList'
][
0
];
if
(
$msg
[
'MsgType'
]
==
51
)
{
if
(
$msg
[
'MsgType'
]
==
51
)
{
$this
->
sender
->
name
=
'system'
;
$this
->
sender
->
type
=
0
;
}
elseif
(
$msg
[
'MsgType'
]
==
37
)
{
}
elseif
(
$msg
[
'MsgType'
]
==
37
)
{
$this
->
sender
->
type
=
37
;
}
elseif
(
Server
::
isMyself
(
$msg
[
'FromUserName'
])){
}
elseif
(
Server
::
isMyself
(
$msg
[
'FromUserName'
]))
{
$this
->
sender
->
name
=
'self'
;
$this
->
sender
->
type
=
1
;
}
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
);
$this
->
sender
->
type
=
3
;
}
}
...
...
src/Models/Account.php
View file @
1889119
...
...
@@ -14,8 +14,15 @@ use Illuminate\Support\Collection;
class
Account
extends
Collection
{
/**
* @var Account
*/
static
$instance
=
null
;
const
NORMAL_MEMBER
=
'normal_member'
;
const
GROUP_MEMBER
=
'group_member'
;
/**
* create a single instance
*
...
...
@@ -30,4 +37,45 @@ class Account extends Collection
return
static
::
$instance
;
}
public
function
addGroupMember
(
$groupMember
)
{
$account
=
static
::
$instance
->
all
();
$account
[
static
::
GROUP_MEMBER
][]
=
$groupMember
;
static
::
$instance
->
make
(
$account
);
}
public
function
addNormalMember
(
$normalMember
)
{
$account
=
static
::
$instance
->
all
();
$account
[
static
::
NORMAL_MEMBER
][]
=
$normalMember
;
static
::
$instance
->
make
(
$account
);
}
public
function
getContactName
(
$id
,
$type
,
$prefer
=
false
)
{
$target
=
static
::
$instance
->
get
(
$type
);
$user
=
$target
[
$id
];
$name
=
[];
if
(
isset
(
$user
[
'RemarkName'
])){
$name
[
'remarkName'
]
=
$user
[
'RemarkName'
];
}
if
(
isset
(
$user
[
'NickName'
])){
$name
[
'nickName'
]
=
$user
[
'NickName'
];
}
if
(
isset
(
$user
[
'DisplayName'
])){
$name
[
'displayName'
]
=
$user
[
'DisplayName'
];
}
if
(
!
$name
){
return
null
;
}
return
$prefer
?
array_values
(
$name
)[
0
]
:
$name
;
}
}
\ No newline at end of file
src/Models/ContactFactory.php
View file @
1889119
...
...
@@ -65,7 +65,7 @@ class ContactFactory
$type
=
'contact'
;
ContactAccount
::
getInstance
()
->
put
(
$contact
[
'UserName'
],
$contact
);
}
Account
::
getInstance
()
->
put
(
$contact
[
'UserName'
],
[
'type'
=>
$type
,
'info'
=>
$contact
]);
Account
::
getInstance
()
->
addNormalMember
([
$contact
[
'UserName'
]
=>
[
'type'
=>
$type
,
'info'
=>
$contact
]
]);
}
$this
->
getBatchGroupMembers
();
}
...
...
@@ -109,6 +109,9 @@ class ContactFactory
$groupAccount
[
'MemberList'
]
=
$group
[
'MemberList'
];
$groupAccount
[
'ChatRoomId'
]
=
$group
[
'EncryChatRoomId'
];
GroupAccount
::
getInstance
()
->
put
(
$group
[
'UserName'
],
$groupAccount
);
foreach
(
$group
[
'MemberList'
]
as
$member
)
{
Account
::
getInstance
()
->
addGroupMember
([
$member
[
'UserName'
]
=>
[
'type'
=>
'groupMember'
,
'info'
=>
$member
,
'group'
=>
$group
]]);
}
}
}
...
...
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