Commit 4531cdcd by lanrion

updated media api

parent 58883640
...@@ -13,11 +13,14 @@ module WeixinAuthorize ...@@ -13,11 +13,14 @@ module WeixinAuthorize
http_upload(upload_media_url, {media: file, media_type: type}) http_upload(upload_media_url, {media: file, media_type: type})
end end
# 目前仅仅把下载链接返回给第三方开发者,由第三方开发者处理下载
# php重新写入文件方式:
# http://www.cnblogs.com/txw1958/p/weixin80-upload-download-media-file.html # http://www.cnblogs.com/txw1958/p/weixin80-upload-download-media-file.html
def download_media(media_id) def download_media_url(media_id)
download_media_url = "#{media_base_url}/get" download_media_url = file_endpoint + "#{media_base_url}/get"
http_download(download_media_url, {media_id: media_id}) download_media_url += "?access_token=#{get_access_token}"
download_media_url += "&media_id=#{media_id}"
download_media_url
end end
private private
...@@ -34,12 +37,6 @@ module WeixinAuthorize ...@@ -34,12 +37,6 @@ module WeixinAuthorize
JSON.parse(RestClient.post(upload_url, options)) JSON.parse(RestClient.post(upload_url, options))
end end
def http_download(url, options={})
options = options.merge(access_token_param)
download_url = file_endpoint + url
RestClient.get(download_url, :params => options)
end
end end
end end
end end
...@@ -15,18 +15,11 @@ describe WeixinAuthorize::Api::Media do ...@@ -15,18 +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" do # it "#download_media_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(media_id) # response = $client.download_media_url(media_id)
binding.pry # response
expect(response.raw_headers.keys).to eq(["server", # end
"date",
"content-type",
"connection",
"content-disposition",
"cache-control",
"content-length"])
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment