Merge branch 'weixin_guange' into develop

This commit is contained in:
cxt 2016-04-20 15:15:54 +08:00
commit 06f15735fe
14 changed files with 64 additions and 37 deletions

View File

@ -1 +1 @@
{"access_token":"q51KZUeA6_-CCCH-Buy1mxFmRjcrCViHgk2mHHHqEDbjuA_pgCM1IyW1DASYvpzyB06xHiarujo3rz1Ucq3GRoXdgQ7hAoFCzkL_q3Z5vczLjwAjowAVwmulYE-cAij8ATUfADAWPQ","expires_in":7200,"got_token_at":1460601163} {"access_token":"x7GUTe-MLoVPMzId82-3VSdCsO6sq5cOJZCmIN-yUjDcohfI00t2lzPkNKdRhETLUBptZRQ--v-IBQTG-o5iRZZv-EelOBX7K96DcPMFt9rdzwNu7XerNnZw_ncGYncSLHXeACAQMC","expires_in":7200,"got_token_at":1461133885}

View File

@ -3061,3 +3061,18 @@ def host_with_protocol
return Setting.protocol + "://" + Setting.host_name return Setting.protocol + "://" + Setting.host_name
end 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

View File

@ -81,10 +81,12 @@ class BlogComment < ActiveRecord::Base
ws = WechatService.new ws = WechatService.new
if self.parent_id.nil? if self.parent_id.nil?
self.author.watcher_users.each do |watcher| 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 end
else 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 end
end end

View File

@ -45,12 +45,14 @@ class Comment < ActiveRecord::Base
if self.commented.course if self.commented.course
if self.author_id != self.commented.author_id 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) 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 end
else # 项目相关 else # 项目相关
if self.author_id != self.commented.author_id 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) 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 end
end end

View File

@ -60,7 +60,7 @@ class HomeworkCommon < ActiveRecord::Base
# if m.user_id != self.user_id # if m.user_id != self.user_id
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false)
ws = WechatService.new 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 end
end end
@ -107,7 +107,7 @@ class HomeworkCommon < ActiveRecord::Base
def wechat_message def wechat_message
self.course.members.each do |member| self.course.members.each do |member|
ws = WechatService.new 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
end end

View File

@ -160,7 +160,8 @@ class Issue < ActiveRecord::Base
unless self.author_id == self.assigned_to_id 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) self.forge_messages << ForgeMessage.new(:user_id => self.assigned_to_id, :project_id => self.project_id, :viewed => false)
ws = WechatService.new 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 end
if self.tracker_id == 5 if self.tracker_id == 5
self.project.members.each do |m| self.project.members.each do |m|

View File

@ -240,6 +240,7 @@ class Journal < ActiveRecord::Base
#缺陷回复微信模板消息 #缺陷回复微信模板消息
def issue_wechat_message def issue_wechat_message
ws = WechatService.new 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
end end

View File

@ -257,7 +257,9 @@ class JournalsForMessage < ActiveRecord::Base
end end
if self.jour_type == 'HomeworkCommon' if self.jour_type == 'HomeworkCommon'
ws = WechatService.new 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
end end
@ -271,7 +273,8 @@ class JournalsForMessage < ActiveRecord::Base
if self.reply_id == 0 if self.reply_id == 0
if self.user_id != self.jour_id # 过滤自己给自己的留言消息 if self.user_id != self.jour_id # 过滤自己给自己的留言消息
receivers << self.jour 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 end
else # 留言回复 else # 留言回复
reply_to = User.find(self.reply_id) 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 # 给东家发信息,如果回复的对象是东家则不发 if self.user_id != self.parent.jour_id && self.reply_id != self.parent.jour_id # 给东家发信息,如果回复的对象是东家则不发
receivers << self.parent.jour receivers << self.parent.jour
end 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 end
receivers.each do |r| 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) self.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => self.id, :journals_for_message_type => "Principal", :viewed => false)

View File

@ -264,14 +264,16 @@ class Message < ActiveRecord::Base
self.course.members.each do |m| self.course.members.each do |m|
if self.author.allowed_to?(:as_teacher, self.course) && m.user_id != self.author_id # 老师 自己的帖子不给自己发送消息 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) 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
end end
else # 回帖 else # 回帖
self.course.members.each do |m| self.course.members.each do |m|
if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 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) 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 end
end end
@ -280,14 +282,16 @@ class Message < ActiveRecord::Base
self.project.members.each do |m| self.project.members.each do |m|
if m.user_id != self.author_id 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) 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
end end
else # 回帖 else # 回帖
self.project.members.each do |m| self.project.members.each do |m|
if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 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) 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 end
end end

View File

@ -171,7 +171,8 @@ class News < ActiveRecord::Base
if m.user_id != self.author_id if m.user_id != self.author_id
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false)
ws = WechatService.new 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
end end
else else

View File

@ -1,11 +1,11 @@
#encoding: utf-8 #encoding: utf-8
class WechatService 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 = { data = {
touser:openid, touser:openid,
template_id:template_id, 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", topcolor:"#FF0000",
data:{ data:{
first: { first: {
@ -33,10 +33,10 @@ class WechatService
data data
end 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 uw = UserWechat.where(user_id: user_id).first
unless uw.nil? 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 begin
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
rescue Exception => e rescue Exception => e
@ -44,12 +44,13 @@ class WechatService
end end
Rails.logger.info "send over. #{req}" Rails.logger.info "send over. #{req}"
end 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
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 uw = UserWechat.where(user_id: user_id).first
unless uw.nil? 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}" Rails.logger.info "start send template message: #{data}"
begin begin
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
@ -58,12 +59,13 @@ class WechatService
end end
Rails.logger.info "send over. #{req}" Rails.logger.info "send over. #{req}"
end 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
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 uw = UserWechat.where(user_id: user_id).first
unless uw.nil? 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}" Rails.logger.info "start send template message: #{data}"
begin begin
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
@ -72,15 +74,16 @@ class WechatService
end end
Rails.logger.info "send over. #{req}" Rails.logger.info "send over. #{req}"
end 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
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 uw = UserWechat.where(user_id: user_id).first
unless uw.nil? unless uw.nil?
data = { data = {
touser:uw.openid, touser:uw.openid,
template_id:"YTyNPZnQD8uZFBFq-Q6cCOWaq5LA9vL6RFlF2JuD5Cg", 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", topcolor:"#FF0000",
data:{ data:{
first: { first: {
@ -101,7 +104,6 @@ class WechatService
} }
} }
} }
Rails.logger.info "start send template message: #{data}" Rails.logger.info "start send template message: #{data}"
begin begin
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
@ -110,5 +112,6 @@ class WechatService
end end
Rails.logger.info "send over. #{req}" Rails.logger.info "send over. #{req}"
end 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
end end

View File

@ -251,7 +251,7 @@
%> %>
<% if @user.projects.visible.count > 0 <% 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 else
projects = [] projects = []
end end

View File

@ -17,7 +17,7 @@
</div> </div>
<div class="weui_cell"> <div class="weui_cell">
<div class="weui_cell_hd"><label class="weui_label">用户名</label></div> <div class="weui_cell_hd"><label class="weui_label">密码</label></div>
<div class="weui_cell_bd weui_cell_primary"> <div class="weui_cell_bd weui_cell_primary">
<input class="weui_input" type="password" name="password" placeholder="请输密码"/> <input class="weui_input" type="password" name="password" placeholder="请输密码"/>
</div> </div>

View File

@ -2138,15 +2138,9 @@ zh:
label_new_journals_template: 您有新留言了 label_new_journals_template: 您有新留言了
label_journals_comment_template: 您的留言有新回复了 label_journals_comment_template: 您的留言有新回复了
label_blog_comment_template: 您的博客有新回复了 label_blog_comment_template: 您的博客有新回复了
label_new_blog_template: 您的课程有新作业 label_new_blog_template: 有新博客
label_new_issue_template: 您有新缺陷了 label_new_issue_template: 您有新缺陷了
label_new_notice_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 #edit yk
label_code_work_tests: 代码测试列表 label_code_work_tests: 代码测试列表