From 55155e0fb624246a21489665b3b973e7fe82e26d Mon Sep 17 00:00:00 2001 From: RandyZhang Date: Thu, 29 May 2025 10:08:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4Google=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E7=9A=84Token=E8=BF=87=E6=9C=9F=E6=97=B6=E9=97=B4=EF=BC=8C?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E4=BB=8EToken=E8=AE=A4=E8=AF=81=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E4=B8=AD=E8=8E=B7=E5=8F=96=E8=BF=87=E6=9C=9F=E6=97=B6?= =?UTF-8?q?=E9=97=B4=EF=BC=8C=E5=A6=82=E6=9E=9C=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E4=BC=9A=E9=80=89=E6=8B=A9=E9=BB=98=E8=AE=A4=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- relay/adaptor/vertexai/token.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/relay/adaptor/vertexai/token.go b/relay/adaptor/vertexai/token.go index 0a5e0aad..b007711a 100644 --- a/relay/adaptor/vertexai/token.go +++ b/relay/adaptor/vertexai/token.go @@ -57,6 +57,17 @@ func getToken(ctx context.Context, channelId int, adcJson string) (string, error } _ = resp - Cache.Set(cacheKey, resp.AccessToken, cache.DefaultExpiration) + // 使用响应中的过期时间,如果获取失败则使用默认时间 + expiration := cache.DefaultExpiration + if resp.ExpireTime != nil { + _expiration := time.Until(resp.ExpireTime.AsTime()) + // 提前10分钟过期,避免边界情况 + _expiration = _expiration - 10*time.Minute + if _expiration > 0 { + expiration = _expiration + } + } + + Cache.Set(cacheKey, resp.AccessToken, expiration) return resp.AccessToken, nil }