diff --git a/.gitignore b/.gitignore index 38f29a661..0727a920a 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,4 @@ vendor/cache /public/files /tags /config/initializers/gitlab_config.rb -/config/wechat.yml -/config/menu.yml 1234567 diff --git a/app/api/mobile/entities/activity.rb b/app/api/mobile/entities/activity.rb index a90ff323d..9e2a39a5a 100644 --- a/app/api/mobile/entities/activity.rb +++ b/app/api/mobile/entities/activity.rb @@ -98,6 +98,7 @@ module Mobile end expose :act_type #缺陷/作业/讨论区/留言等类型 expose :act_id + expose :id expose :container_type #课程/项目/博客/个人 expose :author, using: Mobile::Entities::User do |a, opt| #用户信息 if a.is_a? ::UserActivity diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 17f62f18c..e421b8c69 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -304,7 +304,7 @@ class CoursesController < ApplicationController @render_file = 'new_member_list' @score_sort_by = "desc" - @sort_type = "score" + @sort_type = params[:sort_type] ? params[:sort_type] : "score" @canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1' @role = params[:role].nil? ? '2':params[:role] @is_remote = true @@ -319,7 +319,7 @@ class CoursesController < ApplicationController if @course.open_student == 1 || User.current.member_of_course?(@course) @subPage_title = l :label_student_list page = params[:page].nil? ? 0 : (params['page'].to_i - 1) - @all_members = student_homework_score(0,page, 10,@score_sort_by) + @all_members = student_homework_score(0,page, 10,@score_sort_by,@sort_type) @members = @all_members else render_403 diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index b1d16debb..8ef399d10 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -304,7 +304,7 @@ class MessagesController < ApplicationController @content = "> #{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> " @temp = Message.new - @temp.content = "
#{ll(Setting.default_language, :text_user_wrote, @message.author)}
#{@message.content.html_safe}
".html_safe + @temp.content = "
#{ll(Setting.default_language, :text_user_wrote, @message.author.show_name)}
#{@message.content.html_safe}
".html_safe end def preview diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 4bf95fdbd..ef59e0ed4 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -154,12 +154,7 @@ class WechatsController < ActionController::Base end end - - - ### controller method - - module Controllers def get_open_id begin @@ -193,6 +188,8 @@ class WechatsController < ActionController::Base openid: openid, user: user ) + ws = WechatService.new + ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, format_time(Time.now)) render :json => {status:0, msg: "绑定成功"} rescue Exception=>e render :json => {status: -1, msg: e.message} @@ -207,6 +204,19 @@ class WechatsController < ActionController::Base render 'wechats/login', layout: 'base_wechat' end + def user_activities + session[:wechat_code] = params[:code] if params[:code] + code = params[:code] || session[:wechat_code] + openid = get_openid_from_code(code) + @wechat_user = user_binded?(openid) + unless @wechat_user + redirect_to login_wechat_path + return + end + + render 'wechats/user_activities', layout: nil + end + private def get_openid_from_code(code) openid = session[:wechat_openid] @@ -228,37 +238,8 @@ class WechatsController < ActionController::Base uw = UserWechat.where(openid: openid).first end - def user_activity(user) - @user = user - shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id) - shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id) - @page = params[:page] ? params[:page].to_i + 1 : 0 - user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" - user_course_ids = (@user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")" - course_types = "('Message','News','HomeworkCommon','Poll','Course')" - project_types = "('Message','Issue','Project')" - principal_types = "JournalsForMessage" - - blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" - @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ - "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + - "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) - end - - def process_activity(user_activity) - act= user_activity.act - case user_activity.container_type.to_s - when 'Course' - when 'Project' - case user_activity.act_type.to_s - when 'Issue' - [act.project.name.to_s+" | 项目问题", act.subject.to_s, url_to_avatar(act.author),"http://wechat.trustie.net/app.html#/issue/#{act.id}"] - end - end - end end diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index af21b4f69..255410a89 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -77,16 +77,16 @@ class BlogComment < ActiveRecord::Base end #博客回复微信模板消息 - def blog_wechat_message - ws = WechatService.new - 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, "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, "blog_comment", self.parent_id, "#{l(:label_blog_comment_template)}", self.author.try(:realname), format_time(self.created_at), content - end - end + # def blog_wechat_message + # ws = WechatService.new + # 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, "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, "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 8632c243a..edb5e472f 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -41,15 +41,15 @@ class Comment < ActiveRecord::Base after_destroy :down_course_score def act_as_system_message - ws = WechatService.new + #ws = WechatService.new 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) - count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.commented.author_id} and shield_type='Course' and shield_id=#{self.commented.course.id}").count - if count == 0 - 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 + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.commented.author_id} and shield_type='Course' and shield_id=#{self.commented.course.id}").count + # if count == 0 + # 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 # 项目相关 if self.author_id != self.commented.author_id diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index e4426e78f..325b599e3 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -63,7 +63,7 @@ class HomeworkCommon < ActiveRecord::Base count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count if count == 0 ws = WechatService.new - 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") + ws.homework_message_notice(m.user_id, "homework", self.id, "#{m.user.show_name},#{l(:label_new_homework_template)}:", self.course.name, "新作业:"+ self.name.html_safe, "作业内容请点击“详情”查看。") end # end end @@ -108,15 +108,15 @@ class HomeworkCommon < ActiveRecord::Base end #修改作业后发送微信模板消息 - def wechat_message - self.course.members.each do |member| - count = ShieldWechatMessage.where("container_type='User' and container_id=#{member.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count - if count == 0 - ws = WechatService.new - 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 + # def wechat_message + # self.course.members.each do |member| + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{member.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count + # if count == 0 + # ws = WechatService.new + # 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 delegate :language_name, :language, :to => :homework_detail_programing diff --git a/app/models/issue.rb b/app/models/issue.rb index b5e87feea..4cfea1f43 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -160,27 +160,27 @@ 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) end - self.project.members.each do |m| - count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project_id}").count - if m.user_id != self.author_id && count == 0 - ws = WechatService.new - str = " 有新缺陷了: " - case self.tracker_id - when 1 - str = " 有新缺陷了: " - when 2 - str = " 有新功能了: " - when 3 - str = " 有新支持了: " - when 4 - str = " 有新任务了: " - when 5 - str = " 有新周报了: " - end - content = strip_html self.project.name + str + self.subject.html_safe, 200 - ws.message_update_template m.user_id, "issues", self.id, "#{l(:label_new_issue_template)}", content, format_time(self.created_on) - end - end + # self.project.members.each do |m| + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project_id}").count + # if m.user_id != self.author_id && count == 0 + # ws = WechatService.new + # str = " 有新缺陷了: " + # case self.tracker_id + # when 1 + # str = " 有新缺陷了: " + # when 2 + # str = " 有新功能了: " + # when 3 + # str = " 有新支持了: " + # when 4 + # str = " 有新任务了: " + # when 5 + # str = " 有新周报了: " + # end + # content = strip_html self.project.name + str + self.subject.html_safe, 200 + # ws.message_update_template m.user_id, "issues", self.id, "#{l(:label_new_issue_template)}", content, format_time(self.created_on) + # end + # end if self.tracker_id == 5 self.project.members.each do |m| if m.roles.first.to_s.include?("Manager") && m.user_id != self.author_id && m.user_id != self.assigned_to_id diff --git a/app/models/journal.rb b/app/models/journal.rb index eeaa17dd6..6d59c7414 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -238,11 +238,11 @@ class Journal < ActiveRecord::Base end #缺陷回复微信模板消息 - def issue_wechat_message - if !self.notes.nil? && self.notes.gsub(' ','') != '' - ws = WechatService.new - 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 + # def issue_wechat_message + # if !self.notes.nil? && self.notes.gsub(' ','') != '' + # ws = WechatService.new + # 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 diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index d0113744c..d8819515c 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -259,24 +259,24 @@ class JournalsForMessage < ActiveRecord::Base if self.m_parent_id.nil? if self.user_id != self.jour.user_id self.course_messages << CourseMessage.new(:user_id => self.jour.user_id,:course_id => self.jour.course.id, :viewed => false) - count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.jour.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count - if count == 0 - 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, "homework", self.jour_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), content - end + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.jour.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count + # if count == 0 + # 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, "homework", self.jour_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + # end end else if self.user_id != self.parent.user_id self.course_messages << CourseMessage.new(:user_id => self.parent.user_id,:course_id => self.jour.course.id, :viewed => false) - count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.parent.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count - if count == 0 - 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.parent.user_id, "homework", self.jour_id, "#{l(:label_new_second_comment_template)}", self.user.try(:realname), format_time(self.created_on), content - end + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.parent.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count + # if count == 0 + # 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.parent.user_id, "homework", self.jour_id, "#{l(:label_new_second_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + # end end end end @@ -293,7 +293,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, "journal_for_message", self.id, "#{l(:label_new_journals_template)}", content, format_time(self.created_on) + ws.journal_notice self.jour_id, "journal_for_message", self.id, "#{l(:label_new_journals_template)}", self.user.show_name, format_time(self.created_on),content end else # 留言回复 reply_to = User.find(self.reply_id) @@ -303,8 +303,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 - 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 + #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 cf9adab4e..393fd3a60 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -258,28 +258,28 @@ class Message < ActiveRecord::Base # 主贴项目成员都能收到 # 回帖:帖子的发布人收到 def act_as_system_message - ws = WechatService.new + #ws = WechatService.new if self.course if self.parent_id.nil? # 主贴 self.course.members.includes(:user).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) - count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course.id}").count - if count == 0 - 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 + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course.id}").count + # if count == 0 + # 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 else # 回帖 parent_author_id = Message.find(self.parent_id).author_id if parent_author_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 self.course_messages << CourseMessage.new(:user_id => parent_author_id, :course_id => self.board.course_id, :viewed => false) - count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Course' and shield_id=#{self.board.course_id}").count - if count == 0 - content = strip_html self.content.html_safe, 200 - ws.comment_template parent_author_id, "course_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content - end + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Course' and shield_id=#{self.board.course_id}").count + # if count == 0 + # content = strip_html self.content.html_safe, 200 + # ws.comment_template parent_author_id, "course_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content + # end end end elsif self.project # 项目相关 @@ -287,22 +287,22 @@ class Message < ActiveRecord::Base self.project.members.includes(:user).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) - count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project.id}").count - if count == 0 - 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 + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project.id}").count + # if count == 0 + # 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 else # 回帖 parent_author_id = Message.find(self.parent_id).author_id if parent_author_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 self.forge_messages << ForgeMessage.new(:user_id => parent_author_id, :project_id => self.board.project_id, :viewed => false) - count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Project' and shield_id=#{self.board.project_id}").count - if count == 0 - content = strip_html self.content.html_safe, 200 - ws.comment_template parent_author_id, "project_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content - end + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Project' and shield_id=#{self.board.project_id}").count + # if count == 0 + # content = strip_html self.content.html_safe, 200 + # ws.comment_template parent_author_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 diff --git a/app/models/news.rb b/app/models/news.rb index 0b03dcc48..54f6fce08 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -174,7 +174,7 @@ class News < ActiveRecord::Base if count == 0 ws = WechatService.new 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)}", content, format_time(self.created_on) + ws.class_notice m.user_id, "course_notice", self.id, "#{l(:label_new_notice_template)}", self.course.name, self.author.show_name, format_time(self.created_on), content, "点击查看通知详情" end end end diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index 6d8c0f234..f9a59e080 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -110,4 +110,144 @@ class WechatService Rails.logger.info "send over. #{req}" end end + + def two_keys_template(openid, template_id, type, id, first, key1, key2, remark="") + data = { + touser:openid, + template_id:template_id, + url:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{Setting.protocol}://#{Setting.host_name}/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect", + topcolor:"#FF0000", + data:{ + first: { + value:first, + color:"#707070" + }, + keyword1:{ + value:key1, + color:"#707070" + }, + keyword2:{ + value:key2, + color:"#707070" + }, + remark:{ + value:remark, + color:"#707070" + } + } + } + data + end + + def four_keys_template(openid, template_id, type, id, first, key1, key2, key3, key4, remark="") + data = { + touser:openid, + template_id:template_id, + url:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{Setting.protocol}://#{Setting.host_name}/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect", + topcolor:"#FF0000", + data:{ + first: { + value:first, + color:"#707070" + }, + keyword1:{ + value:key1, + color:"#707070" + }, + keyword2:{ + value:key2, + color:"#707070" + }, + keyword3:{ + value:key3, + color:"#707070" + }, + keyword4:{ + value:key4, + color:"#707070" + }, + remark:{ + value:remark, + color:"#707070" + } + } + } + data + end + + def binding_succ_notice(user_id, first, key1, key2) + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = { + touser:uw.openid, + template_id:Wechat.config.binding_succ_notice, + url:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities&response_type=code&scope=snsapi_base&state=123#wechat_redirect", + topcolor:"#FF0000", + data:{ + first: { + value:first, + color:"#707070" + }, + keyword1:{ + value:key1, + color:"#707070" + }, + keyword2:{ + value:key2, + color:"#707070" + }, + remark:{ + value:"绑定成功后可使用微信查看Trustie平台最新动态", + color:"#707070" + } + } + } + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[homework] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end + end + + def journal_notice(user_id, type, id, first, key1, key2, remark="") + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = two_keys_template uw.openid,Wechat.config.journal_notice, type, id, first, key1, key2, remark + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[homework] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end + end + + def homework_message_notice(user_id, type, id, first, key1, key2, remark="") + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = two_keys_template uw.openid,Wechat.config.homework_message_notice, type, id, first, key1, key2, remark + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[homework] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end + end + + def class_notice(user_id, type, id, first, key1, key2, key3, key4, remark="") + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = four_keys_template uw.openid,Wechat.config.class_notice, type, id, first, key1, key2, key3, key4, remark + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[homework] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end + end + end \ No newline at end of file diff --git a/app/views/courses/_course_activity_users.html.erb b/app/views/courses/_course_activity_users.html.erb index a0cac45f7..93e0e7b77 100644 --- a/app/views/courses/_course_activity_users.html.erb +++ b/app/views/courses/_course_activity_users.html.erb @@ -1,6 +1,11 @@ <% unless contributor_course_scor(course.id).count == 0 %>