From 527b695fabd89abe5cee5215eca85ddd26c87186 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 19 Jan 2016 14:46:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=91=E5=AE=9A=E8=AE=A4=E8=AF=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=20bind?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/wechats_controller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index dc3804bf8..017886194 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -125,10 +125,12 @@ class WechatsController < ActionController::Base end else openid = request[:FromUserName] - puts wechat.user(request[:openid]) + 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: 'https://www.trustie.net/images/trustie_logo1.png', url: login_wechat_url + article.item title: "#{n[:title]}", description: n[:content], pic_url: 'https://www.trustie.net/images/trustie_logo1.png', url: login_wechat_url(openid: uw.id) end end end @@ -140,7 +142,7 @@ class WechatsController < ActionController::Base raise "用户名或密码错误,请重新登录" unless user #补全用户信息 - user.user_wechat = UserWechat.new(openid: params[:openid]) + user.user_wechat = UserWechat.find_by_id(params[:openid]) user.save! rescue Exception=>e @wechat_bind_errors = e.message