From a99589283ad0fe811e9c6e95a5ecd3b4ae76692e Mon Sep 17 00:00:00 2001 From: liyunjia Date: Sun, 5 Jan 2025 19:18:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=87=E6=9C=9F=E6=97=B6=E9=97=B4=E5=A2=9E?= =?UTF-8?q?=E5=8A=A030=E7=A7=92=E7=BC=93=E5=86=B2=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/src/social/google.rs | 2 +- library/src/social/wechat.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/library/src/social/google.rs b/library/src/social/google.rs index 07db408..b03bacf 100644 --- a/library/src/social/google.rs +++ b/library/src/social/google.rs @@ -90,7 +90,7 @@ impl GoogleSocial { &self, ) -> SocialResult> { let mut public_keys = self.google_public_keys.lock().await; - if public_keys.keys.is_empty() || public_keys.refresh_at < Utc::now().timestamp() { + if public_keys.keys.is_empty() || public_keys.refresh_at < (Utc::now().timestamp() - 30) { let response = Client::new().get(GOOGLE_PUBLIC_CERT_URL).send().await?; let mut google_keys: GooglePublicKeys = response.json().await?; tracing::info!("Google公钥获取成功, {:?}", google_keys); diff --git a/library/src/social/wechat.rs b/library/src/social/wechat.rs index 01e43af..6ab1684 100644 --- a/library/src/social/wechat.rs +++ b/library/src/social/wechat.rs @@ -99,7 +99,8 @@ impl WechatSocial { pub async fn get_access_token(&self) -> SocialResult { let mut wechat_access_token = self.access_token.lock().await; if wechat_access_token.access_token.is_empty() - && wechat_access_token.expires_in < Utc::now().timestamp() + // 缓存的access_token过期了,为了防止token已经接近过期时间,所以这里加了30秒的缓冲时间 + && wechat_access_token.expires_in < (Utc::now().timestamp() - 30) { let response = reqwest::get(format!( "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}",