google.rs添加注释
This commit is contained in:
parent
139536924d
commit
f9a594ad50
@ -28,15 +28,82 @@ pub struct GoogleSocial {
|
|||||||
google_public_keys: Arc<Mutex<GooglePublicKeys>>,
|
google_public_keys: Arc<Mutex<GooglePublicKeys>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 假设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";
|
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_AUTH_URL: &str = "https://accounts.google.com/o/oauth2/v2/auth";
|
||||||
|
/// 用途:令牌端点
|
||||||
|
/// - 使用授权码交换访问令牌
|
||||||
|
/// - 刷新访问令牌
|
||||||
|
/// - 获取新的访问令牌
|
||||||
const GOOGLE_TOKEN_URL: &str = "https://oauth2.googleapis.com/token";
|
const GOOGLE_TOKEN_URL: &str = "https://oauth2.googleapis.com/token";
|
||||||
|
/// 用途:令牌撤销端点
|
||||||
|
/// - 撤销访问令牌
|
||||||
|
/// - 撤销刷新令牌
|
||||||
|
/// - 用户退出登录时使用
|
||||||
const GOOGLE_REVOCATION_URL: &str = "https://oauth2.googleapis.com/revoke";
|
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_GAMES_SCOPE: &str = "https://www.googleapis.com/auth/games";
|
||||||
|
/// 用途:用户资料权限范围
|
||||||
|
/// - 访问用户基本资料的权限
|
||||||
|
/// - 获取用户名、头像等信息
|
||||||
const GOOGLE_PROFILE_SCOPE: &str = "https://www.googleapis.com/auth/userinfo.profile";
|
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)]
|
#[derive(Debug, Default, Deserialize)]
|
||||||
pub struct GoogleJwtProfile {
|
pub struct GoogleJwtProfile {
|
||||||
@ -230,8 +297,6 @@ impl GoogleSocial {
|
|||||||
|
|
||||||
/// 获取 Google Play Games 用户资料
|
/// 获取 Google Play Games 用户资料
|
||||||
async fn fetch_play_games_profile(&self, access_token: &str) -> SocialResult<GoogleJwtProfile> {
|
async fn fetch_play_games_profile(&self, access_token: &str) -> SocialResult<GoogleJwtProfile> {
|
||||||
const PLAY_GAMES_PROFILE_URL: &str = "https://games.googleapis.com/games/v1/players/me";
|
|
||||||
|
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let response = client
|
let response = client
|
||||||
.get(PLAY_GAMES_PROFILE_URL)
|
.get(PLAY_GAMES_PROFILE_URL)
|
||||||
@ -274,9 +339,6 @@ impl GoogleSocial {
|
|||||||
&self,
|
&self,
|
||||||
access_token: &str,
|
access_token: &str,
|
||||||
) -> SocialResult<Option<Value>> {
|
) -> SocialResult<Option<Value>> {
|
||||||
const PLAY_GAMES_PLAYER_STATS_URL: &str =
|
|
||||||
"https://games.googleapis.com/games/v1/players/me/playerStates";
|
|
||||||
|
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let response = client
|
let response = client
|
||||||
.get(PLAY_GAMES_PLAYER_STATS_URL)
|
.get(PLAY_GAMES_PLAYER_STATS_URL)
|
||||||
|
Loading…
Reference in New Issue
Block a user