Gem gem “weixin_authorize” 出现错误{"errcode":45009,"errmsg":"api freq out of limit"}

liguangsong · 2015年12月08日 · 最后由 ruby_sky 回复于 2015年12月08日 · 6013 次阅读

现在网站的人上去了,出现请求 access_token 超过最大值,我用的是 weixin_authorize,我的代码如下: 麻烦大神们看看,是哪里出错造成了,请求超出最大值

WeixinAuthorize.configure do |config|
  config.rest_client_options = {timeout: 50, open_timeout: 50, verify_ssl: true}
end

这里的 timeout 和 open_timeout 不知道是怎么使用的,没有查到说明

module WeiXin
  def self.client
    $client = WeixinAuthorize::Client.new(APP_ID, APP_SECRET)
  end
end
require './app/service/weixin/js_sdk'
  def get_ticket
   if !$client || !$client.is_valid?
     $client = WeiXin.client()
   end
   # $client = WeiXin.client()
   sign_package = $client.get_jssign_package(params[:url])
   render :json => {:sign_package => sign_package}
 end

这里的 timeout 和 open_timeout 不知道是怎么使用的,没有查到说明

timeout: session expires in seconds open_timeout:

Number of seconds to wait for the connection to open. Any number may be used, including Floats for fractional seconds. If the FTP object cannot open a connection in this many seconds, it raises a Net::OpenTimeout exception. The default value is nil.

都是以秒为单位。

还有,你的标题提示的 {"errcode":45009,"errmsg":"api freq out of limit"} 明显是接口调用次数超出了频率限制,建议使用 redis 存储你的 token,不要重复调用获取 access_token 的接口:https://github.com/lanrion/weixin_authorize/wiki/config

is_valid?,这个方法会直接将现有的 token 过期,不需要每次调用。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号