diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 4a79d6d93..bd4ebaf7f 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -8,7 +8,11 @@ class WechatsController < ActionController::Base # default text responder when no other match on :text do |request, content| #邀请码 - sendBindClass(request, {invite_code: content}) + if join_request + sendBindClass(request, {invite_code: content}) + else + request.reply.text '您的意见已收到,感谢您的反馈!' + end end # When receive 'help', will trigger this responder @@ -142,6 +146,11 @@ class WechatsController < ActionController::Base end end + def join_request(request) + openid = request[:FromUserName] + wl = WechatLog.where(openid: openid).order('id desc').first + wl && JSON(wl.request_raw)["EventKey"] == 'JOIN_CLASS' + end def sendBindClass(request, params) begin diff --git a/app/models/wechat_log.rb b/app/models/wechat_log.rb new file mode 100644 index 000000000..118a9fade --- /dev/null +++ b/app/models/wechat_log.rb @@ -0,0 +1,4 @@ +#coding=utf-8 +# +class WechatLog < ActiveRecord::Base +end diff --git a/db/migrate/20160709015740_add_index_openid_to_wechat_logs.rb b/db/migrate/20160709015740_add_index_openid_to_wechat_logs.rb new file mode 100644 index 000000000..845a47b72 --- /dev/null +++ b/db/migrate/20160709015740_add_index_openid_to_wechat_logs.rb @@ -0,0 +1,5 @@ +class AddIndexOpenidToWechatLogs < ActiveRecord::Migration + def change + add_index(:wechat_logs, :openid) + end +end diff --git a/db/schema.rb b/db/schema.rb index 56bb5ad7f..32d29d31a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,8 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160708091258) do +ActiveRecord::Schema.define(:version => 20160709015740) do + create_table "activities", :force => true do |t| t.integer "act_id", :null => false t.string "act_type", :null => false @@ -2185,6 +2186,8 @@ ActiveRecord::Schema.define(:version => 20160708091258) do t.datetime "created_at", :null => false end + add_index "wechat_logs", ["openid"], :name => "index_wechat_logs_on_openid" + create_table "wiki_content_versions", :force => true do |t| t.integer "wiki_content_id", :null => false t.integer "page_id", :null => false