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
9e9716f5
Commit
9e9716f5
authored
Mar 16, 2014
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added menu Apis
parent
2810c024
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
0 deletions
+58
-0
lib/weixin_authorize.rb
+1
-0
lib/weixin_authorize/api/menu.rb
+35
-0
lib/weixin_authorize/client.rb
+1
-0
spec/api/menu_spec.rb
+21
-0
No files found.
lib/weixin_authorize.rb
View file @
9e9716f5
require
"rest-client"
require
"rest-client"
require
"weixin_authorize/version"
require
"weixin_authorize/version"
require
"weixin_authorize/api/user"
require
"weixin_authorize/api/user"
require
"weixin_authorize/api/menu"
require
"weixin_authorize/client"
require
"weixin_authorize/client"
module
WeixinAuthorize
module
WeixinAuthorize
...
...
lib/weixin_authorize/api/menu.rb
0 → 100644
View file @
9e9716f5
# encoding: utf-8
module
WeixinAuthorize
module
Api
module
Menu
# 自定义菜单查询接口
# https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN
def
menu
get_menu_url
=
"
#{
menu_base_url
}
/get?
#{
access_token_param
}
"
JSON
.
parse
(
RestClient
.
get
(
get_menu_url
))
end
# 自定义菜单删除接口
# https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN
def
delete_menu
delete_menu_url
=
"
#{
menu_base_url
}
/delete?
#{
access_token_param
}
"
JSON
.
parse
(
RestClient
.
get
(
delete_menu_url
))
end
# 自定义菜单创建接口
# https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN
def
create_menu
(
menu
)
create_menu_url
=
"
#{
menu_base_url
}
/create?
#{
access_token_param
}
"
JSON
.
parse
(
RestClient
.
post
(
create_menu_url
,
menu
))
end
private
def
menu_base_url
"
#{
endpoint
}
/menu"
end
end
end
end
lib/weixin_authorize/client.rb
View file @
9e9716f5
...
@@ -5,6 +5,7 @@ module WeixinAuthorize
...
@@ -5,6 +5,7 @@ module WeixinAuthorize
class
Client
class
Client
attr_accessor
:app_id
,
:app_secret
,
:expired_at
# Time.now + expires_in
attr_accessor
:app_id
,
:app_secret
,
:expired_at
# Time.now + expires_in
include
Api
::
User
include
Api
::
User
include
Api
::
Menu
attr_accessor
:access_token
attr_accessor
:access_token
...
...
spec/api/menu_spec.rb
0 → 100644
View file @
9e9716f5
# encoding: utf-8
require
"spec_helper"
describe
WeixinAuthorize
::
Api
::
Menu
do
it
"can create a menu"
do
menu
=
'{"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC"},{"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER"},{"name":"菜单","sub_button":[{"type":"view","name":"搜索","url":"http://www.soso.com/"},{"type":"view","name":"视频","url":"http://v.qq.com/"},{"type":"click","name":"赞一下我们","key":"V1001_GOOD"}]}]}'
response
=
$client
.
create_menu
(
menu
)
expect
(
response
[
"errcode"
]).
to
eq
(
0
)
end
it
"can get a weixin Menu info"
do
menu_info
=
$client
.
menu
expect
(
menu_info
.
keys
[
0
]).
to
eq
(
"menu"
)
end
it
"can delete weixin Menu"
do
response
=
$client
.
delete_menu
expect
(
response
[
"errcode"
]).
to
eq
(
0
)
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