From 36d82e1315f77b308fd0d8994f5ad3e0276eecd0 Mon Sep 17 00:00:00 2001 From: cxt Date: Mon, 18 Apr 2016 11:24:18 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=87=BA=E7=8E=B0=E4=BA=86=E4=B8=A4=E4=B8=AA?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/wechats/login.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/wechats/login.html.erb b/app/views/wechats/login.html.erb index 27898b690..0e6fd8695 100644 --- a/app/views/wechats/login.html.erb +++ b/app/views/wechats/login.html.erb @@ -17,7 +17,7 @@
-
+
From 0cc5eca34b5fd923cac04e59a2bce20123dd5bcb Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 19 Apr 2016 09:58:51 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=BB=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E9=A1=B9=E7=9B=AE=E5=88=97=E8=A1=A8=E6=9C=89=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E7=9A=84=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/layouts/new_base_user.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/new_base_user.html.erb b/app/views/layouts/new_base_user.html.erb index 2a6df9c86..318d0db7f 100644 --- a/app/views/layouts/new_base_user.html.erb +++ b/app/views/layouts/new_base_user.html.erb @@ -251,7 +251,7 @@ %> <% if @user.projects.visible.count > 0 - projects = @user.projects.visible.select("projects.*, (SELECT MAX(created_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5) + projects = @user.projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5) else projects = [] end From ef987d6bf7aaaca4854ddb5364536e51c904a4c9 Mon Sep 17 00:00:00 2001 From: cxt Date: Wed, 20 Apr 2016 10:44:54 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E4=B8=AD=E6=9C=89html=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1234567 | 2 +- app/helpers/application_helper.rb | 15 +++++++++++++++ app/models/blog_comment.rb | 6 ++++-- app/models/comment.rb | 6 ++++-- app/models/issue.rb | 3 ++- app/models/journal.rb | 3 ++- app/models/journals_for_message.rb | 10 +++++++--- app/models/message.rb | 12 ++++++++---- app/models/news.rb | 3 ++- 9 files changed, 45 insertions(+), 15 deletions(-) diff --git a/1234567 b/1234567 index 459204fe5..b584c6f69 100644 --- a/1234567 +++ b/1234567 @@ -1 +1 @@ -{"access_token":"q51KZUeA6_-CCCH-Buy1mxFmRjcrCViHgk2mHHHqEDbjuA_pgCM1IyW1DASYvpzyB06xHiarujo3rz1Ucq3GRoXdgQ7hAoFCzkL_q3Z5vczLjwAjowAVwmulYE-cAij8ATUfADAWPQ","expires_in":7200,"got_token_at":1460601163} \ No newline at end of file +{"access_token":"GbIQJdIaX2c0IyQSOJcNNT2TxUH5aSQCNL7N92BV9oggGePRoj886HDohtqRokwPS6OVcIYF8WZTnSn717CP-czrWupY_gIHehK4UqjqXYqGkVqODXaXEB_LV0grMIwEXQDhAAAFYL","expires_in":7200,"got_token_at":1461117548} \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 366cea06b..f0f959830 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3068,3 +3068,18 @@ def host_with_protocol return Setting.protocol + "://" + Setting.host_name end +def strip_html(text,len=0,endss="...") + ss = "" + if text.length>0 + ss=text.gsub(/<\/?.*?>/, '').strip + + if len > 0 && ss.length > len + ss = ss[0, len] + endss + elsif len > 0 && ss.length <= len + ss = ss + #ss = truncate(ss, :length => len) + end + end + return ss +end + diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index 62451591f..a328791bf 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -81,10 +81,12 @@ class BlogComment < ActiveRecord::Base ws = WechatService.new if self.parent_id.nil? self.author.watcher_users.each do |watcher| - ws.message_update_template watcher.id, "#{l(:label_new_blog_template)}", self.author.try(:realname) + " 发表了博客:" + self.title.html_safe, format_time(self.created_at) + content = strip_html self.author.try(:realname) + " 发表了博客:" + self.title.html_safe, 200 + ws.message_update_template watcher.id, "#{l(:label_new_blog_template)}", content, format_time(self.created_at) end else - ws.comment_template self.parent.author_id, "#{l(:label_blog_comment_template)}", self.author.try(:realname), format_time(self.created_at), self.content.html_safe + content = strip_html self.content.html_safe, 200 + ws.comment_template self.parent.author_id, "#{l(:label_blog_comment_template)}", self.author.try(:realname), format_time(self.created_at), content end end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 9a752129b..f613a6d46 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -45,12 +45,14 @@ class Comment < ActiveRecord::Base if self.commented.course if self.author_id != self.commented.author_id self.course_messages << CourseMessage.new(:user_id => self.commented.author_id, :course_id => self.commented.course.id, :viewed => false) - ws.comment_template self.commented.author_id, "#{l(:label_notice_comment_template)}", self.author.try(:realname), format_time(self.created_on), self.comments.html_safe + content = strip_html self.comments.html_safe, 200 + ws.comment_template self.commented.author_id, "#{l(:label_notice_comment_template)}", self.author.try(:realname), format_time(self.created_on), content end else # 项目相关 if self.author_id != self.commented.author_id self.forge_messages << ForgeMessage.new(:user_id => self.commented.author_id, :project_id => self.commented.project.id, :viewed => false) - ws.comment_template self.commented.author_id, "#{l(:label_news_comment_template)}", self.author.try(:realname), format_time(self.created_on), self.comments.html_safe + content = strip_html self.comments.html_safe, 200 + ws.comment_template self.commented.author_id, "#{l(:label_news_comment_template)}", self.author.try(:realname), format_time(self.created_on), content end end end diff --git a/app/models/issue.rb b/app/models/issue.rb index 5124dd54b..7681ce45d 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -160,7 +160,8 @@ 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) ws = WechatService.new - ws.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) + content = strip_html self.author.try(:realname) + " 给您指派了缺陷:" + self.subject.html_safe, 200 + ws.message_update_template self.assigned_to_id, "#{l(:label_new_issue_template)}", content, format_time(self.created_on) end if self.tracker_id == 5 self.project.members.each do |m| diff --git a/app/models/journal.rb b/app/models/journal.rb index 80d585b06..60bb16b11 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -240,6 +240,7 @@ class Journal < ActiveRecord::Base #缺陷回复微信模板消息 def issue_wechat_message ws = WechatService.new - ws.comment_template self.issue.author_id, "#{l(:label_issue_comment_template)}", self.user.try(:realname), format_time(self.created_on), self.notes.html_safe + content = strip_html self.notes.html_safe, 200 + ws.comment_template self.issue.author_id, "#{l(:label_issue_comment_template)}", self.user.try(:realname), format_time(self.created_on), content end end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 799af8f74..58aa8620b 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -257,7 +257,9 @@ class JournalsForMessage < ActiveRecord::Base end if self.jour_type == 'HomeworkCommon' ws = WechatService.new - ws.comment_template self.jour.user_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), self.notes.html_safe + #content = truncate(strip_tags(self.notes.to_s), length: 200) + content = strip_html self.notes.html_safe, 200 + ws.comment_template self.jour.user_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), content end end @@ -271,7 +273,8 @@ class JournalsForMessage < ActiveRecord::Base if self.reply_id == 0 if self.user_id != self.jour_id # 过滤自己给自己的留言消息 receivers << self.jour - ws.message_update_template self.jour_id, "#{l(:label_new_journals_template)}", self.notes.html_safe, format_time(self.created_on) + content = strip_html self.notes, 200 + ws.message_update_template self.jour_id, "#{l(:label_new_journals_template)}", content, format_time(self.created_on) end else # 留言回复 reply_to = User.find(self.reply_id) @@ -281,7 +284,8 @@ class JournalsForMessage < ActiveRecord::Base if self.user_id != self.parent.jour_id && self.reply_id != self.parent.jour_id # 给东家发信息,如果回复的对象是东家则不发 receivers << self.parent.jour end - ws.comment_template self.reply_id, "#{l(:label_journals_comment_template)}", self.user.try(:realname), format_time(self.created_on), self.notes.html_safe + content = strip_html self.notes, 200 + ws.comment_template self.reply_id, "#{l(:label_journals_comment_template)}", self.user.try(:realname), format_time(self.created_on), content end receivers.each do |r| self.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => self.id, :journals_for_message_type => "Principal", :viewed => false) diff --git a/app/models/message.rb b/app/models/message.rb index 2f4637042..d606962e1 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -266,14 +266,16 @@ class Message < ActiveRecord::Base self.course.members.each do |m| if self.author.allowed_to?(:as_teacher, self.course) && m.user_id != self.author_id # 老师 自己的帖子不给自己发送消息 self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) - ws.topic_publish_template m.user_id, "#{l(:label_course_topic_template)}", self.subject, self.author.try(:realname), format_time(self.created_on) + content = strip_html self.subject, 200 + ws.topic_publish_template m.user_id, "#{l(:label_course_topic_template)}", content, self.author.try(:realname), format_time(self.created_on) end end else # 回帖 self.course.members.each do |m| if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) - ws.comment_template m.user_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), self.content.html_safe + content = strip_html self.content.html_safe, 200 + ws.comment_template m.user_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content end end end @@ -282,14 +284,16 @@ class Message < ActiveRecord::Base self.project.members.each do |m| if m.user_id != self.author_id self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false) - ws.topic_publish_template m.user_id, "#{l(:label_project_topic_template)}", self.subject, self.author.try(:realname), format_time(self.created_on) + content = strip_html self.subject, 200 + ws.topic_publish_template m.user_id, "#{l(:label_project_topic_template)}", content, self.author.try(:realname), format_time(self.created_on) end end else # 回帖 self.project.members.each do |m| if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false) - ws.comment_template m.user_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), self.content.html_safe + content = strip_html self.content.html_safe, 200 + ws.comment_template m.user_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content end end end diff --git a/app/models/news.rb b/app/models/news.rb index 25a70095f..b7a8baaf5 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -171,7 +171,8 @@ class News < ActiveRecord::Base if m.user_id != self.author_id self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) ws = WechatService.new - ws.message_update_template m.user_id, "#{l(:label_new_notice_template)}", self.author.try(:realname) + " 发布了通知:" + self.title.html_safe, format_time(self.created_on) + content = strip_html self.author.try(:realname) + " 发布了通知:" + self.title.html_safe, 200 + ws.message_update_template m.user_id, "#{l(:label_new_notice_template)}", self.author.try(:realname) + " 发布了通知:" + content, format_time(self.created_on) end end else From aed38182738ac586a31eb34611dc6dbc2eb54d9a Mon Sep 17 00:00:00 2001 From: cxt Date: Wed, 20 Apr 2016 14:44:10 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=82=B9=E5=87=BB=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E8=B7=B3=E5=88=B0=E5=BE=AE=E4=BF=A1=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1234567 | 2 +- app/models/blog_comment.rb | 4 ++-- app/models/comment.rb | 6 +++--- app/models/homework_common.rb | 4 ++-- app/models/issue.rb | 2 +- app/models/journal.rb | 2 +- app/models/journals_for_message.rb | 6 +++--- app/models/message.rb | 8 ++++---- app/models/news.rb | 2 +- app/services/wechat_service.rb | 25 ++++++++++++++----------- config/locales/zh.yml | 8 +------- 11 files changed, 33 insertions(+), 36 deletions(-) diff --git a/1234567 b/1234567 index b584c6f69..327c92785 100644 --- a/1234567 +++ b/1234567 @@ -1 +1 @@ -{"access_token":"GbIQJdIaX2c0IyQSOJcNNT2TxUH5aSQCNL7N92BV9oggGePRoj886HDohtqRokwPS6OVcIYF8WZTnSn717CP-czrWupY_gIHehK4UqjqXYqGkVqODXaXEB_LV0grMIwEXQDhAAAFYL","expires_in":7200,"got_token_at":1461117548} \ No newline at end of file +{"access_token":"x7GUTe-MLoVPMzId82-3VSdCsO6sq5cOJZCmIN-yUjDcohfI00t2lzPkNKdRhETLUBptZRQ--v-IBQTG-o5iRZZv-EelOBX7K96DcPMFt9rdzwNu7XerNnZw_ncGYncSLHXeACAQMC","expires_in":7200,"got_token_at":1461133885} \ No newline at end of file diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index a328791bf..af21b4f69 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -82,11 +82,11 @@ class BlogComment < ActiveRecord::Base if self.parent_id.nil? self.author.watcher_users.each do |watcher| content = strip_html self.author.try(:realname) + " 发表了博客:" + self.title.html_safe, 200 - ws.message_update_template watcher.id, "#{l(:label_new_blog_template)}", content, format_time(self.created_at) + ws.message_update_template watcher.id, "blog_comment", self.id, "#{l(:label_new_blog_template)}", content, format_time(self.created_at) end else content = strip_html self.content.html_safe, 200 - ws.comment_template self.parent.author_id, "#{l(:label_blog_comment_template)}", self.author.try(:realname), format_time(self.created_at), content + ws.comment_template self.parent.author_id, "blog_comment", self.parent_id, "#{l(:label_blog_comment_template)}", self.author.try(:realname), format_time(self.created_at), content end end end diff --git a/app/models/comment.rb b/app/models/comment.rb index f613a6d46..6b1732eab 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -46,13 +46,13 @@ class Comment < ActiveRecord::Base if self.author_id != self.commented.author_id self.course_messages << CourseMessage.new(:user_id => self.commented.author_id, :course_id => self.commented.course.id, :viewed => false) content = strip_html self.comments.html_safe, 200 - ws.comment_template self.commented.author_id, "#{l(:label_notice_comment_template)}", self.author.try(:realname), format_time(self.created_on), content + ws.comment_template self.commented.author_id, "course_notice", self.id, "#{l(:label_notice_comment_template)}", self.author.try(:realname), format_time(self.created_on), content end else # 项目相关 if self.author_id != self.commented.author_id self.forge_messages << ForgeMessage.new(:user_id => self.commented.author_id, :project_id => self.commented.project.id, :viewed => false) - content = strip_html self.comments.html_safe, 200 - ws.comment_template self.commented.author_id, "#{l(:label_news_comment_template)}", self.author.try(:realname), format_time(self.created_on), content + #content = strip_html self.comments.html_safe, 200 + #ws.comment_template self.commented.author_id, "blog_comment", self.id, "#{l(:label_news_comment_template)}", self.author.try(:realname), format_time(self.created_on), content end end end diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 54f13e57e..a2216bdf9 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -60,7 +60,7 @@ class HomeworkCommon < ActiveRecord::Base # if m.user_id != self.user_id self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) ws = WechatService.new - ws.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") + ws.homework_template(m.user_id, "homework", self.id, "#{l(:label_new_homework_template)}", self.course.name, self.name.html_safe, self.end_time.to_s + " 23:59:59") # end end end @@ -107,7 +107,7 @@ class HomeworkCommon < ActiveRecord::Base def wechat_message self.course.members.each do |member| ws = WechatService.new - ws.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") + ws.homework_template(member.user_id, "homework", self.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 7681ce45d..fd378bc05 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -161,7 +161,7 @@ class Issue < ActiveRecord::Base self.forge_messages << ForgeMessage.new(:user_id => self.assigned_to_id, :project_id => self.project_id, :viewed => false) ws = WechatService.new content = strip_html self.author.try(:realname) + " 给您指派了缺陷:" + self.subject.html_safe, 200 - ws.message_update_template self.assigned_to_id, "#{l(:label_new_issue_template)}", content, format_time(self.created_on) + ws.message_update_template self.assigned_to_id, "issues", self.id, "#{l(:label_new_issue_template)}", content, format_time(self.created_on) end if self.tracker_id == 5 self.project.members.each do |m| diff --git a/app/models/journal.rb b/app/models/journal.rb index 60bb16b11..02086fa62 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -241,6 +241,6 @@ class Journal < ActiveRecord::Base def issue_wechat_message ws = WechatService.new content = strip_html self.notes.html_safe, 200 - ws.comment_template self.issue.author_id, "#{l(:label_issue_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + ws.comment_template self.issue.author_id, "issues", self.journalized_id, "#{l(:label_issue_comment_template)}", self.user.try(:realname), format_time(self.created_on), content end end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 58aa8620b..1f8b0253f 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -259,7 +259,7 @@ class JournalsForMessage < ActiveRecord::Base ws = WechatService.new #content = truncate(strip_tags(self.notes.to_s), length: 200) content = strip_html self.notes.html_safe, 200 - ws.comment_template self.jour.user_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + ws.comment_template self.jour.user_id, "homework", self.jour_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), content end end @@ -274,7 +274,7 @@ class JournalsForMessage < ActiveRecord::Base if self.user_id != self.jour_id # 过滤自己给自己的留言消息 receivers << self.jour content = strip_html self.notes, 200 - ws.message_update_template self.jour_id, "#{l(:label_new_journals_template)}", content, format_time(self.created_on) + ws.message_update_template self.jour_id, "journal_for_message", self.id, "#{l(:label_new_journals_template)}", content, format_time(self.created_on) end else # 留言回复 reply_to = User.find(self.reply_id) @@ -285,7 +285,7 @@ class JournalsForMessage < ActiveRecord::Base receivers << self.parent.jour end content = strip_html self.notes, 200 - ws.comment_template self.reply_id, "#{l(:label_journals_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + ws.comment_template self.reply_id, "journal_for_message", self.parent.id, "#{l(:label_journals_comment_template)}", self.user.try(:realname), format_time(self.created_on), content end receivers.each do |r| self.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => self.id, :journals_for_message_type => "Principal", :viewed => false) diff --git a/app/models/message.rb b/app/models/message.rb index d606962e1..5dc5dcc2e 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -267,7 +267,7 @@ class Message < ActiveRecord::Base if self.author.allowed_to?(:as_teacher, self.course) && m.user_id != self.author_id # 老师 自己的帖子不给自己发送消息 self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) content = strip_html self.subject, 200 - ws.topic_publish_template m.user_id, "#{l(:label_course_topic_template)}", content, self.author.try(:realname), format_time(self.created_on) + ws.topic_publish_template m.user_id, "course_discussion", self.id, "#{l(:label_course_topic_template)}", content, self.author.try(:realname), format_time(self.created_on) end end else # 回帖 @@ -275,7 +275,7 @@ class Message < ActiveRecord::Base if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) content = strip_html self.content.html_safe, 200 - ws.comment_template m.user_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content + ws.comment_template m.user_id, "course_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content end end end @@ -285,7 +285,7 @@ class Message < ActiveRecord::Base if m.user_id != self.author_id self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false) content = strip_html self.subject, 200 - ws.topic_publish_template m.user_id, "#{l(:label_project_topic_template)}", content, self.author.try(:realname), format_time(self.created_on) + ws.topic_publish_template m.user_id, "project_discussion", self.id, "#{l(:label_project_topic_template)}", content, self.author.try(:realname), format_time(self.created_on) end end else # 回帖 @@ -293,7 +293,7 @@ class Message < ActiveRecord::Base if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false) content = strip_html self.content.html_safe, 200 - ws.comment_template m.user_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content + ws.comment_template m.user_id, "project_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content end end end diff --git a/app/models/news.rb b/app/models/news.rb index b7a8baaf5..45e5bc424 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -172,7 +172,7 @@ class News < ActiveRecord::Base self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) ws = WechatService.new content = strip_html self.author.try(:realname) + " 发布了通知:" + self.title.html_safe, 200 - ws.message_update_template m.user_id, "#{l(:label_new_notice_template)}", self.author.try(:realname) + " 发布了通知:" + content, format_time(self.created_on) + ws.message_update_template m.user_id, "course_notice", self.id, "#{l(:label_new_notice_template)}", self.author.try(:realname) + " 发布了通知:" + content, format_time(self.created_on) end end else diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index ae097ad4a..2fb222d4f 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -1,11 +1,11 @@ #encoding: utf-8 class WechatService - def template_data(openid, template_id, first, key1, key2, key3, remark="具体内容请点击详情查看网站") + def template_data(openid, template_id, type, id, first, key1, key2, key3, remark="具体内容请点击详情查看网站") data = { touser:openid, template_id:template_id, - url:"https://www.trustie.net/", + url:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect", topcolor:"#FF0000", data:{ first: { @@ -33,10 +33,10 @@ class WechatService data end - def homework_template(user_id, first, key1, key2, key3, remark="具体内容请点击详情查看网站") + def homework_template(user_id, type, id, first, key1, key2, key3, remark="具体内容请点击详情查看网站") uw = UserWechat.where(user_id: user_id).first unless uw.nil? - data = template_data uw.openid,"3e5Dj2GIx8MOcMyRKpTUEQnM7Tg0ASSCNc01NS9HCGI",first, key1, key2, key3, remark + data = template_data uw.openid,"3e5Dj2GIx8MOcMyRKpTUEQnM7Tg0ASSCNc01NS9HCGI", type, id, first, key1, key2, key3, remark begin req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) rescue Exception => e @@ -44,12 +44,13 @@ class WechatService end Rails.logger.info "send over. #{req}" end + Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect" end - def topic_publish_template(user_id, first, key1, key2, key3, remark="具体内容请点击详情查看网站") + def topic_publish_template(user_id, type, id, first, key1, key2, key3, remark="具体内容请点击详情查看网站") uw = UserWechat.where(user_id: user_id).first unless uw.nil? - data = template_data uw.openid,"oKzFCdk7bsIHnGbscA__N8LPQrBkUShvpjV3-kuwWDQ",first, key1, key2, key3, remark + data = template_data uw.openid,"oKzFCdk7bsIHnGbscA__N8LPQrBkUShvpjV3-kuwWDQ", type, id,first, key1, key2, key3, remark Rails.logger.info "start send template message: #{data}" begin req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) @@ -58,12 +59,13 @@ class WechatService end Rails.logger.info "send over. #{req}" end + Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect" end - def comment_template(user_id, first, key1, key2, key3, remark="具体内容请点击详情查看网站") + def comment_template(user_id,type, id, first, key1, key2, key3, remark="具体内容请点击详情查看网站") uw = UserWechat.where(user_id: user_id).first unless uw.nil? - data = template_data uw.openid,"A_3f5v90-zK73V9Kijm-paDkl9S-NuM8Cf-1UJi92_c",first, key1, key2, key3, remark + data = template_data uw.openid,"A_3f5v90-zK73V9Kijm-paDkl9S-NuM8Cf-1UJi92_c",type, id,first, key1, key2, key3, remark Rails.logger.info "start send template message: #{data}" begin req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) @@ -72,15 +74,16 @@ class WechatService end Rails.logger.info "send over. #{req}" end + Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect" end - def message_update_template(user_id, first, key1, key2, remark="具体内容请点击详情查看网站") + def message_update_template(user_id, type, id, first, key1, key2, remark="具体内容请点击详情查看网站") uw = UserWechat.where(user_id: user_id).first unless uw.nil? data = { touser:uw.openid, template_id:"YTyNPZnQD8uZFBFq-Q6cCOWaq5LA9vL6RFlF2JuD5Cg", - url:"https://www.trustie.net/", + url:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect", topcolor:"#FF0000", data:{ first: { @@ -101,7 +104,6 @@ class WechatService } } } - Rails.logger.info "start send template message: #{data}" begin req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) @@ -110,5 +112,6 @@ class WechatService end Rails.logger.info "send over. #{req}" end + Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect" end end \ No newline at end of file diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 65d405733..7160e9d27 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2138,15 +2138,9 @@ zh: label_new_journals_template: 您有新留言了 label_journals_comment_template: 您的留言有新回复了 label_blog_comment_template: 您的博客有新回复了 - label_new_blog_template: 您的课程有新作业了 + label_new_blog_template: 有新博客了 label_new_issue_template: 您有新缺陷了 label_new_notice_template: 您的课程有新通知了 - label_resource_name: 您的课程有新作业了 - label_resource_name: 您的课程有新作业了 - label_resource_name: 您的课程有新作业了 - label_resource_name: 您的课程有新作业了 - label_resource_name: 您的课程有新作业了 - label_resource_name: 您的课程有新作业了 #edit yk label_code_work_tests: 代码测试列表