Skip to content

Commit

Permalink
Fixed #2721
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Jul 5, 2023
1 parent 94de802 commit 10b9f31
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
19 changes: 9 additions & 10 deletions src/MiniApp/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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 @@ -19,15 +20,13 @@
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 @@ -50,7 +49,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 @@ -74,7 +73,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 @@ -107,7 +106,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 @@ -126,7 +125,7 @@ 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(),
Expand Down Expand Up @@ -169,7 +168,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 @@ -180,7 +179,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 change: 0 additions & 1 deletion tests/Kernel/HttpClient/RequestUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use EasyWeChat\Kernel\HttpClient\RequestUtil;
use EasyWeChat\Kernel\Support\UserAgent;
use EasyWeChat\Kernel\Support\Xml;
use EasyWeChat\Tests\TestCase;
use Symfony\Component\HttpClient\Retry\GenericRetryStrategy;

Expand Down

1 comment on commit 10b9f31

@vercel
Copy link

@vercel vercel bot commented on 10b9f31 Jul 5, 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.vercel.app
easywechat-git-6x-overtrue.vercel.app
easywechat-overtrue.vercel.app

Please sign in to comment.