2023-12-22 14:59:06 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Yansongda\Pay\Tests\Plugin\Alipay;
|
|
|
|
|
|
|
|
use Yansongda\Pay\Exception\Exception;
|
2024-01-01 12:17:20 +08:00
|
|
|
use Yansongda\Pay\Exception\InvalidParamsException;
|
2023-12-22 17:09:55 +08:00
|
|
|
use Yansongda\Pay\Exception\InvalidSignException;
|
2023-12-22 14:59:06 +08:00
|
|
|
use Yansongda\Pay\Plugin\Alipay\VerifySignaturePlugin;
|
|
|
|
use Yansongda\Pay\Rocket;
|
|
|
|
use Yansongda\Pay\Tests\TestCase;
|
|
|
|
use Yansongda\Supports\Collection;
|
|
|
|
|
|
|
|
class VerifySignaturePluginTest extends TestCase
|
|
|
|
{
|
|
|
|
protected VerifySignaturePlugin $plugin;
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->plugin = new VerifySignaturePlugin();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSignNormal()
|
|
|
|
{
|
|
|
|
$destination = [
|
|
|
|
"_sign" => 'eITxP5fZiJPB2+vZb90IRkv2iARxeNx/6Omxk7FStqflhG5lMoCvGjo2FZ6Szo1bGBMBReazZuqLaqsgomWAUO9onMVurB3enLbRvwUlpE7XEZaxk/sJYjgc2Y7pIAenvnLL9PEAiXmvUvuinUlvS9J2r1XysC0p/2wu7kEJ/GgZpFDIIYY9mdM6U1rGbi+RvirQXtQHmaEuuJWLA75NR1bvfG3L8znzW9xz1kOQqOWsQmD/bF1CDWbozNLwLCUmClRJz0Fj4mUYRF0zbW2VP8ZgHu1YvVKJ2+dWC9b+0o94URk7psIpc5NjiOM9Jsn6aoC2CfrJ/sqFMRCkYWzw6A==',
|
|
|
|
"code" => "10000",
|
|
|
|
"msg" => "Success",
|
|
|
|
"order_id" => "20231220110070000002150000657610",
|
|
|
|
"out_biz_no" => "2023122022560000",
|
|
|
|
"pay_date" => "2023-12-20 22:56:33",
|
|
|
|
"pay_fund_order_id" => "20231220110070001502150000660902",
|
|
|
|
"status" => "SUCCESS",
|
|
|
|
"trans_amount" => "0.01",
|
|
|
|
];
|
|
|
|
|
|
|
|
$rocket = (new Rocket())
|
|
|
|
->setDestination(new Collection($destination));
|
|
|
|
|
|
|
|
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
|
|
|
|
|
|
|
self::assertSame($rocket, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSignWrong()
|
|
|
|
{
|
|
|
|
$destination = [
|
|
|
|
"_sign" => 'AeITxP5fZiJPB2+vZb90IRkv2iARxeNx/6Omxk7FStqflhG5lMoCvGjo2FZ6Szo1bGBMBReazZuqLaqsgomWAUO9onMVurB3enLbRvwUlpE7XEZaxk/sJYjgc2Y7pIAenvnLL9PEAiXmvUvuinUlvS9J2r1XysC0p/2wu7kEJ/GgZpFDIIYY9mdM6U1rGbi+RvirQXtQHmaEuuJWLA75NR1bvfG3L8znzW9xz1kOQqOWsQmD/bF1CDWbozNLwLCUmClRJz0Fj4mUYRF0zbW2VP8ZgHu1YvVKJ2+dWC9b+0o94URk7psIpc5NjiOM9Jsn6aoC2CfrJ/sqFMRCkYWzw6A==',
|
|
|
|
"code" => "10000",
|
|
|
|
"msg" => "Success",
|
|
|
|
"order_id" => "20231220110070000002150000657610",
|
|
|
|
"out_biz_no" => "2023122022560000",
|
|
|
|
"pay_date" => "2023-12-20 22:56:33",
|
|
|
|
"pay_fund_order_id" => "20231220110070001502150000660902",
|
|
|
|
"status" => "SUCCESS",
|
|
|
|
"trans_amount" => "0.01",
|
|
|
|
];
|
|
|
|
|
|
|
|
$rocket = (new Rocket())
|
|
|
|
->setDestination(new Collection($destination));
|
|
|
|
|
2023-12-22 17:09:55 +08:00
|
|
|
self::expectException(InvalidSignException::class);
|
|
|
|
self::expectExceptionCode(Exception::SIGN_ERROR);
|
2023-12-22 14:59:06 +08:00
|
|
|
|
|
|
|
$this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
|
|
|
}
|
2024-01-01 12:17:20 +08:00
|
|
|
|
|
|
|
public function testSignContentWrong()
|
|
|
|
{
|
|
|
|
$rocket = new Rocket();
|
|
|
|
|
|
|
|
self::expectException(InvalidParamsException::class);
|
|
|
|
self::expectExceptionCode(Exception::RESPONSE_EMPTY);
|
|
|
|
|
|
|
|
$this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
|
|
|
}
|
2023-12-22 14:59:06 +08:00
|
|
|
}
|