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
b4228a30
Commit
b4228a30
authored
Mar 30, 2014
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor media apis
parent
c6eea351
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
21 deletions
+11
-21
lib/weixin_authorize/api/media.rb
+5
-15
spec/api/media_spec.rb
+6
-6
No files found.
lib/weixin_authorize/api/media.rb
View file @
b4228a30
...
@@ -7,19 +7,18 @@ module WeixinAuthorize
...
@@ -7,19 +7,18 @@ module WeixinAuthorize
# http请求方式: POST/FORM
# http请求方式: POST/FORM
# http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE
# http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE
# 支持传路径或者文件类型
# 支持传路径或者文件类型
def
upload_media
(
media
,
type
)
def
upload_media
(
media
,
media_
type
)
file
=
media
.
is_a?
(
File
)
?
media
:
File
.
new
(
media
)
file
=
media
.
is_a?
(
File
)
?
media
:
File
.
new
(
media
)
upload_media_url
=
"
#{
media_base_url
}
/upload"
upload_media_url
=
"
#{
media_base_url
}
/upload"
http_
upload
(
upload_media_url
,
{
media:
file
,
media_type:
type
}
)
http_
post
(
upload_media_url
,
{
media:
file
},
{
type:
media_type
},
"file"
)
end
end
# 目前仅仅把下载链接返回给第三方开发者,由第三方开发者处理下载
# 目前仅仅把下载链接返回给第三方开发者,由第三方开发者处理下载
# php重新写入文件方式:
# http://www.cnblogs.com/txw1958/p/weixin80-upload-download-media-file.html
def
download_media_url
(
media_id
)
def
download_media_url
(
media_id
)
download_media_url
=
file_endpoint
+
"
#{
media_base_url
}
/get"
download_media_url
=
file_endpoint
+
"
#{
media_base_url
}
/get"
download_media_url
+=
"?access_token=
#{
get_access_token
}
"
params
=
URI
.
encode_www_form
(
"access_token"
=>
get_access_token
,
download_media_url
+=
"&media_id=
#{
media_id
}
"
"media_id"
=>
media_id
)
download_media_url
+=
"?
#{
params
}
"
download_media_url
download_media_url
end
end
...
@@ -28,15 +27,6 @@ module WeixinAuthorize
...
@@ -28,15 +27,6 @@ module WeixinAuthorize
def
media_base_url
def
media_base_url
"/media"
"/media"
end
end
def
http_upload
(
url
,
options
)
media_type
=
options
.
delete
(
:media_type
)
upload_url
=
file_endpoint
+
url
upload_url
+=
"?access_token=
#{
get_access_token
}
"
upload_url
+=
"&type=
#{
media_type
}
"
JSON
.
parse
(
RestClient
.
post
(
upload_url
,
options
))
end
end
end
end
end
end
end
spec/api/media_spec.rb
View file @
b4228a30
...
@@ -15,11 +15,11 @@ describe WeixinAuthorize::Api::Media do
...
@@ -15,11 +15,11 @@ describe WeixinAuthorize::Api::Media do
expect
(
response
.
keys
).
to
eq
([
"type"
,
"media_id"
,
"created_at"
])
expect
(
response
.
keys
).
to
eq
([
"type"
,
"media_id"
,
"created_at"
])
end
end
# it "#download_media_
url" do
it
"#download_media_url return a String
url"
do
#
image = $client.upload_media(image_file, "image")
image
=
$client
.
upload_media
(
image_file
,
"image"
)
#
media_id = image["media_id"]
media_id
=
image
[
"media_id"
]
#
response = $client.download_media_url(media_id)
response
=
$client
.
download_media_url
(
media_id
)
# response
expect
(
response
.
class
).
to
eq
(
String
)
#
end
end
end
end
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