|
|
|
@ -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
|
|
|
|
|