Skip to main content

WxDefaultConfig

Struct WxDefaultConfig 

Source
pub struct WxDefaultConfig {
    pub app_id: String,
    pub secret: String,
    pub stable_access_token: bool,
    pub auto_refresh: bool,
    pub http_proxy_host: Option<String>,
    pub http_proxy_port: Option<u16>,
    /* private fields */
}
Expand description

默认内存配置存储实现。

对应 Java Wx*DefaultConfigImpl 的内存语义:token 缓存 + 过期判断 + 锁。 业务模块可用组合方式继承此实现并扩展自身字段。

Fields§

§app_id: String§secret: String§stable_access_token: bool

是否使用稳定版 token 接口

§auto_refresh: bool

token 过期自动刷新

§http_proxy_host: Option<String>

代理主机

§http_proxy_port: Option<u16>

代理端口

Implementations§

Source§

impl WxDefaultConfig

Source

pub fn new(app_id: impl Into<String>, secret: impl Into<String>) -> Self

构建默认配置。

§参数
  • app_id:appId
  • secret:appSecret
Source

pub fn set_clock(&self, clock: Arc<dyn WxClock>) -> bool

注入时钟(仅测试使用:注入 FakeClock 后 token 过期测试零 sleep)。

须在首次读取时间(update_access_token/is_access_token_expired) 之前调用——默认 SystemClock 惰性初始化后不可再替换;重复或迟到 调用返回 false 且不生效。

Trait Implementations§

Source§

impl Debug for WxDefaultConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl WxConfigStorage for WxDefaultConfig

Source§

fn app_id(&self) -> &str

返回 appId。
Source§

fn secret(&self) -> &str

返回 appSecret。
Source§

fn access_token(&self) -> Option<String>

返回当前缓存的 access token。
Source§

fn is_access_token_expired(&self) -> bool

判断 access token 是否已过期。
Source§

fn expire_access_token(&self)

强制将 access token 过期掉。
Source§

fn update_access_token(&self, access_token: &str, expires_in_seconds: i32)

更新 access token(线程安全)。 Read more
Source§

fn access_token_lock(&self) -> Arc<AsyncMutex<()>>

返回 access token 锁(多线程只刷新一次语义)。
Source§

fn is_stable_access_token(&self) -> bool

是否使用稳定版 access token 接口(公众号稳定版)。
Source§

fn auto_refresh_token(&self) -> bool

token 过期时是否自动刷新(默认 true)。
Source§

fn http_proxy_host(&self) -> Option<&str>

返回代理主机(None 为不使用代理)。
Source§

fn http_proxy_port(&self) -> Option<u16>

返回代理端口。
Source§

fn ticket(&self, _ticket_type: TicketType) -> Option<String>

获取指定类型的 ticket 值。
Source§

fn is_ticket_expired(&self, _ticket_type: TicketType) -> bool

判断指定类型的 ticket 是否已过期。
Source§

fn update_ticket( &self, _ticket_type: TicketType, _ticket: &str, _expires_in_seconds: i32, )

更新指定类型的 ticket(线程安全)。
Source§

fn ticket_lock(&self, _ticket_type: TicketType) -> Arc<AsyncMutex<()>>

返回指定类型 ticket 的锁(对应 Java getTicketLock(TicketType) 按类型分配锁)。
Source§

fn expire_ticket(&self, _ticket_type: TicketType)

强制将指定类型的 ticket 过期掉(对应 Java expireTicket)。
Source§

fn tmp_dir(&self) -> Option<&str>

返回临时目录。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more