From 9d867aa22402cd7cd5a6836f3e577d40faa1d826 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Sun, 14 Aug 2016 11:50:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BE=AE=E4=BF=A1BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/new_comment.rb | 16 +++++++++++++++- app/controllers/wechats_controller.rb | 6 +++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index e5e42e624..b8337451f 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -23,7 +23,21 @@ module Mobile refresh_token = session[:refresh_token] if access_token.present? && refresh_token.present? - refreshinfo = Wechat.api.web_refresh_access_token(refresh_token) + begin + refreshinfo = Wechat.api.web_refresh_access_token(refresh_token) + rescue + info = wechat.web_access_token(session[:wechat_code]) + openid =info["openid"] + access_token =info["access_token"] + if access_token + session[:access_token] = access_token + end + refresh_token = info["refresh_token"] + if refresh_token + session[:refresh_token] = refresh_token + end + refreshinfo = Wechat.api.web_refresh_access_token(refresh_token) + end access_token = refreshinfo["access_token"] refresh_token = refreshinfo["refresh_token"] diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index ced8854d9..3e81d491b 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -470,7 +470,11 @@ class WechatsController < ActionController::Base def user_binded?(openid) uw = UserWechat.where(openid: openid).first - uw && uw.bindtype == 0 + if uw.bindtype == 0 + uw + else + nil + end end def current_url