View Source WeChat.Refresher.Default (wechat v0.16.0)
AccessToken 刷新器 - 用于定时刷新 AccessToken
本模块为默认的刷新器
需要修改为自定义的刷新器,可以这样配置:
config :wechat, :refresher, YourRefresher
修改刷新器的配置,支持多种配置方式:
方式1
config :wechat, :refresh_settings, [ClientA, ClientB, ClientC]
以上配置会自动为三个 Client
定时刷新 AccessToken
,
默认会在 AccessToken
过期前 30
分钟刷新,
AccessToken
刷新失败的重试间隔为 1
分钟,
可以通过接口 获取默认的 AccessToken
刷新列表:WeChat.Refresher.DefaultSettings.get_refresh_options_by_client/1
方式2
config :wechat, :refresh_settings, [{ClientA, client_setting}, ClientB, ClientC]
# or
config :wechat, :refresh_settings, %{ClientA => client_setting, ClientB => client_setting, ClientC => client_setting}
client_setting
配置说明见:client_setting/0
为了适应 Storage
在 Refresher
启动之后才启动,可以开启延时启动刷新:
config :wechat, WeChat.Refresher.Default, wait_for_signal: true
当所有的 Storage
都已经完成,可以即可通过 WeChat.Refresher.Default.start_monitor/0
方法刷新 AccessToken
不配置默认为立即启动刷新
Summary
Functions
Returns a specification to start this module under a supervisor.
Types
@type client_setting() :: %{ optional(:refresh_before_expired) => refresh_before_expired(), optional(:refresh_retry_interval) => refresh_retry_interval(), optional(:refresh_options) => WeChat.Refresher.DefaultSettings.refresh_options() }
option
:refresh_before_expired
: 在AccessToken
超时前多少秒刷新,单位:秒,可选, 为保证hub
&hub_client
刷新正常,请保持两者的时间一致;server_role=hub_client
时, 默认值:1800 + 30
秒; 其余角色默认值:1800
秒:refresh_retry_interval
: 刷新AccessToken
失败的重试间隔,单位:秒,可选,默认值:60000
秒:refresh_options
: 刷新AccessToken
配置,可选,默认值:WeChat.Refresher.DefaultSettings.get_refresh_options_by_client/1
的输出结果
@type client_settings() :: [WeChat.client()] | %{required(WeChat.client()) => client_setting()}
@type refresh_before_expired() :: non_neg_integer()
在 AccessToken
超时前多少秒刷新,单位:秒
如果server_role
= hub
, hub server
的值请大于 hub client
@type refresh_retry_interval() :: non_neg_integer()
刷新 AccessToken
失败的重试间隔,单位:秒
@type state() :: %{ :wait_for_signal => boolean(), :clients => [WeChat.client()], required(WeChat.client()) => client_setting() }
Functions
@spec add(WeChat.client(), client_setting()) :: :ok
@spec append_work_agent(WeChat.client(), WeChat.Work.Agent.t()) :: :ok | :client_not_in
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec client_options(WeChat.client()) :: client_setting() | nil
@spec clients() :: [WeChat.client()]
@spec components() :: %{ required(WeChat.component_appid()) => %{ keys: [WeChat.Storage.Adapter.store_key()], clients: [WeChat.client()] } }
@spec refresh(WeChat.client()) :: :ok | :not_found
@spec refresh( WeChat.client(), WeChat.Storage.Adapter.store_id(), WeChat.Storage.Adapter.store_key() ) :: :ok | :not_found
@spec refresh_component(WeChat.component_appid(), WeChat.Storage.Adapter.store_key()) :: :ok | :not_found
@spec refresh_key( WeChat.client(), WeChat.Storage.Adapter.store_id(), WeChat.Storage.Adapter.store_key(), WeChat.Storage.Adapter.value(), expires :: integer() ) :: :ok
@spec remove(WeChat.client()) :: :ok | :not_found
@spec start_link(client_settings()) :: GenServer.on_start()
@spec start_monitor() :: :ok