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 0e2c03ad
authored
Dec 23, 2016
by
hanccc
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
构造message
1 parent
38cdcdf8
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
55 additions
and
36 deletions
src/Collections/Account.php
src/Collections/ContactFactory.php
src/Core/MessageHandler.php
src/Core/Server.php
src/Message/Message.php
test/test.php
src/Collections/Account.php
View file @
0e2c03a
...
@@ -48,7 +48,7 @@ class Account extends Collection
...
@@ -48,7 +48,7 @@ class Account extends Collection
$account
[
static
::
GROUP_MEMBER
][]
=
$groupMember
;
$account
[
static
::
GROUP_MEMBER
][]
=
$groupMember
;
static
::
$instance
->
make
(
$account
);
static
::
$instance
=
static
::
$instance
->
make
(
$account
);
}
}
/**
/**
...
@@ -62,7 +62,7 @@ class Account extends Collection
...
@@ -62,7 +62,7 @@ class Account extends Collection
$account
[
static
::
NORMAL_MEMBER
][]
=
$normalMember
;
$account
[
static
::
NORMAL_MEMBER
][]
=
$normalMember
;
static
::
$instance
->
make
(
$account
);
static
::
$instance
=
static
::
$instance
->
make
(
$account
);
}
}
/**
/**
...
@@ -100,12 +100,11 @@ class Account extends Collection
...
@@ -100,12 +100,11 @@ class Account extends Collection
* 获取联系人
* 获取联系人
*
*
* @param $id
* @param $id
* @param string $type 类型
* @return array
* @return array
*/
*/
public
function
getContact
(
$id
,
$type
)
public
function
getContact
(
$id
)
{
{
$target
=
static
::
$instance
->
get
(
$type
);
$target
=
static
::
$instance
->
get
(
static
::
NORMAL_MEMBER
);
return
$target
[
$id
]
??
null
;
return
$target
[
$id
]
??
null
;
}
}
...
...
src/Collections/ContactFactory.php
View file @
0e2c03a
...
@@ -67,7 +67,9 @@ class ContactFactory
...
@@ -67,7 +67,9 @@ class ContactFactory
}
}
Account
::
getInstance
()
->
addNormalMember
([
$contact
[
'UserName'
]
=>
[
'type'
=>
$type
,
'info'
=>
$contact
]]);
Account
::
getInstance
()
->
addNormalMember
([
$contact
[
'UserName'
]
=>
[
'type'
=>
$type
,
'info'
=>
$contact
]]);
}
}
$this
->
getBatchGroupMembers
();
$this
->
getBatchGroupMembers
();
file_put_contents
(
$this
->
server
->
config
[
'tmp'
]
.
'account.json'
,
json_encode
(
Account
::
getInstance
()
->
all
()));
}
}
/**
/**
...
...
src/Core/MessageHandler.php
View file @
0e2c03a
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
namespace
Hanson\Robot\Core
;
namespace
Hanson\Robot\Core
;
use
Closure
;
use
Closure
;
use
Hanson\Robot\Collections\Account
;
use
Hanson\Robot\Message\Message
;
use
Hanson\Robot\Message\Message
;
use
Hanson\Robot\Support\Log
;
use
Hanson\Robot\Support\Log
;
...
@@ -90,16 +91,30 @@ class MessageHandler
...
@@ -90,16 +91,30 @@ class MessageHandler
}
}
$message
=
$this
->
sync
();
$message
=
$this
->
sync
();
foreach
(
$message
[
'AddMsgList'
]
as
$msg
)
{
foreach
(
$message
[
'AddMsgList'
]
as
$msg
)
{
Log
::
echo
((
new
Message
)
->
make
(
$selector
,
$msg
)
->
content
->
msg
);
$content
=
(
new
Message
)
->
make
(
$selector
,
$msg
);
$response
=
call_user_func_array
(
$this
->
handler
,
[
$content
]);
$this
->
send
(
$response
,
$content
);
}
// Log::echo(json_encode($message));
}
private
function
send
(
$response
,
$content
)
{
if
(
!
$response
&&
!
is_string
(
$response
)){
return
false
;
}
}
Log
::
echo
(
json_encode
(
$message
));
// $messages = (new Message)->make($selector, $message);
$this
->
server
->
http
->
json
(
Server
::
BASE_URI
.
'/webwxsendmsg?pass_ticket='
.
$this
->
server
->
passTicket
,
[
//
'BaseRequest'
=>
$this
->
server
->
baseRequest
,
// foreach ($messages as $message) {
'Msg'
=>
[
// call_user_func_array($this->handler, [$message]);
'Type'
=>
1
,
// }
'Content'
=>
urlencode
(
$response
),
'FromUserName'
=>
$this
->
server
->
getMyAccount
(),
'ToUserName'
=>
$content
->
to
]
]);
}
}
/**
/**
...
...
src/Core/Server.php
View file @
0e2c03a
...
@@ -264,6 +264,11 @@ class Server
...
@@ -264,6 +264,11 @@ class Server
return
$fromUserName
===
static
::
$myAccount
[
'UserName'
];
return
$fromUserName
===
static
::
$myAccount
[
'UserName'
];
}
}
public
function
getMyAccount
()
{
return
static
::
$myAccount
[
'UserName'
];
}
public
function
setMessageHandler
(
\Closure
$closure
)
public
function
setMessageHandler
(
\Closure
$closure
)
{
{
if
(
!
is_callable
(
$closure
)){
if
(
!
is_callable
(
$closure
)){
...
...
src/Message/Message.php
View file @
0e2c03a
...
@@ -76,7 +76,7 @@ class Message
...
@@ -76,7 +76,7 @@ class Message
$this
->
setTo
();
$this
->
setTo
();
$this
->
setContent
();
//
$this->setContent();
$this
->
setType
();
$this
->
setType
();
...
@@ -90,32 +90,12 @@ class Message
...
@@ -90,32 +90,12 @@ class Message
*/
*/
private
function
setFrom
()
private
function
setFrom
()
{
{
$account
=
Account
::
getInstance
();
$this
->
from
=
Account
::
getInstance
()
->
getContact
(
$this
->
rawMsg
[
'FromUserName'
]);
$from
=
$this
->
rawMsg
[
'FromUserName'
];
$fromType
=
substr
(
$this
->
rawMsg
[
'FromUserName'
],
0
,
2
)
===
'@@'
?
Account
::
GROUP_MEMBER
:
Account
::
NORMAL_MEMBER
;
$this
->
from
=
$account
->
getContact
(
$from
,
$fromType
);
//
// if($this->sender->type !== 'Group'){
// $this->sender->from = $account->getContact($this->rawMsg['FromUserName'], Account::NORMAL_MEMBER);
// }
//
// $this->sender->name = html_entity_decode($this->sender->name);
}
}
private
function
setTo
()
private
function
setTo
()
{
{
$account
=
Account
::
getInstance
();
$this
->
to
=
Account
::
getInstance
()
->
getContact
(
$this
->
rawMsg
[
'ToUserName'
]);
$from
=
$this
->
rawMsg
[
'ToUserName'
];
$fromType
=
substr
(
$this
->
rawMsg
[
'ToUserName'
],
0
,
2
)
===
'@@'
?
Account
::
GROUP_MEMBER
:
Account
::
NORMAL_MEMBER
;
$this
->
to
=
$account
->
getContact
(
$from
,
$fromType
);
}
}
private
function
setFromType
()
private
function
setFromType
()
...
@@ -197,8 +177,24 @@ class Message
...
@@ -197,8 +177,24 @@ class Message
$this
->
type
=
'Animation'
;
$this
->
type
=
'Animation'
;
break
;
break
;
case
49
:
case
49
:
$this
->
type
=
'Animation'
;
$this
->
type
=
'Share'
;
break
;
case
62
:
$this
->
type
=
'Video'
;
break
;
case
53
:
$this
->
type
=
'VideoCall'
;
break
;
case
10002
:
$this
->
type
=
'Redraw'
;
break
;
break
;
case
10000
:
$this
->
type
=
'Unknown'
;
break
;
default
:
$this
->
type
=
'Unknown'
;
break
;
}
}
}
}
...
...
test/test.php
View file @
0e2c03a
...
@@ -36,5 +36,7 @@ $robot->server->setMessageHandler(function($message){
...
@@ -36,5 +36,7 @@ $robot->server->setMessageHandler(function($message){
// # do something;
// # do something;
// }
// }
print_r
(
$message
);
});
});
$robot
->
server
->
run
();
$robot
->
server
->
run
();
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