From f9a594ad5052907a36175d8d84241ebd7ae9d60a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=BF=90=E5=AE=B6?= Date: Thu, 23 Jan 2025 14:40:38 +0800 Subject: [PATCH] =?UTF-8?q?google.rs=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/src/social/google.rs | 76 ++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 7 deletions(-) diff --git a/library/src/social/google.rs b/library/src/social/google.rs index 59c77c8..a8a1892 100644 --- a/library/src/social/google.rs +++ b/library/src/social/google.rs @@ -28,15 +28,82 @@ pub struct GoogleSocial { google_public_keys: Arc>, } -// 假设GOOGLE_PUBLIC_CERT_URL是Google提供的公钥URL +/// 假设GOOGLE_PUBLIC_CERT_URL是Google提供的公钥URL const GOOGLE_PUBLIC_CERT_URL: &str = "https://www.googleapis.com/oauth2/v3/certs"; -// Google OAuth2 相关常量 +/// 用途:授权端点 +/// - 用户登录和授权的入口 +/// - 获取用户同意访问特定范围的权限 const GOOGLE_AUTH_URL: &str = "https://accounts.google.com/o/oauth2/v2/auth"; +/// 用途:令牌端点 +/// - 使用授权码交换访问令牌 +/// - 刷新访问令牌 +/// - 获取新的访问令牌 const GOOGLE_TOKEN_URL: &str = "https://oauth2.googleapis.com/token"; +/// 用途:令牌撤销端点 +/// - 撤销访问令牌 +/// - 撤销刷新令牌 +/// - 用户退出登录时使用 const GOOGLE_REVOCATION_URL: &str = "https://oauth2.googleapis.com/revoke"; +/// 用途:Google Play Games 权限范围 +/// - 访问游戏相关API的权限 +/// - 获取玩家信息、成就等 const GOOGLE_GAMES_SCOPE: &str = "https://www.googleapis.com/auth/games"; +/// 用途:用户资料权限范围 +/// - 访问用户基本资料的权限 +/// - 获取用户名、头像等信息 const GOOGLE_PROFILE_SCOPE: &str = "https://www.googleapis.com/auth/userinfo.profile"; +/// 用途:获取玩家状态信息 +/// 返回的信息包括: +/// - 游戏进度 +/// - 玩家统计数据 +/// - 游戏内状态 +/// - 成就完成情况 +/// - 排行榜数据等 +/// 示例响应: +/// ``` +/// { +/// "kind": "games#playerState", +/// "timeMillis": "1234567890", +/// "key": "gameState", +/// "data": { +/// // 游戏相关的状态数据 +/// "progress": "...", +/// "achievements": [...], +/// "scores": [...], +/// // 其他游戏特定数据 +/// } +/// } +/// ``` +const PLAY_GAMES_PLAYER_STATS_URL: &str = "https://games.googleapis.com/games/v1/players/me/playerStates"; +/// 用途:获取玩家基本资料 +/// 返回的信息包括: +// - 玩家ID (playerId) +/// - 显示名称 (displayName) +/// - 头像URL (avatarImageUrl) +/// - 玩家等级 +/// - 最后登录时间 +/// - 玩家标签 +/// 示例响应: +/// ``` +/// { +/// "kind": "games#player", +/// "playerId": "123456789", +/// "displayName": "Player Name", +/// "avatarImageUrl": "https://...", +/// "bannerUrlLandscape": "https://...", +/// "bannerUrlPortrait": "https://...", +/// "profileSettings": { +/// "friendsListVisibility": "ALL" +/// }, +/// "title": "Level 10 Player", +/// "lastPlayedWith": { +/// "kind": "games#played", +/// "timeMillis": "1234567890" +/// } +/// } +/// ``` +const PLAY_GAMES_PROFILE_URL: &str = "https://games.googleapis.com/games/v1/players/me"; #[derive(Debug, Default, Deserialize)] pub struct GoogleJwtProfile { @@ -230,8 +297,6 @@ impl GoogleSocial { /// 获取 Google Play Games 用户资料 async fn fetch_play_games_profile(&self, access_token: &str) -> SocialResult { - const PLAY_GAMES_PROFILE_URL: &str = "https://games.googleapis.com/games/v1/players/me"; - let client = Client::new(); let response = client .get(PLAY_GAMES_PROFILE_URL) @@ -274,9 +339,6 @@ impl GoogleSocial { &self, access_token: &str, ) -> SocialResult> { - const PLAY_GAMES_PLAYER_STATS_URL: &str = - "https://games.googleapis.com/games/v1/players/me/playerStates"; - let client = Client::new(); let response = client .get(PLAY_GAMES_PLAYER_STATS_URL)