Skip to content

Commit

Permalink
optimize: 优化微信 ResponsePlugin 插件去除不必要的返回参数 (#996)
Browse files Browse the repository at this point in the history
  • Loading branch information
yansongda committed Jun 10, 2024
1 parent 66942f1 commit 3683c69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## TBD - v3.7.5

### optimized

- optimize: 优化微信 `ResponsePlugin` 插件去除不必要的返回参数(#996)

### deprecated

- deprecate: 微信 `StartPlugin` 改为使用 `yansongda/artful` 中的插件(#993)
Expand Down
8 changes: 2 additions & 6 deletions src/Plugin/Wechat/ResponsePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
namespace Yansongda\Pay\Plugin\Wechat;

use Closure;
use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\ResponseInterface;
use Yansongda\Artful\Contract\PluginInterface;
use Yansongda\Artful\Exception\InvalidResponseException;
use Yansongda\Artful\Logger;
use Yansongda\Artful\Rocket;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Supports\Collection;

class ResponsePlugin implements PluginInterface
{
Expand All @@ -26,7 +24,7 @@ public function assembly(Rocket $rocket, Closure $next): Rocket

Logger::debug('[Wechat][ResponsePlugin] 插件开始装载', ['rocket' => $rocket]);

$rocket->setDestination($this->validateResponse($rocket));
$this->validateResponse($rocket);

Logger::info('[Wechat][ResponsePlugin] 插件装载完毕', ['rocket' => $rocket]);

Expand All @@ -36,15 +34,13 @@ public function assembly(Rocket $rocket, Closure $next): Rocket
/**
* @throws InvalidResponseException
*/
protected function validateResponse(Rocket $rocket): null|Collection|MessageInterface
protected function validateResponse(Rocket $rocket): void
{
$response = $rocket->getDestinationOrigin();

if ($response instanceof ResponseInterface
&& ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300)) {
throw new InvalidResponseException(Exception::RESPONSE_CODE_WRONG, '微信返回状态码异常,请检查参数是否错误', $rocket->getDestination());
}

return $rocket->getDestination();
}
}

0 comments on commit 3683c69

Please sign in to comment.