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