feat: 接入微信小程序支付

This commit is contained in:
2026-05-14 00:16:17 +08:00
parent bf4423e53b
commit ae58a443a3
42 changed files with 2265 additions and 191 deletions

View File

@@ -118,6 +118,14 @@ pub struct WechatIdentityProfile {
pub avatar_url: Option<String>,
}
/// 已绑定微信身份快照。
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct WechatIdentityRecord {
pub user_id: String,
pub provider_uid: String,
pub provider_union_id: Option<String>,
}
/// 微信授权 state 快照。
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct WechatAuthStateRecord {

View File

@@ -797,6 +797,13 @@ impl WechatAuthService {
created: true,
})
}
pub fn get_identity_by_user_id(
&self,
user_id: &str,
) -> Result<Option<WechatIdentityRecord>, WechatAuthError> {
self.store.get_wechat_identity_by_user_id(user_id)
}
}
impl AuthUserService {
@@ -1342,6 +1349,29 @@ impl InMemoryAuthStore {
.map(|stored| stored.user.clone()))
}
fn get_wechat_identity_by_user_id(
&self,
user_id: &str,
) -> Result<Option<WechatIdentityRecord>, WechatAuthError> {
let state = self
.inner
.lock()
.map_err(|_| WechatAuthError::Store("用户仓储锁已中毒".to_string()))?;
let Some(identity) = state
.wechat_identity_by_provider_uid
.values()
.find(|identity| identity.user_id == user_id.trim())
else {
return Ok(None);
};
Ok(Some(WechatIdentityRecord {
user_id: identity.user_id.clone(),
provider_uid: identity.provider_uid.clone(),
provider_union_id: identity.provider_union_id.clone(),
}))
}
fn refresh_wechat_identity_profile(
&self,
user_id: &str,