Skip to content

Commit

Permalink
优化开放平台代理请求
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Mar 17, 2022
1 parent 4476970 commit 3cc7a66
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 25 deletions.
1 change: 0 additions & 1 deletion src/OfficialAccount/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public function getServer(): Server|ServerInterface
{
if (!$this->server) {
$this->server = new Server(
account: $this->getAccount(),
request: $this->getRequest(),
encryptor: $this->getAccount()->getAesKey() ? $this->getEncryptor() : null
);
Expand Down
2 changes: 0 additions & 2 deletions src/OfficialAccount/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use EasyWeChat\Kernel\Traits\DecryptXmlMessage;
use EasyWeChat\Kernel\Traits\InteractWithHandlers;
use EasyWeChat\Kernel\Traits\RespondXmlMessage;
use EasyWeChat\OfficialAccount\Contracts\Account as AccountInterface;
use Nyholm\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -28,7 +27,6 @@ class Server implements ServerInterface
* @throws \Throwable
*/
public function __construct(
protected AccountInterface $account,
?ServerRequestInterface $request = null,
protected ?Encryptor $encryptor = null,
) {
Expand Down
7 changes: 6 additions & 1 deletion src/OpenPlatform/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public function getServer(): Server|ServerInterface
{
if (!$this->server) {
$this->server = new Server(
account: $this->getAccount(),
encryptor: $this->getEncryptor(),
request: $this->getRequest()
);
Expand Down Expand Up @@ -240,7 +239,10 @@ public function getOfficialAccount(AuthorizerAccessToken $authorizerAccessToken,
\array_merge(
[
'app_id' => $authorizerAccessToken->getAppId(),
'token' => $this->config->get('token'),
'aes_key' => $this->config->get('aes_key'),
'logging' => $this->config->get('logging'),
'http' => $this->config->get('http'),
],
$config
)
Expand All @@ -264,7 +266,10 @@ public function getMiniApp(AuthorizerAccessToken $authorizerAccessToken, array $
\array_merge(
[
'app_id' => $authorizerAccessToken->getAppId(),
'token' => $this->config->get('token'),
'aes_key' => $this->config->get('aes_key'),
'logging' => $this->config->get('logging'),
'http' => $this->config->get('http'),
],
$config
)
Expand Down
2 changes: 0 additions & 2 deletions src/OpenPlatform/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use EasyWeChat\Kernel\Traits\DecryptXmlMessage;
use EasyWeChat\Kernel\Traits\InteractWithHandlers;
use EasyWeChat\Kernel\Traits\RespondXmlMessage;
use EasyWeChat\OpenPlatform\Contracts\Account as AccountInterface;
use Nyholm\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -29,7 +28,6 @@ class Server implements ServerInterface
* @throws \Throwable
*/
public function __construct(
protected AccountInterface $account,
protected Encryptor $encryptor,
?ServerRequestInterface $request = null,
) {
Expand Down
1 change: 0 additions & 1 deletion src/OpenWork/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public function getServer(): Server|ServerInterface
{
if (!$this->server) {
$this->server = new Server(
account: $this->getAccount(),
encryptor: $this->getSuiteEncryptor(),
providerEncryptor: $this->getEncryptor(),
request: $this->getRequest(),
Expand Down
2 changes: 0 additions & 2 deletions src/OpenWork/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use EasyWeChat\Kernel\Traits\DecryptXmlMessage;
use EasyWeChat\Kernel\Traits\InteractWithHandlers;
use EasyWeChat\Kernel\Traits\RespondXmlMessage;
use EasyWeChat\OpenWork\Contracts\Account as AccountInterface;
use EasyWeChat\Kernel\Contracts\Server as ServerInterface;
use Nyholm\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -29,7 +28,6 @@ class Server implements ServerInterface
* @throws \Throwable
*/
public function __construct(
protected AccountInterface $account,
protected Encryptor $encryptor,
protected Encryptor $providerEncryptor,
?ServerRequestInterface $request = null,
Expand Down
1 change: 0 additions & 1 deletion src/Work/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public function getServer(): Server|ServerInterface
{
if (!$this->server) {
$this->server = new Server(
account: $this->getAccount(),
request: $this->getRequest(),
encryptor: $this->getEncryptor()
);
Expand Down
2 changes: 0 additions & 2 deletions src/Work/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use EasyWeChat\Kernel\Traits\DecryptXmlMessage;
use EasyWeChat\Kernel\Traits\InteractWithHandlers;
use EasyWeChat\Kernel\Traits\RespondXmlMessage;
use EasyWeChat\Work\Contracts\Account as AccountInterface;
use Nyholm\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -28,7 +27,6 @@ class Server implements ServerInterface
* @throws \Throwable
*/
public function __construct(
protected AccountInterface $account,
protected Encryptor $encryptor,
?ServerRequestInterface $request = null,
) {
Expand Down
2 changes: 1 addition & 1 deletion tests/OfficialAccount/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function test_get_and_set_server()
$this->assertSame($app->getServer(), $app->getServer());

// set
$server = new Server(\Mockery::mock(Account::class), \Mockery::mock(ServerRequestInterface::class));
$server = new Server(\Mockery::mock(ServerRequestInterface::class));
$app->setServer($server);
$this->assertSame($server, $app->getServer());
}
Expand Down
9 changes: 4 additions & 5 deletions tests/OfficialAccount/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace EasyWeChat\Tests\OfficialAccount;

use EasyWeChat\Kernel\Support\Xml;
use EasyWeChat\OfficialAccount\Account;
use EasyWeChat\OfficialAccount\Server;
use EasyWeChat\Tests\TestCase;
use Nyholm\Psr7\ServerRequest;
Expand All @@ -15,7 +14,7 @@ class ServerTest extends TestCase
public function test_it_will_handle_validation_request()
{
$request = (new ServerRequest('GET', 'http://easywechat.com/?echostr=abcdefghijklmn'))->withQueryParams(['echostr' => 'abcdefghijklmn']);
$server = new Server(\Mockery::mock(Account::class), $request);
$server = new Server($request);

$response = $server->serve();

Expand All @@ -33,7 +32,7 @@ public function test_it_will_response_success_without_handlers()
<MsgId>1234567890123456</MsgId>
</xml>';
$request = (new ServerRequest('POST', 'http://easywechat.com/server', [], $body));
$server = new Server(\Mockery::mock(Account::class), $request);
$server = new Server($request);

$response = $server->serve();

Expand All @@ -51,7 +50,7 @@ public function test_it_will_respond_from_message_handlers()
<MsgId>1234567890123456</MsgId>
</xml>';
$request = (new ServerRequest('POST', 'http://easywechat.com/server', [], $body));
$server = new Server(\Mockery::mock(Account::class), $request);
$server = new Server($request);

$response = $server
->addMessageListener(
Expand Down Expand Up @@ -86,7 +85,7 @@ public function test_it_will_respond_from_event_handlers()
<Ticket><![CDATA[TICKET]]></Ticket>
</xml>';
$request = (new ServerRequest('POST', 'http://easywechat.com/server', [], $body));
$server = new Server(\Mockery::mock(Account::class), $request);
$server = new Server($request);

$response = $server
->addMessageListener(
Expand Down
1 change: 0 additions & 1 deletion tests/OpenPlatform/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public function test_get_and_set_server()

// set
$server = new Server(
account: \Mockery::mock(Account::class),
encryptor: \Mockery::mock(Encryptor::class),
request: \Mockery::mock(ServerRequestInterface::class)
);
Expand Down
8 changes: 3 additions & 5 deletions tests/OpenPlatform/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace EasyWeChat\Tests\OpenPlatform;

use EasyWeChat\Kernel\Encryptor;
use EasyWeChat\OpenPlatform\Account;
use EasyWeChat\OpenPlatform\Server;
use EasyWeChat\Tests\TestCase;

Expand All @@ -24,7 +23,7 @@ public function test_it_will_handle_authorized_event()
$encryptor = new Encryptor('wx5823bf96d3bd56c7', 'QDG6eK', 'jWmYm7qr5nMoAUwZRjGtBxmz3KA1tkAj3ykkR6q2B2C');
$request = $this->createEncryptedXmlMessageRequest($body, $encryptor);

$server = new Server(account: \Mockery::mock(Account::class), encryptor: $encryptor, request: $request);
$server = new Server(encryptor: $encryptor, request: $request);

$handleResult = null;
$response = $server->handleAuthorized(function ($message) use (&$handleResult) {
Expand All @@ -47,7 +46,7 @@ public function test_it_will_handle_unauthorized_event()
$encryptor = new Encryptor('wx5823bf96d3bd56c7', 'QDG6eK', 'jWmYm7qr5nMoAUwZRjGtBxmz3KA1tkAj3ykkR6q2B2C');
$request = $this->createEncryptedXmlMessageRequest($body, $encryptor);

$server = new Server(account: \Mockery::mock(Account::class), encryptor: $encryptor, request: $request);
$server = new Server(encryptor: $encryptor, request: $request);

$handleResult = null;
$response = $server->handleUnauthorized(function ($message) use (&$handleResult) {
Expand All @@ -73,7 +72,7 @@ public function test_it_will_handle_authorize_updated_event()
$encryptor = new Encryptor('wx5823bf96d3bd56c7', 'QDG6eK', 'jWmYm7qr5nMoAUwZRjGtBxmz3KA1tkAj3ykkR6q2B2C');
$request = $this->createEncryptedXmlMessageRequest($body, $encryptor);

$server = new Server(account: \Mockery::mock(Account::class), encryptor: $encryptor, request: $request);
$server = new Server(encryptor: $encryptor, request: $request);

$handleResult = null;
$response = $server->handleAuthorizeUpdated(function ($message) use (&$handleResult) {
Expand All @@ -97,7 +96,6 @@ public function test_it_will_handle_verify_ticket_refresh_event()
$request = $this->createEncryptedXmlMessageRequest($body, $encryptor);

$server = new Server(
account: \Mockery::mock(Account::class),
encryptor: $encryptor,
request: $request
);
Expand Down
1 change: 0 additions & 1 deletion tests/Work/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public function test_get_and_set_server()

// set
$server = new Server(
account: \Mockery::mock(Account::class),
encryptor: $app->getEncryptor(),
request: \Mockery::mock(ServerRequestInterface::class)
);
Expand Down

1 comment on commit 3cc7a66

@vercel
Copy link

@vercel vercel bot commented on 3cc7a66 Mar 17, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.