Skip to content

Commit

Permalink
fix MiniApp Application getAccessToken lost stable arguments (#2719)
Browse files Browse the repository at this point in the history
  • Loading branch information
lyt8384 committed Jul 4, 2023
1 parent 7487ea7 commit 00cf52d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/MiniApp/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace EasyWeChat\MiniApp;

use function array_merge;
use EasyWeChat\Kernel\Contracts\AccessToken as AccessTokenInterface;
use EasyWeChat\Kernel\Contracts\Server as ServerInterface;
use EasyWeChat\Kernel\Encryptor;
Expand All @@ -20,13 +19,15 @@
use EasyWeChat\Kernel\Traits\InteractWithServerRequest;
use EasyWeChat\MiniApp\Contracts\Account as AccountInterface;
use EasyWeChat\MiniApp\Contracts\Application as ApplicationInterface;
use function is_null;
use JetBrains\PhpStorm\Pure;
use Psr\Log\LoggerAwareTrait;
use function str_contains;
use Symfony\Component\HttpClient\Response\AsyncContext;
use Symfony\Component\HttpClient\RetryableHttpClient;

use function array_merge;
use function is_null;
use function str_contains;

/**
* @psalm-suppress PropertyNotSetInConstructor
*/
Expand All @@ -49,7 +50,7 @@ class Application implements ApplicationInterface

public function getAccount(): AccountInterface
{
if (! $this->account) {
if (!$this->account) {
$this->account = new Account(
appId: (string) $this->config->get('app_id'), /** @phpstan-ignore-line */
secret: (string) $this->config->get('secret'), /** @phpstan-ignore-line */
Expand All @@ -73,7 +74,7 @@ public function setAccount(AccountInterface $account): static
*/
public function getEncryptor(): Encryptor
{
if (! $this->encryptor) {
if (!$this->encryptor) {
$token = $this->getAccount()->getToken();
$aesKey = $this->getAccount()->getAesKey();

Expand Down Expand Up @@ -106,7 +107,7 @@ public function setEncryptor(Encryptor $encryptor): static
*/
public function getServer(): Server|ServerInterface
{
if (! $this->server) {
if (!$this->server) {
$this->server = new Server(
request: $this->getRequest(),
encryptor: $this->getAccount()->getAesKey() ? $this->getEncryptor() : null
Expand All @@ -125,12 +126,13 @@ public function setServer(ServerInterface $server): static

public function getAccessToken(): AccessTokenInterface
{
if (! $this->accessToken) {
if (!$this->accessToken) {
$this->accessToken = new AccessToken(
appId: $this->getAccount()->getAppId(),
secret: $this->getAccount()->getSecret(),
cache: $this->getCache(),
httpClient: $this->getHttpClient(),
stable: $this->config->get('use_stable_access_token', false)
);
}

Expand Down Expand Up @@ -167,7 +169,7 @@ public function createClient(): AccessTokenAwareClient
accessToken: $this->getAccessToken(),
failureJudge: fn (
Response $response
) => (bool) ($response->toArray()['errcode'] ?? 0) || ! is_null($response->toArray()['error'] ?? null),
) => (bool) ($response->toArray()['errcode'] ?? 0) || !is_null($response->toArray()['error'] ?? null),
throw: (bool) $this->config->get('http.throw', true),
))->setPresets($this->config->all());
}
Expand All @@ -178,7 +180,7 @@ public function getRetryStrategy(): AccessTokenExpiredRetryStrategy

return (new AccessTokenExpiredRetryStrategy($retryConfig))
->decideUsing(function (AsyncContext $context, ?string $responseContent): bool {
return ! empty($responseContent)
return !empty($responseContent)
&& str_contains($responseContent, '42001')
&& str_contains($responseContent, 'access_token expired');
});
Expand Down

1 comment on commit 00cf52d

@vercel
Copy link

@vercel vercel bot commented on 00cf52d Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

easywechat – ./

easywechat-overtrue.vercel.app
easywechat-git-6x-overtrue.vercel.app
easywechat.vercel.app

Please sign in to comment.