回复的模板消息
This commit is contained in:
parent
00d79f2ed0
commit
2898805aa7
|
@ -0,0 +1 @@
|
|||
{"access_token":"8_uw_0k7gzuGR_jM5OHas7VXxNKScuDVYDAFT0MCXckv53f9QBUtlUxs4baMASygfA-Y45NVaeEFefOcfB8xcyBRdyZjVrEj_A7fr9qxYxWT7RCB8J4whon2_uE5np28JQVcABAFMR","expires_in":7200,"got_token_at":1460444599}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: 您的课程有新作业了
|
||||
|
|
Loading…
Reference in New Issue