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 728e78dc
authored
Jan 11, 2017
by
hanccc
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
还没改完上传问题。。。
1 parent
a39fe166
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
8 deletions
example/image.php
src/Core/Http.php
src/Message/UploadAble.php
example/image.php
View file @
728e78d
...
...
@@ -20,7 +20,7 @@ $robot = new Robot([
$robot
->
server
->
setMessageHandler
(
function
(
$message
){
/** @var $message Message */
if
(
$message
->
content
===
'测试图片'
){
Image
::
send
(
$message
->
username
,
realpath
(
__DIR__
.
'/./../tmp/jpg/
1483791274935140574833210401
.jpg'
));
Image
::
send
(
$message
->
username
,
realpath
(
__DIR__
.
'/./../tmp/jpg/
843242266304844229
.jpg'
));
}
});
...
...
src/Core/Http.php
View file @
728e78d
...
...
@@ -18,8 +18,6 @@ class Http
protected
$client
;
public
$cookies
;
/**
* @return Http
*/
...
...
src/Message/UploadAble.php
View file @
728e78d
...
...
@@ -18,6 +18,8 @@ namespace Hanson\Robot\Message;
trait
UploadAble
{
static
$file
;
/**
* @param $username
* @param $file
...
...
@@ -27,15 +29,15 @@ trait UploadAble
{
$url
=
'https://file.wx.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json'
;
static
::
$mediaCount
=
++
static
::
$mediaCount
;
static
::
$file
=
$file
;
$lastModifyDate
=
gmdate
(
'D M d Y H:i:s TO'
,
filemtime
(
$file
));
list
(
$mime
,
$mediaType
)
=
static
::
getMediaType
(
$file
);
$data
=
[
'id'
=>
'WU_FILE_'
.
static
::
$mediaCount
,
'name'
=>
$file
,
'name'
=>
basename
(
$file
)
,
'type'
=>
$mime
,
'lastModifieDate'
=>
$lastModifyDate
,
'lastModifieDate'
=>
date
(
'D M m Y H:i:s'
)
.
' GMT+0800 (CST)'
,
'size'
=>
filesize
(
$file
),
'mediatype'
=>
$mediaType
,
'uploadmediarequest'
=>
json_encode
([
...
...
@@ -51,12 +53,21 @@ trait UploadAble
// 'FileMd5' => md5_file($file)
],
JSON_UNESCAPED_UNICODE
|
JSON_UNESCAPED_SLASHES
),
'webwx_data_ticket'
=>
static
::
getTicket
(),
'pass_ticket'
=>
server
()
->
passTicket
,
'filename'
=>
'@'
.
$file
'pass_ticket'
=>
urldecode
(
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
// ]);
print_r
(
$data
);
print_r
(
$result
);
...
...
@@ -84,4 +95,21 @@ trait UploadAble
return
$cookies
[
$key
][
'Value'
];
}
private
function
dataToMultipart
(
$data
)
{
$result
=
[];
foreach
(
$data
as
$key
=>
$item
)
{
$field
=
[
'name'
=>
$key
,
'contents'
=>
$item
];
if
(
$key
===
'filename'
)
$field
[
'filename'
]
=
basename
(
static
::
$file
);
$result
[]
=
$field
;
}
return
$result
;
}
}
\ 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