From 0ab579af98b32e6e3a9d176a7b05009c65a418e1 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Sun, 28 Feb 2016 22:22:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E9=98=85=E6=97=B6=E5=8F=91=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/wechats_controller.rb | 29 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index eeb3a8455..b6b6cc237 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -23,7 +23,7 @@ class WechatsController < ActionController::Base end on :event, with: 'subscribe' do |request| - request.reply.text "#{request[:FromUserName]} subscribe now" + sendBind end # When unsubscribe user scan qrcode qrscene_xxxxxx to subscribe in public account @@ -147,17 +147,22 @@ class WechatsController < ActionController::Base url: n[:url] end else - openid = request[:FromUserName] - attrs = wechat.user(openid) - UserWechat.delete_all(openid: openid) - uw = UserWechat.create!(attrs) - news = (1..1).each_with_object([]) { |n, memo| memo << { title: '绑定登录', content: "您还未绑定确实的用户,请先绑定." } } - request.reply.news(news) do |article, n, index| # article is return object - article.item title: "#{n[:title]}", - description: n[:content], - pic_url: 'http://wechat.trustie.net/images/trustie_logo2.png', - url: login_wechat_url(openid: uw.id) - end + sendBind + end + end + + def sendBind + openid = request[:FromUserName] + attrs = wechat.user(openid) + UserWechat.delete_all(openid: openid) + uw = UserWechat.create!(attrs) + news = (1..1).each_with_object([]) { |n, memo| memo << { title: '绑定登录', content: "您还未绑定确实的用户,请先绑定." } } + request.reply.news(news) do |article, n, index| # article is return object + url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{self.corpid}&redirect_uri=#{login_wechat_url(uid: uw.id)}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect" + article.item title: "#{n[:title]}", + description: n[:content], + pic_url: 'http://wechat.trustie.net/images/trustie_logo2.png', + url: url end end