pub struct WechatConfig {
pub app_type: WechatAppType,
pub app_id: String,
pub app_secret: String,
pub token: Option<String>,
pub encoding_aes_key: Option<String>,
pub oauth_redirect_uri: Option<String>,
}Expand description
微信配置 — 对齐 PHP EasyWeChat\Factory::officialAccount() 配置
使用 Builder 模式构建,必填字段在 WechatConfig::new 中提供,
可选字段通过 with_* 链式方法追加。
§PHP 对齐
// PHP EasyWeChat
$config = [
'app_id' => 'wx-app-id',
'secret' => 'wx-app-secret',
'token' => 'wx-token',
'aes_key' => 'wx-aes-key',
'oauth' => ['redirect_uri' => 'https://example.com/oauth/callback'],
];
$app = Factory::officialAccount($config);§Rust 用法
ⓘ
use sz_rust_auth_facade::wechat::{WechatAppType, WechatConfig};
let config = WechatConfig::new(
WechatAppType::OfficialAccount,
"wx-app-id",
"wx-app-secret",
)
.with_token("wx-token")
.with_encoding_aes_key("wx-aes-key")
.with_oauth_redirect_uri("https://example.com/oauth/callback");Fields§
§app_type: WechatAppType应用类型
app_id: StringAppID
app_secret: StringAppSecret
token: Option<String>Token(用于消息验证)
encoding_aes_key: Option<String>EncodingAESKey(用于消息加解密)
oauth_redirect_uri: Option<String>OAuth2 回调 URL
Implementations§
Source§impl WechatConfig
impl WechatConfig
Sourcepub fn new(
app_type: WechatAppType,
app_id: impl Into<String>,
app_secret: impl Into<String>,
) -> WechatConfig
pub fn new( app_type: WechatAppType, app_id: impl Into<String>, app_secret: impl Into<String>, ) -> WechatConfig
Sourcepub fn with_token(self, token: impl Into<String>) -> WechatConfig
pub fn with_token(self, token: impl Into<String>) -> WechatConfig
设置消息验证 Token
Sourcepub fn with_encoding_aes_key(self, key: impl Into<String>) -> WechatConfig
pub fn with_encoding_aes_key(self, key: impl Into<String>) -> WechatConfig
设置 EncodingAESKey(消息加解密)
Sourcepub fn with_oauth_redirect_uri(self, uri: impl Into<String>) -> WechatConfig
pub fn with_oauth_redirect_uri(self, uri: impl Into<String>) -> WechatConfig
设置 OAuth2 回调 URL
Sourcepub fn validate(&self) -> Result<(), WechatError>
pub fn validate(&self) -> Result<(), WechatError>
校验配置必填字段
必填字段:app_id / app_secret。任一为空字符串则返回 WechatError::Config。
Trait Implementations§
Source§impl Clone for WechatConfig
impl Clone for WechatConfig
Source§fn clone(&self) -> WechatConfig
fn clone(&self) -> WechatConfig
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for WechatConfig
impl RefUnwindSafe for WechatConfig
impl Send for WechatConfig
impl Sync for WechatConfig
impl Unpin for WechatConfig
impl UnsafeUnpin for WechatConfig
impl UnwindSafe for WechatConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.