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={}",