Skip to content

Commit

Permalink
fix: 修改百度accessToken换成key,避免更换secretId时不获取新的Token,导致不切换账号问题 (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-wangwei authored Jan 2, 2025
1 parent 317206f commit c41f5d9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Support/BaiduAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,28 @@ class BaiduAccessToken

protected $cache;

private $tokenKey;

public function __construct(Http $http, CacheInterface $cache, string $secretID = null, string $secretKey = null)
{
$this->secretID = $secretID;
$this->secretKey = $secretKey;
$this->http = $http;
$this->cache = $cache;
$this->tokenKey = self::CACHE_KEY . '.' . $secretID;
}

public function getAccessToken(): string
{
$accessToken = $this->cache->get(self::CACHE_KEY);
$accessToken = $this->cache->get($this->tokenKey);

if ($accessToken) {
return $accessToken;
}

[$accessToken, $expiresIn] = $this->requestAccessToken();

$this->cache->set(self::CACHE_KEY, $accessToken, $expiresIn - 10);
$this->cache->set($this->tokenKey, $accessToken, $expiresIn - 10);

return $accessToken;
}
Expand Down

0 comments on commit c41f5d9

Please sign in to comment.