From 7f5bb11a5f28cb448995bda653f1c5fa4e87faa3 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 19 Jan 2016 15:25:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A4=E8=AF=81=E5=90=8E=E5=9B=9E=E5=A4=8D?= =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/wechats_controller.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 3cf0664e4..993007308 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -118,10 +118,15 @@ class WechatsController < ActionController::Base on :fallback, respond: 'fallback message' on :click, with: 'MY_NEWS' do |request, key| - if user_binded?(request[:FromUserName]) - news = (1..count.to_i).each_with_object([]) { |n, memo| memo << { title: 'News title', content: "No. #{n} news content" } } + uw = user_binded?(request[:FromUserName]) + if uw + ua = UserActivity.where(user_id: uw.user.id).order("id desc").limit(5) + news = ua.map do |ua| + {title: "act_type: #{ua.act_type}, act_id: #{ua.act_id}", content: "container_id: #{ua.container_id}, container_type: #{ua.container_type}"} + end + 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/' + article.item title: "#{index} #{n[:title]}", description: n[:content], pic_url: 'https://www.trustie.net/images/trustie_logo1.png', url: 'http://www.baidu.com/' end else openid = request[:FromUserName]