Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
241 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ | |
|
||
namespace Yansongda\Pay\Parser; | ||
|
||
class JsonParser extends ArrayPacker | ||
class JsonParser extends ArrayParser | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yansongda\Pay\Parser; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Yansongda\Pay\Contract\ParserInterface; | ||
|
||
class NoHttpRequestParser implements ParserInterface | ||
{ | ||
public function parse(?ResponseInterface $response): ?ResponseInterface | ||
{ | ||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yansongda\Pay\Plugin\Alipay; | ||
|
||
use Closure; | ||
use Yansongda\Pay\Contract\PluginInterface; | ||
use Yansongda\Pay\Exception\InvalidResponseException; | ||
use Yansongda\Pay\Parser\NoHttpRequestParser; | ||
use Yansongda\Pay\Rocket; | ||
use Yansongda\Supports\Collection; | ||
|
||
class CallbackPlugin implements PluginInterface | ||
{ | ||
/** | ||
* @throws \Yansongda\Pay\Exception\ContainerDependencyException | ||
* @throws \Yansongda\Pay\Exception\ContainerException | ||
* @throws \Yansongda\Pay\Exception\InvalidConfigException | ||
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException | ||
* @throws \Yansongda\Pay\Exception\InvalidResponseException | ||
*/ | ||
public function assembly(Rocket $rocket, Closure $next): Rocket | ||
{ | ||
$this->filterPayload($rocket); | ||
|
||
if (!($rocket->getParams()['sign'] ?? false)) { | ||
throw new InvalidResponseException(InvalidResponseException::INVALID_RESPONSE_SIGN, '', $rocket->getParams()); | ||
} | ||
|
||
if (!verify_alipay_response( | ||
$rocket->getParams(), | ||
$this->getSignContent($rocket->getPayload()), | ||
base64_decode($rocket->getParams()['sign'])) | ||
) { | ||
throw new InvalidResponseException(InvalidResponseException::INVALID_RESPONSE_SIGN, '', $rocket->getParams()); | ||
} | ||
|
||
$rocket->setDirection(NoHttpRequestParser::class) | ||
->setDestination($rocket->getPayload()); | ||
|
||
return $next($rocket); | ||
} | ||
|
||
protected function filterPayload(Rocket $rocket): void | ||
{ | ||
$payload = (new Collection($rocket->getParams()))->filter(function ($v, $k) { | ||
return '' !== $v && !is_null($v) && 'sign' != $k && 'sign_type' != $k; | ||
}); | ||
|
||
$rocket->setPayload($payload); | ||
} | ||
|
||
protected function getSignContent(Collection $payload): string | ||
{ | ||
return urldecode($payload->sortKeys()->toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.