绑定用户事件

This commit is contained in:
guange 2016-01-19 14:07:59 +08:00
parent 571196ad2d
commit 96d0b2e717
2 changed files with 36 additions and 10 deletions

View File

@ -1,6 +1,8 @@
class WechatsController < ActionController::Base
wechat_responder
# default text responder when no other match
on :text do |request, content|
request.reply.text "echo: #{content}" # Just echo
@ -54,14 +56,6 @@ class WechatsController < ActionController::Base
end
end
on :click, with: 'MY_NEWS' do |request, key|
news = (1..count.to_i).each_with_object([]) { |n, memo| memo << { title: 'News title', content: "No. #{n} news content" } }
request.reply.news(news) do |article, n, index| # article is return object
article.item title: "#{index} #{n[:title]}", description: n[:content], pic_url: 'http://www.baidu.com/img/bdlogo.gif', url: 'http://www.baidu.com/'
end
end
# When user click the menu button
on :click, with: 'BOOK_LUNCH' do |request, key|
request.reply.text "User: #{request[:FromUserName]} click #{key}"
@ -124,4 +118,32 @@ class WechatsController < ActionController::Base
# Any not match above will fail to below
on :fallback, respond: 'fallback message'
on :click, with: 'MY_NEWS' do |request, key|
if user_binded?
news = (1..count.to_i).each_with_object([]) { |n, memo| memo << { title: 'News title', content: "No. #{n} news content" } }
request.reply.news(news) do |article, n, index| # article is return object
article.item title: "#{index} #{n[:title]}", description: n[:content], pic_url: 'http://www.baidu.com/img/bdlogo.gif', url: 'http://www.baidu.com/'
end
else
news = (1..1).each_with_object([]) { |n, memo| memo << { title: '绑定登录', content: "您还未绑定确实的用户,请先绑定." } }
request.reply.news(news) do |article, n, index| # article is return object
article.item title: "#{n[:title]}", description: n[:content], pic_url: 'https://www.trustie.net/images/trustie_logo1.png', url: login_wechat_path
end
end
end
def bind
end
def login
end
private
def user_binded?
openid = request[:FromUserName]
uw = UserWechat.where(:openid, open).first
end
end

View File

@ -1122,8 +1122,12 @@ RedmineApp::Application.routes.draw do
end
resources :at
resource :wechat, only:[:show, :create]
resource :wechat, only:[:show, :create] do
collection do
get :login
post :bind
end
end
Dir.glob File.expand_path("plugins/*", Rails.root) do |plugin_dir|
file = File.join(plugin_dir, "config/routes.rb")