From cb143c376a05b4721d58c5e01af78ff5ca186ecd Mon Sep 17 00:00:00 2001 From: wjfz Date: Wed, 31 Aug 2022 12:02:23 +0800 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20=E7=94=B1=E5=8C=85=E7=BB=B4?= =?UTF-8?q?=E6=8A=A4=E6=8E=88=E6=9D=83=E4=BC=81=E4=B8=9A=E7=9A=84token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/OpenWork/Application.php | 23 +++-- src/OpenWork/AuthorizerAccessToken.php | 120 +++++++++++++++++++++++-- 2 files changed, 123 insertions(+), 20 deletions(-) diff --git a/src/OpenWork/Application.php b/src/OpenWork/Application.php index 9f13e9219..c10c9ba97 100644 --- a/src/OpenWork/Application.php +++ b/src/OpenWork/Application.php @@ -43,6 +43,8 @@ class Application implements ApplicationInterface protected ?AccessTokenInterface $suiteAccessToken = null; + protected ?AuthorizerAccessToken $authorizerAccessToken = null; + public function getAccount(): AccountInterface { if (! $this->account) { @@ -247,21 +249,18 @@ public function getAuthorizerAccessToken( ?AccessTokenInterface $suiteAccessToken = null ): AuthorizerAccessToken { $suiteAccessToken = $suiteAccessToken ?? $this->getSuiteAccessToken(); - $response = $this->getHttpClient()->request('POST', 'cgi-bin/service/get_corp_token', [ - 'query' => [ - 'suite_access_token' => $suiteAccessToken->getToken(), - ], - 'json' => [ - 'auth_corpid' => $corpId, - 'permanent_code' => $permanentCode, - ], - ])->toArray(false); - if (empty($response['access_token'])) { - throw new HttpException('Failed to get access_token: '.json_encode($response, JSON_UNESCAPED_UNICODE)); + if (!$this->authorizerAccessToken) { + $this->authorizerAccessToken = new AuthorizerAccessToken( + corpId: $corpId, + permanentCodeOrAccessToken: $permanentCode, + suiteAccessToken: $suiteAccessToken, + cache: $this->getCache(), + httpClient: $this->getHttpClient(), + ); } - return new AuthorizerAccessToken($corpId, accessToken: $response['access_token']); + return $this->authorizerAccessToken; } public function createClient(): AccessTokenAwareClient diff --git a/src/OpenWork/AuthorizerAccessToken.php b/src/OpenWork/AuthorizerAccessToken.php index b479c4cac..1b2f66b6d 100644 --- a/src/OpenWork/AuthorizerAccessToken.php +++ b/src/OpenWork/AuthorizerAccessToken.php @@ -4,15 +4,38 @@ namespace EasyWeChat\OpenWork; -use EasyWeChat\Kernel\Contracts\AccessToken; +use EasyWeChat\Kernel\Contracts\AccessToken as AccessTokenInterface; +use EasyWeChat\Kernel\Contracts\RefreshableAccessToken; +use EasyWeChat\Kernel\Exceptions\HttpException; use JetBrains\PhpStorm\ArrayShape; -use JetBrains\PhpStorm\Pure; +use Psr\SimpleCache\CacheInterface; +use Psr\SimpleCache\InvalidArgumentException; use Stringable; +use Symfony\Component\Cache\Adapter\FilesystemAdapter; +use Symfony\Component\Cache\Psr16Cache; +use Symfony\Component\HttpClient\HttpClient; +use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; +use Symfony\Contracts\HttpClient\HttpClientInterface; -class AuthorizerAccessToken implements AccessToken, Stringable +class AuthorizerAccessToken implements RefreshableAccessToken, Stringable { - public function __construct(protected string $corpId, protected string $accessToken) - { + protected HttpClientInterface $httpClient; + protected CacheInterface $cache; + + public function __construct( + protected string $corpId, + protected string $permanentCodeOrAccessToken, + protected ?AccessTokenInterface $suiteAccessToken = null, + protected ?string $key = null, + ?CacheInterface $cache = null, + ?HttpClientInterface $httpClient = null, + ) { + $this->httpClient = $httpClient ?? HttpClient::create(['base_uri' => 'https://qyapi.weixin.qq.com/']); + $this->cache = $cache ?? new Psr16Cache(new FilesystemAdapter(namespace: 'easywechat', defaultLifetime: 1500)); } public function getCorpId(): string @@ -20,23 +43,104 @@ public function getCorpId(): string return $this->corpId; } + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws InvalidArgumentException + * @throws ClientExceptionInterface + * @throws HttpException + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ public function getToken(): string { - return $this->accessToken; + if (!isset($this->suiteAccessToken)) { + return $this->permanentCodeOrAccessToken; + } + + $token = $this->cache->get($this->getKey()); + + if (!!$token && is_string($token)) { + return $token; + } + + return $this->refresh(); } + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws InvalidArgumentException + * @throws ClientExceptionInterface + * @throws HttpException + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ public function __toString() { - return $this->accessToken; + return $this->getToken(); } /** - * @return array + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws InvalidArgumentException + * @throws ClientExceptionInterface + * @throws HttpException + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface */ + #[ArrayShape(['access_token' => "string"])] #[Pure] #[ArrayShape(['access_token' => 'string'])] public function toQuery(): array { return ['access_token' => $this->getToken()]; } + + public function getKey(): string + { + return $this->key ?? $this->key = sprintf('open_work.authorizer.access_token.%s', $this->corpId); + } + + public function setKey(string $key): static + { + $this->key = $key; + + return $this; + } + + /** + * @throws HttpException + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws InvalidArgumentException + */ + public function refresh(): string + { + if (!isset($this->suiteAccessToken)) { + return ''; + } + + $response = $this->httpClient->request('POST', 'cgi-bin/service/get_corp_token', [ + 'query' => [ + 'suite_access_token' => $this->suiteAccessToken->getToken(), + ], + 'json' => [ + 'auth_corpid' => $this->corpId, + 'permanent_code' => $this->permanentCodeOrAccessToken, + ], + ])->toArray(false); + + if (empty($response['access_token'])) { + throw new HttpException('Failed to get access_token: ' . json_encode($response, JSON_UNESCAPED_UNICODE)); + } + + $this->cache->set($this->getKey(), $response['access_token'], intval($response['expires_in'])); + + return $response['access_token']; + } } From 46b13124cac0068d1b2e8faecdbf3c22637e38a1 Mon Sep 17 00:00:00 2001 From: wjfz Date: Wed, 31 Aug 2022 16:54:07 +0800 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20OpenWork=E6=B7=BB=E5=8A=A0getAuthor?= =?UTF-8?q?izerClient?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/OpenWork/Application.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/OpenWork/Application.php b/src/OpenWork/Application.php index c10c9ba97..10c8d0e4e 100644 --- a/src/OpenWork/Application.php +++ b/src/OpenWork/Application.php @@ -21,6 +21,12 @@ use Overtrue\Socialite\Contracts\ProviderInterface as SocialiteProviderInterface; use Overtrue\Socialite\Providers\OpenWeWork; +use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; + class Application implements ApplicationInterface { use InteractWithCache; @@ -273,6 +279,24 @@ public function createClient(): AccessTokenAwareClient ))->setPresets($this->config->all()); } + /** + * @throws HttpException + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + */ + public function getAuthorizerClient(string $corpId, string $permanentCode, ?AccessTokenInterface $suiteAccessToken = null): AccessTokenAwareClient + { + return (new AccessTokenAwareClient( + client: $this->getHttpClient(), + accessToken: $this->getAuthorizerAccessToken($corpId, $permanentCode, $suiteAccessToken), + failureJudge: fn (Response $response) => !!($response->toArray()['errcode'] ?? 0), + throw: !!$this->config->get('http.throw', true), + ))->setPresets($this->config->all()); + } + public function getOAuth( string $suiteId, ?AccessTokenInterface $suiteAccessToken = null From 4dbd844cc4c10460e8c0afcc6c61a7f9aa4a79b2 Mon Sep 17 00:00:00 2001 From: wjfz Date: Wed, 31 Aug 2022 18:25:38 +0800 Subject: [PATCH 3/7] =?UTF-8?q?feat:=20OpenWork=E6=B7=BB=E5=8A=A0jsApiTick?= =?UTF-8?q?et?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/OpenWork/Application.php | 17 ++++ src/OpenWork/JsApiTicket.php | 163 +++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 src/OpenWork/JsApiTicket.php diff --git a/src/OpenWork/Application.php b/src/OpenWork/Application.php index 10c8d0e4e..a34808819 100644 --- a/src/OpenWork/Application.php +++ b/src/OpenWork/Application.php @@ -297,6 +297,23 @@ public function getAuthorizerClient(string $corpId, string $permanentCode, ?Acce ))->setPresets($this->config->all()); } + /** + * @throws HttpException + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + */ + public function getJsApiTicket(string $corpId, string $permanentCode, ?AccessTokenInterface $suiteAccessToken = null): JsApiTicket + { + return new JsApiTicket( + corpId: $corpId, + cache: $this->getCache(), + httpClient: $this->getAuthorizerClient($corpId, $permanentCode, $suiteAccessToken), + ); + } + public function getOAuth( string $suiteId, ?AccessTokenInterface $suiteAccessToken = null diff --git a/src/OpenWork/JsApiTicket.php b/src/OpenWork/JsApiTicket.php new file mode 100644 index 000000000..3d65ed08e --- /dev/null +++ b/src/OpenWork/JsApiTicket.php @@ -0,0 +1,163 @@ +httpClient = $httpClient ?? HttpClient::create(['base_uri' => 'https://qyapi.weixin.qq.com/']); + $this->cache = $cache ?? new Psr16Cache(new FilesystemAdapter(namespace: 'easywechat', defaultLifetime: 1500)); + } + + /** + * @return array + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws InvalidArgumentException + * @throws HttpException + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function createConfigSignature(string $nonce, int $timestamp, string $url, array $jsApiList = [], bool $debug = false, bool $beta = true): array + { + return [ + 'appId' => $this->corpId, + 'nonceStr' => $nonce, + 'timestamp' => $timestamp, + 'url' => $url, + 'signature' => $this->getTicketSignature($this->getTicket(), $nonce, $timestamp, $url), + 'jsApiList' => $jsApiList, + 'debug' => $debug, + 'beta' => $beta, + ]; + } + + public function getTicketSignature(string $ticket, string $nonce, int $timestamp, string $url): string + { + return sha1(sprintf('jsapi_ticket=%s&noncestr=%s×tamp=%s&url=%s', $ticket, $nonce, $timestamp, $url)); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws InvalidArgumentException + * @throws TransportExceptionInterface + * @throws HttpException + * @throws ServerExceptionInterface + */ + public function getTicket(): string + { + $key = $this->getKey(); + $ticket = $this->cache->get($key); + + if (!!$ticket && is_string($ticket)) { + return $ticket; + } + + $response = $this->httpClient->request('GET', '/cgi-bin/get_jsapi_ticket')->toArray(false); + + if (empty($response['ticket'])) { + throw new HttpException('Failed to get jssdk ticket: ' . json_encode($response, JSON_UNESCAPED_UNICODE)); + } + + $this->cache->set($key, $response['ticket'], intval($response['expires_in'])); + + return $response['ticket']; + } + + public function setKey(string $key): static + { + $this->key = $key; + + return $this; + } + + public function getKey(): string + { + return $this->key ?? $this->key = sprintf('open_work.jsapi_ticket.%s', $this->corpId); + } + + /** + * @throws ClientExceptionInterface + * @throws DecodingExceptionInterface + * @throws HttpException + * @throws InvalidArgumentException + * @throws RedirectionExceptionInterface + * @throws ServerExceptionInterface + * @throws TransportExceptionInterface + */ + public function createAgentConfigSignature(int $agentId, string $nonce, int $timestamp, string $url, array $jsApiList = []): array + { + return [ + 'corpid' => $this->corpId, + 'agentid' => $agentId, + 'nonceStr' => $nonce, + 'timestamp' => $timestamp, + 'signature' => $this->getTicketSignature($this->getAgentTicket($agentId), $nonce, $timestamp, $url), + 'jsApiList' => $jsApiList, + ]; + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws InvalidArgumentException + * @throws ClientExceptionInterface + * @throws HttpException + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function getAgentTicket(int $agentId): string + { + $key = $this->getAgentKey($agentId); + $ticket = $this->cache->get($key); + + if (!!$ticket && is_string($ticket)) { + return $ticket; + } + + $response = $this->httpClient->request('GET', '/cgi-bin/ticket/get', ['query' => ['type' => 'agent_config']])->toArray(false); + + if (empty($response['ticket'])) { + throw new HttpException('Failed to get jssdk agentTicket: ' . json_encode($response, JSON_UNESCAPED_UNICODE)); + } + + $this->cache->set($key, $response['ticket'], intval($response['expires_in'])); + + return $response['ticket']; + } + + public function getAgentKey(int $agentId): string + { + return sprintf('%s.%s', $this->getKey(), $agentId); + } +} From 856c7e7534b1f94297eed2357f8ad09ac23bf20b Mon Sep 17 00:00:00 2001 From: wjfz Date: Fri, 9 Sep 2022 06:11:08 +0800 Subject: [PATCH 4/7] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86=E4=BC=81=E4=B8=9A?= =?UTF-8?q?token=E6=9C=89=E5=8F=AF=E8=83=BD=E5=A4=B1=E6=95=88=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/OpenWork/AuthorizerAccessToken.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenWork/AuthorizerAccessToken.php b/src/OpenWork/AuthorizerAccessToken.php index 1b2f66b6d..3abe6fcdd 100644 --- a/src/OpenWork/AuthorizerAccessToken.php +++ b/src/OpenWork/AuthorizerAccessToken.php @@ -100,7 +100,7 @@ public function toQuery(): array public function getKey(): string { - return $this->key ?? $this->key = sprintf('open_work.authorizer.access_token.%s', $this->corpId); + return $this->key ?? $this->key = sprintf('open_work.authorizer.access_token.%s.%s', $this->corpId, $this->permanentCodeOrAccessToken); } public function setKey(string $key): static From 6980f98f78f1d31a7abfbe82dd2553ecf83f733c Mon Sep 17 00:00:00 2001 From: wjfz Date: Wed, 28 Sep 2022 16:55:26 +0800 Subject: [PATCH 5/7] style: fix style --- src/OpenWork/Application.php | 7 +++---- src/OpenWork/AuthorizerAccessToken.php | 21 +++++++++++---------- src/OpenWork/JsApiTicket.php | 23 ++++++++++++----------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/OpenWork/Application.php b/src/OpenWork/Application.php index a34808819..92d9a6fff 100644 --- a/src/OpenWork/Application.php +++ b/src/OpenWork/Application.php @@ -20,7 +20,6 @@ use EasyWeChat\OpenWork\Contracts\SuiteTicket as SuiteTicketInterface; use Overtrue\Socialite\Contracts\ProviderInterface as SocialiteProviderInterface; use Overtrue\Socialite\Providers\OpenWeWork; - use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; @@ -256,7 +255,7 @@ public function getAuthorizerAccessToken( ): AuthorizerAccessToken { $suiteAccessToken = $suiteAccessToken ?? $this->getSuiteAccessToken(); - if (!$this->authorizerAccessToken) { + if (! $this->authorizerAccessToken) { $this->authorizerAccessToken = new AuthorizerAccessToken( corpId: $corpId, permanentCodeOrAccessToken: $permanentCode, @@ -292,8 +291,8 @@ public function getAuthorizerClient(string $corpId, string $permanentCode, ?Acce return (new AccessTokenAwareClient( client: $this->getHttpClient(), accessToken: $this->getAuthorizerAccessToken($corpId, $permanentCode, $suiteAccessToken), - failureJudge: fn (Response $response) => !!($response->toArray()['errcode'] ?? 0), - throw: !!$this->config->get('http.throw', true), + failureJudge: fn (Response $response) => (bool) ($response->toArray()['errcode'] ?? 0), + throw: (bool) $this->config->get('http.throw', true), ))->setPresets($this->config->all()); } diff --git a/src/OpenWork/AuthorizerAccessToken.php b/src/OpenWork/AuthorizerAccessToken.php index 3abe6fcdd..7818600a8 100644 --- a/src/OpenWork/AuthorizerAccessToken.php +++ b/src/OpenWork/AuthorizerAccessToken.php @@ -24,15 +24,16 @@ class AuthorizerAccessToken implements RefreshableAccessToken, Stringable { protected HttpClientInterface $httpClient; + protected CacheInterface $cache; public function __construct( - protected string $corpId, - protected string $permanentCodeOrAccessToken, + protected string $corpId, + protected string $permanentCodeOrAccessToken, protected ?AccessTokenInterface $suiteAccessToken = null, - protected ?string $key = null, - ?CacheInterface $cache = null, - ?HttpClientInterface $httpClient = null, + protected ?string $key = null, + ?CacheInterface $cache = null, + ?HttpClientInterface $httpClient = null, ) { $this->httpClient = $httpClient ?? HttpClient::create(['base_uri' => 'https://qyapi.weixin.qq.com/']); $this->cache = $cache ?? new Psr16Cache(new FilesystemAdapter(namespace: 'easywechat', defaultLifetime: 1500)); @@ -54,13 +55,13 @@ public function getCorpId(): string */ public function getToken(): string { - if (!isset($this->suiteAccessToken)) { + if (! isset($this->suiteAccessToken)) { return $this->permanentCodeOrAccessToken; } $token = $this->cache->get($this->getKey()); - if (!!$token && is_string($token)) { + if ((bool) $token && is_string($token)) { return $token; } @@ -90,7 +91,7 @@ public function __toString() * @throws TransportExceptionInterface * @throws ServerExceptionInterface */ - #[ArrayShape(['access_token' => "string"])] + #[ArrayShape(['access_token' => 'string'])] #[Pure] #[ArrayShape(['access_token' => 'string'])] public function toQuery(): array @@ -121,7 +122,7 @@ public function setKey(string $key): static */ public function refresh(): string { - if (!isset($this->suiteAccessToken)) { + if (! isset($this->suiteAccessToken)) { return ''; } @@ -136,7 +137,7 @@ public function refresh(): string ])->toArray(false); if (empty($response['access_token'])) { - throw new HttpException('Failed to get access_token: ' . json_encode($response, JSON_UNESCAPED_UNICODE)); + throw new HttpException('Failed to get access_token: '.json_encode($response, JSON_UNESCAPED_UNICODE)); } $this->cache->set($this->getKey(), $response['access_token'], intval($response['expires_in'])); diff --git a/src/OpenWork/JsApiTicket.php b/src/OpenWork/JsApiTicket.php index 3d65ed08e..12f82a3bc 100644 --- a/src/OpenWork/JsApiTicket.php +++ b/src/OpenWork/JsApiTicket.php @@ -5,8 +5,11 @@ namespace EasyWeChat\OpenWork; use EasyWeChat\Kernel\Exceptions\HttpException; +use function intval; +use function is_string; use Psr\SimpleCache\CacheInterface; use Psr\SimpleCache\InvalidArgumentException; +use function sprintf; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Psr16Cache; use Symfony\Component\HttpClient\HttpClient; @@ -17,19 +20,16 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; -use function intval; -use function is_string; -use function sprintf; - class JsApiTicket { protected HttpClientInterface $httpClient; + protected CacheInterface $cache; public function __construct( - protected string $corpId, - protected ?string $key = null, - ?CacheInterface $cache = null, + protected string $corpId, + protected ?string $key = null, + ?CacheInterface $cache = null, ?HttpClientInterface $httpClient = null ) { $this->httpClient = $httpClient ?? HttpClient::create(['base_uri' => 'https://qyapi.weixin.qq.com/']); @@ -38,6 +38,7 @@ public function __construct( /** * @return array + * * @throws RedirectionExceptionInterface * @throws DecodingExceptionInterface * @throws ClientExceptionInterface @@ -79,14 +80,14 @@ public function getTicket(): string $key = $this->getKey(); $ticket = $this->cache->get($key); - if (!!$ticket && is_string($ticket)) { + if ((bool) $ticket && is_string($ticket)) { return $ticket; } $response = $this->httpClient->request('GET', '/cgi-bin/get_jsapi_ticket')->toArray(false); if (empty($response['ticket'])) { - throw new HttpException('Failed to get jssdk ticket: ' . json_encode($response, JSON_UNESCAPED_UNICODE)); + throw new HttpException('Failed to get jssdk ticket: '.json_encode($response, JSON_UNESCAPED_UNICODE)); } $this->cache->set($key, $response['ticket'], intval($response['expires_in'])); @@ -141,14 +142,14 @@ public function getAgentTicket(int $agentId): string $key = $this->getAgentKey($agentId); $ticket = $this->cache->get($key); - if (!!$ticket && is_string($ticket)) { + if ((bool) $ticket && is_string($ticket)) { return $ticket; } $response = $this->httpClient->request('GET', '/cgi-bin/ticket/get', ['query' => ['type' => 'agent_config']])->toArray(false); if (empty($response['ticket'])) { - throw new HttpException('Failed to get jssdk agentTicket: ' . json_encode($response, JSON_UNESCAPED_UNICODE)); + throw new HttpException('Failed to get jssdk agentTicket: '.json_encode($response, JSON_UNESCAPED_UNICODE)); } $this->cache->set($key, $response['ticket'], intval($response['expires_in'])); From 56b7387a2a6be7a75f8140b1a1a0bf9b0ca313c1 Mon Sep 17 00:00:00 2001 From: wjfz Date: Sun, 9 Oct 2022 16:47:35 +0800 Subject: [PATCH 6/7] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=B8=A4?= =?UTF-8?q?=E4=B8=AA=E9=80=9A=E7=9F=A5=E5=9B=9E=E8=B0=83=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/OpenWork/Server.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/OpenWork/Server.php b/src/OpenWork/Server.php index 8e05e24e7..ca1a0fb5e 100644 --- a/src/OpenWork/Server.php +++ b/src/OpenWork/Server.php @@ -219,6 +219,24 @@ public function handleShareAgentChanged(callable $handler): static return $this; } + public function handleResetPermanentCode(callable $handler): static + { + $this->with(function (Message $message, Closure $next) use ($handler): mixed { + return $message->InfoType === 'reset_permanent_code' ? $handler($message, $next) : $next($message); + }); + + return $this; + } + + public function handleChangeAppAdmin(callable $handler): static + { + $this->with(function (Message $message, Closure $next) use ($handler): mixed { + return $message->InfoType === 'change_app_admin' ? $handler($message, $next) : $next($message); + }); + + return $this; + } + protected function decryptRequestMessage(): Closure { $query = $this->request->getQueryParams(); From 7b39336b4ce57d05fd62f43a59fcbd413ad3dd31 Mon Sep 17 00:00:00 2001 From: wjfz Date: Tue, 11 Oct 2022 15:30:08 +0800 Subject: [PATCH 7/7] =?UTF-8?q?fix:=20=E7=A7=9F=E6=88=B7token=E4=B8=8D?= =?UTF-8?q?=E5=BA=94=E8=AF=A5=E4=BD=BF=E7=94=A8=E5=8D=95=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/OpenWork/Application.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/OpenWork/Application.php b/src/OpenWork/Application.php index 92d9a6fff..7b863ec12 100644 --- a/src/OpenWork/Application.php +++ b/src/OpenWork/Application.php @@ -255,17 +255,13 @@ public function getAuthorizerAccessToken( ): AuthorizerAccessToken { $suiteAccessToken = $suiteAccessToken ?? $this->getSuiteAccessToken(); - if (! $this->authorizerAccessToken) { - $this->authorizerAccessToken = new AuthorizerAccessToken( - corpId: $corpId, - permanentCodeOrAccessToken: $permanentCode, - suiteAccessToken: $suiteAccessToken, - cache: $this->getCache(), - httpClient: $this->getHttpClient(), - ); - } - - return $this->authorizerAccessToken; + return new AuthorizerAccessToken( + corpId: $corpId, + permanentCodeOrAccessToken: $permanentCode, + suiteAccessToken: $suiteAccessToken, + cache: $this->getCache(), + httpClient: $this->getHttpClient(), + ); } public function createClient(): AccessTokenAwareClient