新增创建班级的模版消息

This commit is contained in:
yuanke 2016-07-12 17:00:01 +08:00
parent 2844ac2e65
commit 824f9d9174
4 changed files with 61 additions and 0 deletions

View File

@ -633,6 +633,9 @@ class CoursesController < ApplicationController
=end
end
if @course
#发送微信消息
ss = SyllabusesService.new
ss.send_wechat_create_class_notice User.current,@course
respond_to do |format|
flash[:notice] = l(:notice_successful_create)
format.html {redirect_to course_url(@course)}

View File

@ -72,6 +72,15 @@ class SyllabusesService
course.course_infos << course_info
end
def send_wechat_create_class_notice user,course
count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='Course' and shield_id=#{course.id}").count
if count == 0
ws = WechatService.new
title = "恭喜您创建班级成功"
ws.create_class_notice user.id, "create_course_notice", course.id,title, course.name, user.show_name, 0, "点击查看班级详情"
end
end
#创建大纲
# params {title: '大纲名称', [{course}, {course}]}
def create(user, title, courses = [])
@ -83,6 +92,7 @@ class SyllabusesService
if ::Course === course
course.syllabus_id = sy.id
course.save!
send_wechat_create_class_notice user,course
elsif Hash === course
c = ::Course.new(course)
c.tea_id = user.id
@ -91,6 +101,7 @@ class SyllabusesService
c.is_public = 0
c.save!
after_create_course(c, user)
send_wechat_create_class_notice user,c
end
end
@ -134,6 +145,7 @@ class SyllabusesService
course.is_public = 0
course.save!
after_create_course(course, user)
send_wechat_create_class_notice user,course
end
status = 0
end

View File

@ -139,6 +139,38 @@ class WechatService
data
end
def three_keys_template(openid, template_id, type, id, first, key1, key2, key3, remark="")
data = {
touser:openid,
template_id:template_id,
url:"#{Setting.protocol}://#{Setting.host_name}/assets/wechat/app.html#/#{type}/#{id}",
topcolor:"#FF0000",
data:{
first: {
value:first,
color:"#707070"
},
keyword1:{
value:key1,
color:"#707070"
},
keyword2:{
value:key2,
color:"#707070"
},
keyword3:{
value:key3,
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,
@ -250,4 +282,17 @@ class WechatService
end
end
def create_class_notice(user_id, type, id, first, key1, key2, key3, remark="")
uw = UserWechat.where(user_id: user_id).first
unless uw.nil?
data = three_keys_template uw.openid,Wechat.config.create_class_notice, type, id, first, key1, key2, key3, remark
begin
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
rescue Exception => e
Rails.logger.error "[wechat_create_class_notice] ===> #{e}"
end
Rails.logger.info "send over. #{req}"
end
end
end

View File

@ -26,6 +26,7 @@ default: &default
journal_notice: "uC1zAw4F2q6HTA3Pcj8VUO6wKKKiYFwnPJB4iXxpdoM"
homework_message_notice: "tCf7teCVqc2vl2LZ_hppIdWmpg8yLcrI8XifxYePjps"
class_notice: "MQ_mFupbXP-9jWbeHT3C5xqNBvPo8EIlNv4ULakSpJA"
create_class_notice: "2GtJJGzzNlNy2i0UrsjEDlvfSVIUXQfSo47stpcQAVw"
production:
<<: *default