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