Skip to content

Instantly share code, notes, and snippets.

@lajunta
Created November 18, 2013 06:47
Show Gist options
  • Save lajunta/7523646 to your computer and use it in GitHub Desktop.
Save lajunta/7523646 to your computer and use it in GitHub Desktop.
#encoding: utf-8
require "json"
require "rest_client"
def get_access_token
appid="your appid"
appsecret="your appsecret"
uri = "https://api.yixin.im/cgi-bin/token?grant_type=client_credential&appid=#{appid}&secret=#{appsecret}"
res = RestClient.get(uri)
hsh = JSON.parse(res)
hsh["access_token"]
end
access_token=get_access_token
uri_string="https://api.yixin.im/cgi-bin/menu/create?access_token=#{access_token}"
menu_string=<<-MENU
{ "button":[
{ "name":"新闻中心",
"sub_button": [
{"name":"图片新闻", "type":"click", "key":"news/图片新闻" },
{"name":"通知公告", "type":"click", "key":"news/通知公告" },
{"name":"教育动态", "type":"click", "key":"news/教育动态" },
{"name":"招生考试", "type":"click", "key":"news/招生考试" }
]
},
{ "name":"活动交流",
"sub_button": [
{"name":"有奖问答", "type":"click", "key":"festival_qa" },
{"name":"文本回复", "type":"click", "key":"text_test" }
]
}
]}
MENU
menu_string.gsub!(/\s+/,"")
puts menu_string
res = RestClient.post uri_string,menu_string, :content_type => :json, :accept => :json
hsh = JSON.parse(res.body)
puts hsh
if hsh["errcode"].to_i==0
puts "Menu Created"
else
puts "Menu Failed"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment