mirror of
https://gitee.com/yansongda/pay.git
synced 2024-11-29 18:58:38 +08:00
parent
1ad9a4c09a
commit
ac29721c5c
@ -2,7 +2,7 @@
|
||||
|
||||
### fixed
|
||||
|
||||
- fix: 提前读取响应数据造成验签错误的问题(#633)
|
||||
- fix: 提前读取响应数据造成数据错误的问题(#633, #634)
|
||||
|
||||
## v3.1.7
|
||||
|
||||
|
@ -20,7 +20,7 @@ class ArrayParser implements ParserInterface
|
||||
throw new InvalidResponseException(Exception::RESPONSE_NONE);
|
||||
}
|
||||
|
||||
$contents = $response->getBody()->getContents();
|
||||
$contents = (string) $response->getBody();
|
||||
|
||||
$result = json_decode($contents, true);
|
||||
|
||||
|
@ -33,7 +33,7 @@ class CallbackPlugin implements PluginInterface
|
||||
/* @phpstan-ignore-next-line */
|
||||
verify_wechat_sign($rocket->getDestinationOrigin(), $rocket->getParams());
|
||||
|
||||
$body = json_decode($rocket->getDestination()->getBody()->getContents(), true);
|
||||
$body = json_decode((string) $rocket->getDestination()->getBody(), true);
|
||||
|
||||
$rocket->setDirection(NoHttpRequestParser::class)->setPayload(new Collection($body));
|
||||
|
||||
@ -57,7 +57,7 @@ class CallbackPlugin implements PluginInterface
|
||||
throw new InvalidParamsException(Exception::REQUEST_NULL_ERROR);
|
||||
}
|
||||
|
||||
$contents = $request->getBody()->getContents();
|
||||
$contents = (string) $request->getBody();
|
||||
|
||||
$rocket->setDestination($request->withBody(Utils::streamFor($contents)))
|
||||
->setDestinationOrigin($request->withBody(Utils::streamFor($contents)))
|
||||
|
@ -100,7 +100,7 @@ abstract class AbstractProvider implements ProviderInterface
|
||||
try {
|
||||
$response = $http->sendRequest($rocket->getRadar());
|
||||
|
||||
$contents = $response->getBody()->getContents();
|
||||
$contents = (string) $response->getBody();
|
||||
|
||||
$rocket->setDestination($response->withBody(Utils::streamFor($contents)))
|
||||
->setDestinationOrigin($response->withBody(Utils::streamFor($contents)));
|
||||
|
@ -21,7 +21,7 @@ class Request extends \GuzzleHttp\Psr7\Request implements JsonSerializableInterf
|
||||
'url' => $this->getUri()->__toString(),
|
||||
'method' => $this->getMethod(),
|
||||
'headers' => $this->getHeaders(),
|
||||
'body' => $this->getBody()->getContents(),
|
||||
'body' => (string) $this->getBody(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -38,4 +38,16 @@ class ArrayParserTest extends TestCase
|
||||
|
||||
self::assertEquals(['name' => 'yansongda'], $result);
|
||||
}
|
||||
|
||||
public function testReadContents()
|
||||
{
|
||||
$response = new Response(200, [], '{"name": "yansongda"}');
|
||||
|
||||
$response->getBody()->read(2);
|
||||
|
||||
$parser = new ArrayParser();
|
||||
$result = $parser->parse($response);
|
||||
|
||||
self::assertEquals(['name' => 'yansongda'], $result);
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,26 @@ class AbstractProviderTest extends TestCase
|
||||
$provider = new FooProviderStub();
|
||||
$result = $provider->ignite($rocket);
|
||||
|
||||
self::assertEquals('yansongda/pay', $result->getDestination()->getBody()->getContents());
|
||||
self::assertEquals('yansongda/pay', (string) $result->getDestination()->getBody());
|
||||
}
|
||||
|
||||
public function testIgnitePreRead()
|
||||
{
|
||||
$response = new Response(200, [], 'yansongda/pay');
|
||||
$response->getBody()->read(1);
|
||||
|
||||
$rocket = new Rocket();
|
||||
$rocket->setRadar(new Request('get', ''));
|
||||
|
||||
$http = Mockery::mock(Client::class);
|
||||
$http->shouldReceive('sendRequest')->andReturn($response);
|
||||
|
||||
Pay::set(HttpClientInterface::class, $http);
|
||||
|
||||
$provider = new FooProviderStub();
|
||||
$result = $provider->ignite($rocket);
|
||||
|
||||
self::assertEquals('yansongda/pay', (string) $result->getDestination()->getBody());
|
||||
}
|
||||
|
||||
public function testIgniteWrongHttpClient()
|
||||
@ -117,6 +136,11 @@ class FooProviderStub extends AbstractProvider
|
||||
|
||||
public function success(): ResponseInterface
|
||||
{
|
||||
return new Response(
|
||||
200,
|
||||
['Content-Type' => 'application/json'],
|
||||
json_encode(['code' => 'SUCCESS', 'message' => '成功']),
|
||||
);
|
||||
}
|
||||
|
||||
public function mergeCommonPlugins(array $plugins): array
|
||||
|
Loading…
Reference in New Issue
Block a user