Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
weixin_authorize
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
weixin_authorize
Commits
fa49512e
Commit
fa49512e
authored
Aug 01, 2015
by
Feng Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add API: media/uploadimg
add meida/uploadimg api. fix png image path in media testcase.
parent
b45f27ad
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletions
+26
-1
lib/weixin_authorize/api/media.rb
+13
-0
spec/api/media_spec.rb
+13
-1
No files found.
lib/weixin_authorize/api/media.rb
View file @
fa49512e
...
@@ -68,6 +68,19 @@ module WeixinAuthorize
...
@@ -68,6 +68,19 @@ module WeixinAuthorize
http_post
(
"
#{
media_base_url
}
/uploadvideo"
,
video_msg
)
http_post
(
"
#{
media_base_url
}
/uploadvideo"
,
video_msg
)
end
end
# 上传图文消息内的图片获取URL
# https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=ACCESS_TOKEN
#
# return:
# {
# "url": "http://mmbiz.qpic.cn/mmbiz/gLO17UPS6FS2xsypf378iaNhWacZ1G1UplZYWEYfwvuU6Ont96b1roYs CNFwaRrSaKTPCUdBK9DgEHicsKwWCBRQ/0"
# }
def
upload_image
(
image
)
file
=
process_file
(
image
)
upload_image_url
=
"
#{
media_base_url
}
/uploadimg"
http_post
(
upload_image_url
,
{
media:
file
},
{
type:
'image'
},
'file'
)
end
private
private
def
media_base_url
def
media_base_url
...
...
spec/api/media_spec.rb
View file @
fa49512e
...
@@ -17,13 +17,25 @@ describe WeixinAuthorize::Api::Media do
...
@@ -17,13 +17,25 @@ describe WeixinAuthorize::Api::Media do
end
end
let
(
:remote_png_path
)
do
let
(
:remote_png_path
)
do
"https://ruby-china-files.b0.upaiyun.com/
user/big_avatar/273.jp
g"
"https://ruby-china-files.b0.upaiyun.com/
photo/5982eaaa64f467d9dbda03ad4f40ea27.pn
g"
end
end
let
(
:remote_jpg_path
)
do
let
(
:remote_jpg_path
)
do
"http://g.hiphotos.baidu.com/baike/c0%3Dbaike80%2C5%2C5%2C80%2C26/sign=ce55457e4334970a537e187df4a3baad/03087bf40ad162d99455ef4d13dfa9ec8b13632762d0ed14.jpg"
"http://g.hiphotos.baidu.com/baike/c0%3Dbaike80%2C5%2C5%2C80%2C26/sign=ce55457e4334970a537e187df4a3baad/03087bf40ad162d99455ef4d13dfa9ec8b13632762d0ed14.jpg"
end
end
it
"can upload a jpg image and get url"
do
response
=
$client
.
upload_image
(
image_jpg_file
)
expect
(
response
.
code
).
to
eq
(
WeixinAuthorize
::
OK_CODE
)
expect
(
response
.
result
.
keys
).
to
eq
([
"url"
])
end
it
"can upload a png image and get url"
do
response
=
$client
.
upload_image
(
remote_png_path
)
expect
(
response
.
code
).
to
eq
(
WeixinAuthorize
::
OK_CODE
)
expect
(
response
.
result
.
keys
).
to
eq
([
"url"
])
end
it
"can upload a jpg File image"
do
it
"can upload a jpg File image"
do
response
=
$client
.
upload_media
(
image_jpg_file
,
"image"
)
response
=
$client
.
upload_media
(
image_jpg_file
,
"image"
)
expect
(
response
.
code
).
to
eq
(
WeixinAuthorize
::
OK_CODE
)
expect
(
response
.
code
).
to
eq
(
WeixinAuthorize
::
OK_CODE
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment