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
904c7b4b
Commit
904c7b4b
authored
Mar 28, 2014
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added media api
parent
c1ee50ee
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
0 deletions
+47
-0
lib/weixin_authorize.rb
+1
-0
lib/weixin_authorize/api/media.rb
+45
-0
lib/weixin_authorize/client.rb
+1
-0
No files found.
lib/weixin_authorize.rb
View file @
904c7b4b
...
@@ -6,6 +6,7 @@ require "weixin_authorize/api/menu"
...
@@ -6,6 +6,7 @@ require "weixin_authorize/api/menu"
require
"weixin_authorize/api/custom"
require
"weixin_authorize/api/custom"
require
"weixin_authorize/api/groups"
require
"weixin_authorize/api/groups"
require
"weixin_authorize/api/qrcode"
require
"weixin_authorize/api/qrcode"
require
"weixin_authorize/api/media"
require
"weixin_authorize/client"
require
"weixin_authorize/client"
module
WeixinAuthorize
module
WeixinAuthorize
...
...
lib/weixin_authorize/api/media.rb
0 → 100644
View file @
904c7b4b
# encoding: utf-8
module
WeixinAuthorize
module
Api
module
Media
# 上传多媒体文件
# http请求方式: POST/FORM
# http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE
# 支持传路径或者文件类型
def
upload_media
(
media
,
type
)
file
=
media
.
is_a?
(
File
)
?
media
:
File
.
new
(
media
)
upload_media_url
=
"
#{
media_base_url
}
/upload"
http_upload
(
upload_media_url
,
{
media:
file
,
media_type:
type
})
end
# http://www.cnblogs.com/txw1958/p/weixin80-upload-download-media-file.html
def
download_media
(
media_id
)
download_media_url
=
"
#{
media_base_url
}
/get"
http_download
(
download_media_url
,
{
media_id:
media_id
})
end
private
def
media_base_url
"/media"
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
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
lib/weixin_authorize/client.rb
View file @
904c7b4b
...
@@ -9,6 +9,7 @@ module WeixinAuthorize
...
@@ -9,6 +9,7 @@ module WeixinAuthorize
include
Api
::
Custom
include
Api
::
Custom
include
Api
::
Groups
include
Api
::
Groups
include
Api
::
Qrcode
include
Api
::
Qrcode
include
Api
::
Media
attr_accessor
:app_id
,
:app_secret
,
:expired_at
# Time.now + expires_in
attr_accessor
:app_id
,
:app_secret
,
:expired_at
# Time.now + expires_in
attr_accessor
:access_token
,
:redis_key
attr_accessor
:access_token
,
:redis_key
...
...
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