From 7700445c178938c23db5f0dbde9b9a8d4d6b780e Mon Sep 17 00:00:00 2001
From: guange <8863824@gmail.com>
Date: Wed, 22 Jun 2016 16:42:20 +0800
Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E8=AF=BE=E7=A8=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/api/mobile/apis/courses.rb | 4 +-
app/controllers/wechats_controller.rb | 17 +++++---
app/views/wechats/user_activities.html.erb | 39 ++++++++++---------
public/assets/wechat/myclass.html | 32 +++++++++++++++
.../javascripts/wechat/controllers/myclass.js | 8 ++++
public/stylesheets/weui/weixin.css | 2 +
6 files changed, 74 insertions(+), 28 deletions(-)
diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb
index b585e7dae..de2e48c8e 100644
--- a/app/api/mobile/apis/courses.rb
+++ b/app/api/mobile/apis/courses.rb
@@ -97,15 +97,13 @@ module Mobile
desc "加入课程"
params do
- optional :openid, type: String, desc: '微信ID'
+ requires :token, type: String
requires :invite_code, type: String, desc: '邀请码'
end
post "join" do
authenticate!
-
cs = CoursesService.new
status = cs.join_course({openid: params[:openid], invite_code: params[:invite_code]}, current_user)
-
{
status: status[:state],
messsge:CoursesService::JoinCourseError.message(status[:state])
diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb
index b1bab6c56..f6e73e088 100644
--- a/app/controllers/wechats_controller.rb
+++ b/app/controllers/wechats_controller.rb
@@ -8,12 +8,14 @@ class WechatsController < ActionController::Base
# default text responder when no other match
on :text do |request, content|
#邀请码
- if join_class(content)
-
+ uw = user_binded?(request[:FromUserName])
+ if !uw
+ sendBind()
+ elsif (course = join_class(content, uw.user)) && course
news = (1..1).each_with_object([]) { |n, memo| memo << { title: '恭喜您成功加入班级,开始学习吧!',
- content: "课程名称: 数据结构\n班级名称: 数据结构A班\n任课老师: 尹刚\n进入班级,和小伙伴愉快的学习吧!"} }
+ content: "课程名称: #{course.name}\n班级名称: #{course.name}\n任课老师: #{course.teacher.show_name}\n进入班级,和小伙伴愉快的学习吧!"} }
request.reply.news(news) do |article, n, index| # article is return object
- url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities'}&response_type=code&scope=snsapi_base&state=myclass#wechat_redirect"
+ url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities?id='+course.id}&response_type=code&scope=snsapi_base&state=myclass#wechat_redirect"
pic_url = "#{ROOT_URL}/images/wechat/class.jpg"
article.item title: "#{n[:title]}",
description: n[:content],
@@ -179,8 +181,11 @@ class WechatsController < ActionController::Base
end
end
- def join_class(content)
- true
+ def join_class(content, user)
+ cs = CoursesService.new
+ status = cs.join_course({invite_code: content.trim}, current_user)
+ logger.info status
+ status[:state] == 0 ? status[:course] : nil
end
### controller method
diff --git a/app/views/wechats/user_activities.html.erb b/app/views/wechats/user_activities.html.erb
index f920aed4b..b5bd82fc5 100644
--- a/app/views/wechats/user_activities.html.erb
+++ b/app/views/wechats/user_activities.html.erb
@@ -25,25 +25,26 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+