diff --git a/1234567 b/1234567 new file mode 100644 index 000000000..2954ee65a --- /dev/null +++ b/1234567 @@ -0,0 +1 @@ +{"access_token":"8_uw_0k7gzuGR_jM5OHas7VXxNKScuDVYDAFT0MCXckv53f9QBUtlUxs4baMASygfA-Y45NVaeEFefOcfB8xcyBRdyZjVrEj_A7fr9qxYxWT7RCB8J4whon2_uE5np28JQVcABAFMR","expires_in":7200,"got_token_at":1460444599} \ No newline at end of file diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index cfe6fe3f3..8f618476a 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -78,44 +78,12 @@ 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://www.trustie.net/", - 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}" - begin - req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) - rescue Exception => e - logger.error "[blog_comment] ===> #{e}" + if self.parent_id.nil? + self.author.watcher_users.each do |watcher| + Wechat.api.message_update_template watcher.id, "#{l(:label_new_blog_template)}", self.author.try(:realname) + " 发表了博客:" + self.title.html_safe, format_time(self.created_at) end - logger.info "send over. #{req}" + else + Wechat.api.comment_template self.parent.author_id, "#{l(:label_blog_comment_template)}", self.author.try(:realname), format_time(self.created_at), self.content.html_safe end end end diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index c34c63f2d..2774295a1 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -59,7 +59,7 @@ class HomeworkCommon < ActiveRecord::Base self.course.members.each do |m| # if m.user_id != self.user_id self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) - Wechat.api.homework_template(m.user_id, "#{l(:label_new_homework_template)}", self.course.name, self.name, self.end_time.to_s + " 23:59:59") + Wechat.api.homework_template(m.user_id, "#{l(:label_new_homework_template)}", self.course.name, self.name.html_safe, self.end_time.to_s + " 23:59:59") # end end end @@ -105,7 +105,7 @@ class HomeworkCommon < ActiveRecord::Base #修改作业后发送微信模板消息 def wechat_message self.course.members.each do |member| - Wechat.api.homework_template(member.user_id, "#{l(:label_update_homework_template)}", self.course.name, self.name, self.end_time.to_s + " 23:59:59") + Wechat.api.homework_template(member.user_id, "#{l(:label_update_homework_template)}", self.course.name, self.name.html_safe, self.end_time.to_s + " 23:59:59") end end diff --git a/app/models/issue.rb b/app/models/issue.rb index 0d72407ba..45347b5ad 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1,3 +1,4 @@ +#encoding: utf-8 # Redmine - project management software # Copyright (C) 2006-2013 Jean-Philippe Lang # @@ -16,6 +17,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class Issue < ActiveRecord::Base + require 'net/http' + require 'json' include Redmine::SafeAttributes include Redmine::Utils::DateCalculation include UserScoreHelper @@ -156,6 +159,7 @@ class Issue < ActiveRecord::Base # 指派给自己的缺陷不提示消息 unless self.author_id == self.assigned_to_id self.forge_messages << ForgeMessage.new(:user_id => self.assigned_to_id, :project_id => self.project_id, :viewed => false) + Wechat.api.message_update_template self.assigned_to_id, "#{l(:label_new_issue_template)}", self.author.try(:realname) + " 给您指派了缺陷:" + self.subject.html_safe, format_time(self.created_on) end if self.tracker_id == 5 self.project.members.each do |m| diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index c975bcaa6..ce18e1bdb 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -269,7 +269,7 @@ class JournalsForMessage < ActiveRecord::Base if self.reply_id == 0 if self.user_id != self.jour_id # 过滤自己给自己的留言消息 receivers << self.jour - Wechat.api.comment_template self.jour_id, "#{l(:label_new_journals_template)}", self.user.try(:realname), format_time(self.created_on), self.notes.html_safe + Wechat.api.message_update_template self.jour_id, "#{l(:label_new_journals_template)}", self.notes.html_safe, format_time(self.created_on) end else # 留言回复 reply_to = User.find(self.reply_id) diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 4b7180857..664e5cfac 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -17,8 +17,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class Mailer < ActionMailer::Base - require 'net/http' - require 'json' layout 'mailer' helper :application helper :issues @@ -642,9 +640,6 @@ class Mailer < ActionMailer::Base mail :to => recipients, :subject => "[ #{l(:label_user_homework)} : #{homework_common.name} #{l(:label_memo_create_succ)}]", :filter => true - @homework_common.course.members.each do |member| - mail_wechat_message member.user_id, "3e5Dj2GIx8MOcMyRKpTUEQnM7Tg0ASSCNc01NS9HCGI", "您的课程有新作业了", @homework_common.course.name, @homework_common.name, @homework_common.end_time.to_s + " 23:59:59" - end end # Builds a Mail::Message object used to email recipients of a news' project when a news item is added. @@ -710,8 +705,6 @@ class Mailer < ActionMailer::Base mail :to => recipients, :subject => "[#{news.course.name}] #{l(:label_news)}: #{news.title}", :filter => true - - mail_wechat_message news.author_id, "A_3f5v90-zK73V9Kijm-paDkl9S-NuM8Cf-1UJi92_c", "您的课程通知有新回复了", @author.try(:realname), format_time(comment.created_on), comment.comments.html_safe end end @@ -736,14 +729,7 @@ class Mailer < ActionMailer::Base :cc => cc, :subject => "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}", :filter => true - if message.parent_id == nil - message.project.members.each do |member| - mail_wechat_message member.user_id, "oKzFCdk7bsIHnGbscA__N8LPQrBkUShvpjV3-kuwWDQ", "项目讨论区有新帖子发布了", message.subject, @author.try(:realname), format_time(message.created_on) - end - else - mail_wechat_message message.parent.author_id, "A_3f5v90-zK73V9Kijm-paDkl9S-NuM8Cf-1UJi92_c", "您的帖子有新回复了", @author.try(:realname), format_time(message.created_on), message.content.html_safe - end - elsif message.course + elsif message.course redmine_headers 'Course' => message.course.id, 'Topic-Id' => (message.parent_id || message.id) @author = message.author @@ -758,14 +744,7 @@ class Mailer < ActionMailer::Base :cc => cc, :subject => "[#{message.board.course.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}", :filter => true - if message.parent_id == nil - message.course.members.each do |member| - mail_wechat_message member.user_id, "oKzFCdk7bsIHnGbscA__N8LPQrBkUShvpjV3-kuwWDQ", "课程问答区有新帖子发布了", message.subject, @author.try(:realname), format_time(message.created_on) - end - else - mail_wechat_message message.parent.author_id, "A_3f5v90-zK73V9Kijm-paDkl9S-NuM8Cf-1UJi92_c", "您的帖子有新回复了", @author.try(:realname), format_time(message.created_on), message.content.html_safe end - end end # Builds a Mail::Message object used to email the recipients of a project of the specified wiki content was added. @@ -1119,48 +1098,4 @@ class Mailer < ActionMailer::Base 1.upto(len) { |i| newpass << chars[rand(chars.size-1)] } return newpass end - - #微信模板消息 - def mail_wechat_message user_id, template_id, first, key1, key2, key3, remark="具体内容请点击详情查看网站" - uw = UserWechat.where(user_id: user_id).first - logger.info "mail_wechat_message #{user_id} #{uw}" - unless uw.nil? - data = { - touser:uw.openid, - template_id:template_id, - url:"http://www.trustie.net/", - topcolor:"#FF0000", - data:{ - first: { - value:first, - color:"#173177" - }, - keyword1:{ - value:key1, - color:"#173177" - }, - keyword2:{ - value:key2, - color:"#173177" - }, - keyword3:{ - value:key3, - color:"#173177" - }, - remark:{ - value:remark, - color:"#173177" - } - } - } - - logger.info "start send template message: #{data}" - begin - req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) - rescue Exception => e - logger.error "[mailer] ===> #{e}" - end - logger.info "send over. #{req}" - end - end end diff --git a/app/models/news.rb b/app/models/news.rb index 6746d90cd..967516e65 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -1,3 +1,4 @@ +#encoding: utf-8 # Redmine - project management software # Copyright (C) 2006-2013 Jean-Philippe Lang # @@ -16,6 +17,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class News < ActiveRecord::Base + require 'net/http' + require 'json' include Redmine::SafeAttributes belongs_to :project,:touch => true include ApplicationHelper @@ -167,6 +170,7 @@ class News < ActiveRecord::Base self.course.members.each do |m| if m.user_id != self.author_id self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) + Wechat.api.message_update_template m.user_id, "#{l(:label_new_notice_template)}", self.author.try(:realname) + " 发布了通知:" + self.title.html_safe, format_time(self.created_on) end end else diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 8990f2490..4f0c6b701 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2137,10 +2137,10 @@ zh: label_homework_comment_template: 您的作业有新回复了 label_new_journals_template: 您有新留言了 label_journals_comment_template: 您的留言有新回复了 - label_resource_name: 您的课程有新作业了 - label_resource_name: 您的课程有新作业了 - label_resource_name: 您的课程有新作业了 - label_resource_name: 您的课程有新作业了 + label_blog_comment_template: 您的博客有新回复了 + label_new_blog_template: 您的课程有新作业了 + label_new_issue_template: 您有新缺陷了 + label_new_notice_template: 您的课程有新通知了 label_resource_name: 您的课程有新作业了 label_resource_name: 您的课程有新作业了 label_resource_name: 您的课程有新作业了