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 b29bc04a
authored
Dec 15, 2016
by
hanccc
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
完善群组成员
1 parent
61406210
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
112 additions
and
9 deletions
src/Core/Http.php
src/Core/MessageHandler.php
src/Core/Server.php
src/Message/Message.php
src/Models/ContactFactory.php
src/Core/Http.php
View file @
b29bc04
...
@@ -29,9 +29,11 @@ class Http
...
@@ -29,9 +29,11 @@ class Http
return
$this
->
request
(
$url
,
'POST'
,
[
$key
=>
$options
]);
return
$this
->
request
(
$url
,
'POST'
,
[
$key
=>
$options
]);
}
}
public
function
json
(
$url
,
$options
=
[])
public
function
json
(
$url
,
$options
=
[]
,
$array
=
false
)
{
{
return
$this
->
request
(
$url
,
'POST'
,
[
'json'
=>
$options
]);
$content
=
$this
->
request
(
$url
,
'POST'
,
[
'json'
=>
$options
]);
return
$array
?
json_decode
(
$content
,
true
)
:
$content
;
}
}
public
function
setClient
(
HttpClient
$client
)
public
function
setClient
(
HttpClient
$client
)
...
...
src/Core/MessageHandler.php
0 → 100644
View file @
b29bc04
<?php
/**
* Created by PhpStorm.
* User: Hanson
* Date: 2016/12/14
* Time: 23:08
*/
namespace
Hanson\Robot\Core
;
use
Closure
;
class
MessageHandler
{
private
$handler
;
public
function
setMessageHandler
(
Closure
$closure
)
{
if
(
!
$closure
instanceof
Closure
){
throw
new
\Exception
(
'message handler must be a closure!'
);
}
$this
->
handler
=
$closure
;
}
public
function
listen
()
{
call_user_func_array
(
$this
->
handler
,
[]);
}
}
\ No newline at end of file
\ No newline at end of file
src/Core/Server.php
View file @
b29bc04
...
@@ -44,7 +44,9 @@ class Server
...
@@ -44,7 +44,9 @@ class Server
public
$http
;
public
$http
;
protected
$config
;
public
$config
;
public
$messageHandler
;
protected
$debug
=
false
;
protected
$debug
=
false
;
...
@@ -68,10 +70,11 @@ class Server
...
@@ -68,10 +70,11 @@ class Server
Log
::
echo
(
'[INFO] init success!'
);
Log
::
echo
(
'[INFO] init success!'
);
$this
->
statusNotify
();
$this
->
statusNotify
();
Log
::
echo
(
'[INFO] begin to init contacts'
);
$this
->
initContact
();
$this
->
initContact
();
Log
::
echo
(
'[INFO] init contacts success!'
);
Log
::
echo
(
'[INFO] init contacts success!'
);
print_r
(
GroupAccount
::
getInstance
()
->
first
());
MessageHandler
::
listen
();
}
}
public
function
prepare
()
public
function
prepare
()
...
...
src/Message/Message.php
0 → 100644
View file @
b29bc04
<?php
/**
* Created by PhpStorm.
* User: Hanson
* Date: 2016/12/15
* Time: 0:12
*/
namespace
Hanson\Robot\Message
;
class
Message
{
}
\ No newline at end of file
\ No newline at end of file
src/Models/ContactFactory.php
View file @
b29bc04
...
@@ -44,24 +44,73 @@ class ContactFactory
...
@@ -44,24 +44,73 @@ class ContactFactory
$this
->
makeContactList
(
$memberList
);
$this
->
makeContactList
(
$memberList
);
}
}
/**
* make instance model
*
* @param $memberList
*/
protected
function
makeContactList
(
$memberList
)
protected
function
makeContactList
(
$memberList
)
{
{
foreach
(
$memberList
as
$contact
)
{
foreach
(
$memberList
as
$contact
)
{
if
(
$contact
[
'VerifyFlag'
]
&
8
!=
0
){
#公众号
if
(
$contact
[
'VerifyFlag'
]
&
8
!=
0
){
#公众号
$type
=
'public'
;
$type
=
'public'
;
OfficialAccount
::
getInstance
()
->
pu
sh
(
$contact
);
OfficialAccount
::
getInstance
()
->
pu
t
(
$contact
[
'UserName'
],
$contact
);
}
elseif
(
in_array
(
$contact
[
'UserName'
],
static
::
SPECIAL_USERS
)){
# 特殊账户
}
elseif
(
in_array
(
$contact
[
'UserName'
],
static
::
SPECIAL_USERS
)){
# 特殊账户
$type
=
'special'
;
$type
=
'special'
;
SpecialAccount
::
getInstance
()
->
pu
sh
(
$contact
);
SpecialAccount
::
getInstance
()
->
pu
t
(
$contact
[
'UserName'
],
$contact
);
}
elseif
(
strstr
(
$contact
[
'UserName'
],
'@@'
)
!==
false
){
# 群聊
}
elseif
(
strstr
(
$contact
[
'UserName'
],
'@@'
)
!==
false
){
# 群聊
$type
=
'group'
;
$type
=
'group'
;
GroupAccount
::
getInstance
()
->
pu
sh
(
$contact
);
GroupAccount
::
getInstance
()
->
pu
t
(
$contact
[
'UserName'
],
$contact
);
}
else
{
}
else
{
$type
=
'contact'
;
$type
=
'contact'
;
ContactAccount
::
getInstance
()
->
pu
sh
(
$contact
);
ContactAccount
::
getInstance
()
->
pu
t
(
$contact
[
'UserName'
],
$contact
);
}
}
Account
::
getInstance
()
->
put
(
$contact
[
'UserName'
],
[
'type'
=>
$type
,
'info'
=>
$contact
]);
Account
::
getInstance
()
->
put
(
$contact
[
'UserName'
],
[
'type'
=>
$type
,
'info'
=>
$contact
]);
}
}
$this
->
getBatchGroupMembers
();
}
/**
* get group members by api
*/
public
function
getBatchGroupMembers
()
{
$url
=
sprintf
(
Server
::
BASE_URI
.
'/webwxbatchgetcontact?type=ex&r=%s&pass_ticket=%s'
,
time
(),
$this
->
server
->
passTicket
);
$list
=
[];
GroupAccount
::
getInstance
()
->
each
(
function
(
$item
,
$key
)
use
(
&
$list
){
$list
[]
=
[
'UserName'
=>
$key
,
'EncryChatRoomId'
=>
''
];
});
file_put_contents
(
$this
->
server
->
config
[
'tmp'
]
.
'debug.json'
,
json_encode
([
'BaseRequest'
=>
$this
->
server
->
baseRequest
,
'Count'
=>
GroupAccount
::
getInstance
()
->
count
(),
'List'
=>
$list
]));
$content
=
$this
->
server
->
http
->
json
(
$url
,
[
'BaseRequest'
=>
$this
->
server
->
baseRequest
,
'Count'
=>
GroupAccount
::
getInstance
()
->
count
(),
'List'
=>
$list
],
true
);
$this
->
initGroupMembers
(
$content
);
}
/**
* init group members and chat room id
*
* @param $array
*/
private
function
initGroupMembers
(
$array
)
{
foreach
(
$array
[
'ContactList'
]
as
$group
)
{
$groupAccount
=
GroupAccount
::
getInstance
()
->
get
(
$group
[
'UserName'
]);
$groupAccount
[
'MemberList'
]
=
$group
[
'MemberList'
];
$groupAccount
[
'ChatRoomId'
]
=
$group
[
'EncryChatRoomId'
];
GroupAccount
::
getInstance
()
->
put
(
$group
[
'UserName'
],
$groupAccount
);
}
}
}
}
}
\ No newline at end of file
\ 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