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 e71f4e1c
authored
Jan 09, 2017
by
HanSon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
增加上传
1 parent
f24efc01
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
6 deletions
README.md
src/Message/Message.php
src/Message/UploadAble.php
README.md
View file @
e71f4e1
...
...
@@ -304,6 +304,8 @@ $robot->server->setCustomHandler(function(){
-
[
]
命令行操作信息发送
-
[
]
消息抽象成每个类
-
[
x
]
增加消息集合存储
-
[
]
消息发送
...
...
@@ -322,6 +324,7 @@ $robot->server->setCustomHandler(function(){
-
[
]
表情
-
[
]
分享
-
[
]
视频
-
[
]
小程序
# 已知bug
...
...
src/Message/Message.php
View file @
e71f4e1
...
...
@@ -75,6 +75,8 @@ class Message
public
$rawMsg
;
private
$mediaCount
=
-
1
;
public
function
make
(
$selector
,
$msg
)
{
$this
->
rawMsg
=
$msg
;
...
...
@@ -155,7 +157,6 @@ class Message
*/
private
function
handleMessageByType
()
{
print_r
(
$this
->
rawMsg
);
switch
(
$this
->
rawMsg
[
'MsgType'
]){
case
1
:
//文本消息
if
(
Location
::
isLocation
(
$this
->
rawMsg
)){
...
...
@@ -215,8 +216,6 @@ class Message
$msgId
=
$this
->
parseMsgId
(
$this
->
rawMsg
[
'Content'
]);
$message
=
message
()
->
get
(
$msgId
);
$nickname
=
$message
[
'sender'
]
?
$message
[
'sender'
][
'NickName'
]
:
account
()
->
getAccount
(
$message
[
'username'
])[
'NickName'
];
print_r
(
$message
);
Console
::
log
(
'nickname:'
.
$nickname
);
$this
->
content
=
"
{
$nickname
}
刚撤回了消息
\"
{
$message
[
'content'
]
}
\"
"
;
break
;
default
:
...
...
@@ -334,13 +333,11 @@ class Message
);
if
(
$result
[
'BaseResponse'
][
'Ret'
]
!=
0
){
Console
::
log
(
'发送
消息
失败'
);
Console
::
log
(
'发送
图片
失败'
);
return
false
;
}
return
true
;
}
// pri
}
\ No newline at end of file
src/Message/UploadAble.php
0 → 100644
View file @
e71f4e1
<?php
/**
* Created by PhpStorm.
* User: HanSon
* Date: 2017/1/9
* Time: 16:18
*/
namespace
Hanson\Robot\Message
;
/**
* Class UploadAble
* @package Hanson\Robot\Message\
*
* @property string $mediaCount
*/
trait
UploadAble
{
/**
* @param $username
* @param $file
*/
public
function
uploadMedia
(
$username
,
$file
)
{
$url
=
'https://file.wx.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json'
;
$this
->
mediaCount
=
++
$this
->
mediaCount
;
$lastModifyDate
=
gmdate
(
'D M d Y H:i:s TO'
,
filemtime
(
$file
));
list
(
$mime
,
$mediaType
)
=
$this
->
getMediaType
(
$file
);
http
()
->
post
(
$url
,
[
'id'
=>
'WU_FILE_'
.
$this
->
mediaCount
,
'name'
=>
$file
,
'type'
=>
$mime
,
'lastModifieDate'
=>
$lastModifyDate
,
'size'
=>
filesize
(
$file
),
'mediatype'
=>
$mediaType
,
'uploadmediarequest'
=>
json_encode
([
'BaseRequest'
=>
server
()
->
baseRequest
,
'ClientMediaId'
=>
(
time
()
*
1000
)
.
mt_rand
(
10000
,
99999
),
'TotalLen'
=>
filesize
(
$file
),
'StartPos'
=>
0
,
'DataLen'
=>
filesize
(
$file
),
'MediaType'
=>
4
,
'UploadType'
=>
2
,
'FromUserName'
=>
myself
()
->
username
,
'ToUserName'
=>
$username
,
'FileMd5'
=>
md5_file
(
$file
)
],
JSON_UNESCAPED_UNICODE
|
JSON_UNESCAPED_SLASHES
),
'webwx_data_ticket'
=>
http
()
->
getClient
()
->
get
,
'pass_ticket'
=>
$pass_ticket
,
'filename'
=>
'@'
.
$file_name
]);
}
private
function
getMediaType
(
$file
)
{
$info
=
finfo_open
(
FILEINFO_MIME_TYPE
);
$mime
=
finfo_file
(
$info
,
$file
);
finfo_close
(
$info
);
return
[
$mime
,
explode
(
'/'
,
$mime
)[
0
]
===
'image'
?
'pic'
:
'doc'
];
}
}
\ 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