diff --git a/1234567 b/1234567 index 459204fe5..327c92785 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":"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/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9572034aa..606c9b5fd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3061,3 +3061,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..af21b4f69 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, "blog_comment", self.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, "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 9a752129b..6b1732eab 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, "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) - 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, "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 5124dd54b..fd378bc05 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, "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 80d585b06..02086fa62 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, "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 799af8f74..1f8b0253f 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, "homework", self.jour_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, "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) @@ -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, "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 1c7bf7677..e6df9493b 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -264,14 +264,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, "course_discussion", self.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, "course_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content end end end @@ -280,14 +282,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, "project_discussion", self.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, "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 25a70095f..45e5bc424 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, "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/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 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 @@