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 46ac3d11
authored
Jan 13, 2017
by
HanSon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
完成发送图片,修改撤回
1 parent
c532cc2b
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
108 additions
and
30 deletions
README.md
example/image.php
example/recall.php
src/Core/Server.php
src/Message/Image.php
src/Message/Message.php
src/Message/Recall.php
src/Message/UploadAble.php
src/Support/ObjectAble.php
README.md
View file @
46ac3d1
...
...
@@ -304,7 +304,7 @@ $robot->server->setCustomHandler(function(){
-
[
]
命令行操作信息发送
-
[
]
消息抽象成每个类
-
[
]
抽象消息
-
[
]
群操作
-
[
]
创建群
...
...
@@ -327,6 +327,11 @@ $robot->server->setCustomHandler(function(){
-
[
]
发送图片
-
[
]
发送表情
-
[
]
消息存储
-
[
x
]
语音
-
[
x
]
图片
-
[
]
视频
-
[
]
消息处理
-
[
x
]
文字
-
[
x
]
图片
...
...
example/image.php
View file @
46ac3d1
...
...
@@ -20,7 +20,12 @@ $robot = new Robot([
$robot
->
server
->
setMessageHandler
(
function
(
$message
){
/** @var $message Message */
if
(
$message
->
content
===
'测试图片'
){
// https://wx2.qq.com/cgi-bin/mmwebwx-bin
// 自己发就发送给自己
Image
::
send
(
$message
->
username
,
realpath
(
__DIR__
.
'/./../tmp/jpg/1547651860337387181.jpg'
));
}
if
(
$message
->
type
===
'Recall'
&&
$message
->
rawMsg
[
'FromUserName'
]
!==
myself
()
->
username
){
Console
::
log
(
$message
->
content
);
Message
::
send
(
$message
->
content
,
$message
->
username
);
Image
::
send
(
$message
->
username
,
realpath
(
__DIR__
.
'/./../tmp/jpg/1547651860337387181.jpg'
));
}
...
...
example/recall.php
View file @
46ac3d1
...
...
@@ -19,10 +19,16 @@ $robot = new Robot([
$robot
->
server
->
setMessageHandler
(
function
(
$message
){
/** @var $message Message */
// 发送撤回消息 (排除自己)
print_r
(
http
()
->
getClient
()
->
getConfig
(
'cookies'
)
->
toArray
());
if
(
$message
->
type
===
'Recall'
&&
$message
->
rawMsg
[
'FromUserName'
]
!==
myself
()
->
username
){
Console
::
log
(
$message
->
content
);
Message
::
send
(
$message
->
content
,
$message
->
username
);
if
(
$message
->
type
===
'Recall'
&&
$message
->
rawMsg
[
'FromUserName'
]
!==
myself
()
->
username
){
// Message::send($message->content, $message->username);
$message
=
message
()
->
get
(
$message
->
msgId
);
$nickname
=
$message
[
'sender'
]
?
$message
[
'sender'
][
'NickName'
]
:
account
()
->
getAccount
(
$message
[
'username'
])[
'NickName'
];
$content
=
"
{
$nickname
}
刚撤回了消息 "
.
$message
[
'type'
]
===
'Text'
?
"
\"
{
$message
[
'content'
]
}
\"
"
:
null
;
if
(
$message
[
'type'
]
===
'Image'
){
\Hanson\Robot\Message\Image
::
send
(
$message
->
username
,
realpath
(
__DIR__
.
"/./../tmp/jpg/
{
$message
->
msgId
}
.jpg"
));
}
else
{
return
$content
;
}
}
});
...
...
src/Core/Server.php
View file @
46ac3d1
...
...
@@ -111,8 +111,9 @@ class Server
$content
=
http
()
->
get
(
'https://login.weixin.qq.com/jslogin'
,
[
'appid'
=>
'wx782c26e4c19acffb'
,
'fun'
=>
'new'
,
//
'lang' => 'zh_CN',
'lang'
=>
'zh_CN'
,
// '_' => time() * 1000 . random_int(1, 999)
'_'
=>
time
()
]);
preg_match
(
'/window.QRLogin.code = (\d+); window.QRLogin.uuid = \"(\S+?)\"/'
,
$content
,
$matches
);
...
...
src/Message/Image.php
View file @
46ac3d1
...
...
@@ -29,7 +29,6 @@ class Image extends Message
$mediaId
=
$response
[
'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'
=>
[
...
...
@@ -37,13 +36,13 @@ class Image extends Message
'MediaId'
=>
$mediaId
,
'FromUserName'
=>
myself
()
->
username
,
'ToUserName'
=>
$username
,
'LocalID'
=>
$clientMsgId
,
'ClientMsgId'
=>
$clientMsgId
'LocalID'
=>
time
()
*
1e4
,
'ClientMsgId'
=>
time
()
*
1e4
]
];
$result
=
http
()
->
post
(
$url
,
json_encode
(
$data
,
JSON_UNESCAPED_UNICODE
),
true
);
$result
=
http
()
->
json
(
$url
,
$data
,
true
);
print_r
(
$result
);
if
(
$result
[
'BaseResponse'
][
'Ret'
]
!=
0
){
Console
::
log
(
'发送图片失败'
);
...
...
src/Message/Message.php
View file @
46ac3d1
...
...
@@ -96,13 +96,14 @@ class Message
*/
private
function
setFrom
()
{
$this
->
from
=
contact
()
->
getContactByUsername
(
$this
->
rawMsg
[
'FromUserName'
]);
$this
->
from
=
$this
->
toObject
(
account
()
->
getAccount
(
$this
->
rawMsg
[
'FromUserName'
]));
// $this->from = contact()->getContactByUsername($this->rawMsg['FromUserName']);
$this
->
username
=
$this
->
rawMsg
[
'FromUserName'
];
}
private
function
setTo
()
{
$this
->
to
=
contact
()
->
getContactByUsername
(
$this
->
rawMsg
[
'ToUserName'
]
);
$this
->
to
=
$this
->
toObject
(
contact
()
->
getContactByUsername
(
$this
->
rawMsg
[
'ToUserName'
])
);
}
private
function
setFromType
()
...
...
@@ -213,10 +214,9 @@ class Message
break
;
case
10002
:
$this
->
type
=
'Recall'
;
// 撤回
$msgId
=
$this
->
parseMsgId
(
$this
->
rawMsg
[
'Content'
]);
$message
=
message
()
->
get
(
$msgId
);
$nickname
=
$message
[
'sender'
]
?
$message
[
'sender'
][
'NickName'
]
:
account
()
->
getAccount
(
$message
[
'username'
])[
'NickName'
];
$this
->
content
=
"
{
$nickname
}
刚撤回了消息
\"
{
$message
[
'content'
]
}
\"
"
;
$this
->
msgId
=
$msgId
=
$this
->
parseMsgId
(
$this
->
rawMsg
[
'Content'
]);
// if($message['type'] === )
break
;
default
:
$this
->
type
=
'Unknown'
;
...
...
@@ -231,7 +231,7 @@ class Message
*/
private
function
handleGroupContent
(
$content
)
{
if
(
!
$content
&&
!
str_contains
(
$content
,
'<br/>'
)){
if
(
!
$content
||
!
str_contains
(
$content
,
'<br/>'
)){
return
;
}
list
(
$uid
,
$content
)
=
explode
(
'<br/>'
,
$content
,
2
);
...
...
@@ -313,4 +313,9 @@ class Message
return
true
;
}
private
function
toObject
(
Array
$array
)
{
return
json_decode
(
json_encode
(
$array
));
}
}
\ No newline at end of file
src/Message/Recall.php
0 → 100644
View file @
46ac3d1
<?php
/**
* Created by PhpStorm.
* User: HanSon
* Date: 2017/1/13
* Time: 15:48
*/
namespace
Hanson\Robot\Message
;
class
Recall
extends
Message
{
public
$raw
;
/**
* @var string 上一条撤回的msgId
*/
public
$msgId
;
public
$msg
;
public
$content
;
public
function
__construct
(
array
$msg
)
{
$this
->
raw
=
$msg
;
$msgId
=
$this
->
parseMsgId
(
$this
->
rawMsg
[
'Content'
]);
$this
->
msg
=
$message
=
message
()
->
get
(
$msgId
);
$nickname
=
$message
[
'sender'
]
?
$message
[
'sender'
][
'NickName'
]
:
account
()
->
getAccount
(
$message
[
'username'
])[
'NickName'
];
$this
->
content
=
"
{
$nickname
}
刚撤回了消息 "
.
$message
[
'type'
]
===
'Text'
?
"
\"
{
$message
[
'content'
]
}
\"
"
:
null
;
}
/**
* 解析message获取msgId
*
* @param $xml
* @return string msgId
*/
private
function
parseMsgId
(
$xml
)
{
preg_match
(
'/<msgid>(\d+)<\/msgid>/'
,
$xml
,
$matches
);
return
$matches
[
1
];
}
}
\ No newline at end of file
src/Message/UploadAble.php
View file @
46ac3d1
...
...
@@ -37,7 +37,6 @@ trait UploadAble
'id'
=>
'WU_FILE_'
.
static
::
$mediaCount
,
'name'
=>
basename
(
$file
),
'type'
=>
$mime
,
// 'lastModifieDate' => gmdate('D M d Y H:i:s', filemtime($file) ).' GMT+0800 (CST)',
'lastModifieDate'
=>
gmdate
(
'D M d Y H:i:s TO'
,
filemtime
(
$file
))
.
' (CST)'
,
'size'
=>
filesize
(
$file
),
'mediatype'
=>
$mediaType
,
...
...
@@ -55,24 +54,16 @@ trait UploadAble
],
JSON_UNESCAPED_UNICODE
|
JSON_UNESCAPED_SLASHES
),
'webwx_data_ticket'
=>
static
::
getTicket
(),
'pass_ticket'
=>
(
server
()
->
passTicket
),
// 'filename' => "@{$file};filename=".basename($file),
// 'filename' => file_get_contents($file),
'filename'
=>
fopen
(
$file
,
'r'
),
// 'filename' => $file
// 'filename' => curl_file_create($file, $mime, basename($file))
];
$data
=
static
::
dataToMultipart
(
$data
);
// $result = http()->post($url, $data, true);
$result
=
http
()
->
request
(
$url
,
'post'
,
[
'multipart'
=>
$data
]);
$result
=
json_decode
(
$result
,
true
);
print_r
(
$data
);
print_r
(
$result
);
if
(
$result
[
'BaseResponse'
][
'Ret'
]
==
0
){
return
$result
;
}
...
...
@@ -109,7 +100,6 @@ trait UploadAble
];
if
(
$key
===
'filename'
){
$field
[
'filename'
]
=
basename
(
static
::
$file
);
// $field['Content-type'] = 'application/octet-stream';
}
$result
[]
=
$field
;
}
...
...
src/Support/ObjectAble.php
0 → 100644
View file @
46ac3d1
<?php
/**
* Created by PhpStorm.
* User: HanSon
* Date: 2017/1/13
* Time: 17:23
*/
namespace
Hanson\Robot\Support
;
trait
ObjectAble
{
public
function
toObject
(
Array
$array
)
{
return
json_decode
(
json_encode
(
$array
));
}
}
\ 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