lanrion
lanrion
均有这种情况,在 wiki 中 https://github.com/lanrion/weixin_authorize/wiki/Getting-Started#%E7%89%B9%E5%88%AB%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9 对此有特别声明。如果开发者对此有严格的控制,这种异常一般不会出现,即使出现,也可以通过wiki的方法进行处理。
你是不是每台机器都new了一个 WeixinAuthorize::Client?**这样子的话,会互相请求access_token的API,导致其他worker正在使用时失败。** ## 请务必独立一个worker获取access_token,并让其他worker统一调用。 微信的官方wiki对此的解释:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140183&token=&lang=zh_CN > > 1、为了保密appsecrect,第三方需要一个access_token获取和刷新的中控服务器。而其他业务逻辑服务器所使用的access_token均来自于该中控服务器,不应该各自去刷新,否则会造成access_token覆盖而影响业务; ## weixin_authorize 使用自定义token的方法 https://github.com/lanrion/weixin_authorize/wiki/input-custom_access_token 即先在中控服务器使用weixin_authorize的 [get_access_token](https://github.com/lanrion/weixin_authorize/blob/master/lib/weixin_authorize/client.rb#L37)接口获取,然后在其他业务服务器使用这些数据,参照wiki https://github.com/lanrion/weixin_authorize/wiki/input-custom_access_token
workproess 如果是多个的话,可以看成是多个client获取access_token。 根据微信的建议,你需要独立获取access_token,然后供应给其他人使用。
@lingceng 获取access_token 最好是单独一台机器来维护. 添加分布式锁setnx 也是最好的方案.
把错误信息贴一下,同时这样写的话,兼容 < 5的版本吗?
`verify_authenticity_token` 是为了处理 `protect_from_forgery with: :exception` (防止跨域) 但 qy_wechat_controller.rb是直接继承 `ActionController::Base`,不会有protect_from_forgery。 所以这行代码逻辑,应该是不需要的,可以直接删除。