ExWechatpay.Config.Manager (ex_wechatpay v0.3.5)

View Source

配置管理器模块

该模块负责管理 ExWechatpay 的配置,提供配置热更新功能。 通过使用 Agent 进程保存配置,可以在运行时动态更新配置。

Summary

Functions

Returns a specification to start this module under a supervisor.

禁用自动更新证书

获取当前配置

启动配置管理器

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

disable_auto_update(name)

@spec disable_auto_update(atom()) :: :ok

禁用自动更新证书

参数

  • name - 配置管理器名称

返回值

  • :ok - 成功禁用

enable_auto_update(name, client_name, interval \\ 86_400_000)

@spec enable_auto_update(atom(), atom(), non_neg_integer()) :: :ok

启用自动更新证书

参数

  • name - 配置管理器名称
  • client_name - 客户端名称(用于调用 API)
  • interval - 更新间隔(毫秒,默认:1天)

返回值

  • :ok - 成功启用

get_config(name)

@spec get_config(atom()) :: keyword()

获取当前配置

参数

  • name - 配置管理器名称

返回值

  • config - 当前配置

start_link(arg)

@spec start_link({atom(), keyword(), keyword()}) :: GenServer.on_start()

启动配置管理器

参数

  • name - 配置管理器名称
  • config - 初始配置
  • opts - 额外选项
    • :auto_update - 是否启用自动更新证书(默认:false)
    • :update_interval - 自动更新间隔(毫秒,默认:1天)

返回值

  • {:ok, pid} - 成功启动的 GenServer 进程 ID
  • {:error, reason} - 启动失败的原因

update_certificates(name, client_name)

@spec update_certificates(atom(), atom()) :: {:ok, keyword()} | {:error, term()}

更新证书

从微信支付服务器获取最新的平台证书并更新配置。

参数

  • name - 配置管理器名称
  • client_name - 客户端名称(用于调用 API)

返回值

  • {:ok, new_config} - 更新后的配置
  • {:error, error} - 更新失败的错误信息

update_config(name, updates)

@spec update_config(
  atom(),
  keyword()
) :: {:ok, keyword()} | {:error, term()}

更新配置

参数

  • name - 配置管理器名称
  • updates - 要更新的配置

返回值

  • {:ok, new_config} - 更新后的配置
  • {:error, error} - 更新失败的错误信息