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 04712535
authored
Jan 11, 2017
by
HanSon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
还没修复
1 parent
728e78dc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
9 deletions
example/image.php
src/Message/UploadAble.php
example/image.php
View file @
0471253
...
@@ -20,7 +20,7 @@ $robot = new Robot([
...
@@ -20,7 +20,7 @@ $robot = new Robot([
$robot
->
server
->
setMessageHandler
(
function
(
$message
){
$robot
->
server
->
setMessageHandler
(
function
(
$message
){
/** @var $message Message */
/** @var $message Message */
if
(
$message
->
content
===
'测试图片'
){
if
(
$message
->
content
===
'测试图片'
){
Image
::
send
(
$message
->
username
,
realpath
(
__DIR__
.
'/./../tmp/jpg/
843242266304844229
.jpg'
));
Image
::
send
(
$message
->
username
,
realpath
(
__DIR__
.
'/./../tmp/jpg/
5102437722783331610
.jpg'
));
}
}
});
});
...
...
src/Message/UploadAble.php
View file @
0471253
...
@@ -37,7 +37,8 @@ trait UploadAble
...
@@ -37,7 +37,8 @@ trait UploadAble
'id'
=>
'WU_FILE_'
.
static
::
$mediaCount
,
'id'
=>
'WU_FILE_'
.
static
::
$mediaCount
,
'name'
=>
basename
(
$file
),
'name'
=>
basename
(
$file
),
'type'
=>
$mime
,
'type'
=>
$mime
,
'lastModifieDate'
=>
date
(
'D M m Y H:i:s'
)
.
' GMT+0800 (CST)'
,
// 'lastModifieDate' => gmdate('D M d Y H:i:s', filemtime($file) ).' GMT+0800 (CST)',
'lastModifieDate'
=>
date
(
'D M d Y H:i:s'
,
filemtime
(
$file
))
.
' GMT+0800 (CST)'
,
'size'
=>
filesize
(
$file
),
'size'
=>
filesize
(
$file
),
'mediatype'
=>
$mediaType
,
'mediatype'
=>
$mediaType
,
'uploadmediarequest'
=>
json_encode
([
'uploadmediarequest'
=>
json_encode
([
...
@@ -47,10 +48,10 @@ trait UploadAble
...
@@ -47,10 +48,10 @@ trait UploadAble
'StartPos'
=>
0
,
'StartPos'
=>
0
,
'DataLen'
=>
filesize
(
$file
),
'DataLen'
=>
filesize
(
$file
),
'MediaType'
=>
4
,
'MediaType'
=>
4
,
//
'UploadType' => 2,
'UploadType'
=>
2
,
//
'FromUserName' => myself()->username,
'FromUserName'
=>
myself
()
->
username
,
//
'ToUserName' => $username,
'ToUserName'
=>
$username
,
//
'FileMd5' => md5_file($file)
'FileMd5'
=>
md5_file
(
$file
)
],
JSON_UNESCAPED_UNICODE
|
JSON_UNESCAPED_SLASHES
),
],
JSON_UNESCAPED_UNICODE
|
JSON_UNESCAPED_SLASHES
),
'webwx_data_ticket'
=>
static
::
getTicket
(),
'webwx_data_ticket'
=>
static
::
getTicket
(),
'pass_ticket'
=>
urldecode
(
server
()
->
passTicket
),
'pass_ticket'
=>
urldecode
(
server
()
->
passTicket
),
...
@@ -61,13 +62,15 @@ trait UploadAble
...
@@ -61,13 +62,15 @@ trait UploadAble
// 'filename' => curl_file_create($file, $mime, basename($file))
// 'filename' => curl_file_create($file, $mime, basename($file))
];
];
$data
=
static
::
dataToMultipart
(
$data
);
//
$data = static::dataToMultipart($data);
$result
=
http
()
->
post
(
$url
,
$data
,
true
);
$result
=
http
()
->
post
(
$url
,
$data
,
true
);
// $result = http()->request($url, 'post', [
// $result = http()->request($url, 'post', [
// 'multipart' => $data
// 'multipart' => $data
// ]);
// ]);
// $result = json_decode($result, true);
print_r
(
$data
);
print_r
(
$data
);
print_r
(
$result
);
print_r
(
$result
);
...
@@ -96,7 +99,7 @@ trait UploadAble
...
@@ -96,7 +99,7 @@ trait UploadAble
return
$cookies
[
$key
][
'Value'
];
return
$cookies
[
$key
][
'Value'
];
}
}
private
function
dataToMultipart
(
$data
)
private
static
function
dataToMultipart
(
$data
)
{
{
$result
=
[];
$result
=
[];
...
@@ -105,7 +108,10 @@ trait UploadAble
...
@@ -105,7 +108,10 @@ trait UploadAble
'name'
=>
$key
,
'name'
=>
$key
,
'contents'
=>
$item
'contents'
=>
$item
];
];
if
(
$key
===
'filename'
)
$field
[
'filename'
]
=
basename
(
static
::
$file
);
if
(
$key
===
'filename'
){
$field
[
'filename'
]
=
basename
(
static
::
$file
);
$field
[
'Content-type'
]
=
'image/jpeg'
;
}
$result
[]
=
$field
;
$result
[]
=
$field
;
}
}
...
...
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