过期时间增加30秒缓冲时间
This commit is contained in:
parent
4b2744de4e
commit
a99589283a
@ -90,7 +90,7 @@ impl GoogleSocial {
|
||||
&self,
|
||||
) -> SocialResult<HashMap<String, GooglePublicKey>> {
|
||||
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);
|
||||
|
@ -99,7 +99,8 @@ impl WechatSocial {
|
||||
pub async fn get_access_token(&self) -> SocialResult<WeChatAccessToken> {
|
||||
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={}",
|
||||
|
Loading…
Reference in New Issue
Block a user