From f951d22d56052d5919d15049974dd0875e42ed2d Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 8 Apr 2016 20:53:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E5=B8=83=E5=8D=9A=E5=AE=A2500?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/blog_comment.rb | 72 ++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index 7e368064b..c60a1d87e 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -78,40 +78,44 @@ class BlogComment < ActiveRecord::Base #博客回复微信模板消息 def blog_wechat_message - uw = UserWechat.where(user_id: self.parent.author_id).first - #unless uw.nil? && self.parent.author_id != User.current.id - unless uw.nil? - data = { - touser:uw.openid, - template_id:"A_3f5v90-zK73V9Kijm-paDkl9S-NuM8Cf-1UJi92_c", - url:"http://weixin.qq.com/download", - topcolor:"#FF0000", - data:{ - first: { - value:"您的博客有新回复了", - color:"#173177" - }, - keyword1:{ - value:self.author.try(:realname), - color:"#173177" - }, - keyword2:{ - value:format_time(self.created_at), - color:"#173177" - }, - keyword3:{ - value:self.content.html_safe, - color:"#173177" - }, - remark:{ - value:"具体内容请点击详情查看网站", - color:"#173177" - } - } - } - logger.info "start send template message: #{data}" - req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) - logger.info "send over. #{req}" + # 发布博客 + unless self.parent_id.nil? + uw = UserWechat.where(user_id: self.parent.author_id).first + #unless uw.nil? && self.parent.author_id != User.current.id + unless uw.nil? + data = { + touser:uw.openid, + template_id:"A_3f5v90-zK73V9Kijm-paDkl9S-NuM8Cf-1UJi92_c", + url:"http://weixin.qq.com/download", + topcolor:"#FF0000", + data:{ + first: { + value:"您的博客有新回复了", + color:"#173177" + }, + keyword1:{ + value:self.author.try(:realname), + color:"#173177" + }, + keyword2:{ + value:format_time(self.created_at), + color:"#173177" + }, + keyword3:{ + value:self.content.html_safe, + color:"#173177" + }, + remark:{ + value:"具体内容请点击详情查看网站", + color:"#173177" + } + } + } + logger.info "start send template message: #{data}" + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + logger.info "send over. #{req}" + end end + end end