From 96d0b2e717fb345aaff60f88b29f31bdef172699 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 19 Jan 2016 14:07:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=91=E5=AE=9A=E7=94=A8=E6=88=B7=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/wechats_controller.rb | 38 +++++++++++++++++++++------ config/routes.rb | 8 ++++-- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 880b5d6de..24de889a8 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index aa97e84e5..3ed832368 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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")