mirror of
https://gitee.com/zoujingli/WeChatDeveloper.git
synced 2026-09-04 23:12:09 +08:00
- 将 src/Tests 迁移到根目录 tests,并同步 composer autoload-dev 与 phpunit 配置。 - 补充 raw/download/upload、微信支付签名下载、XML 嵌套重复节点和消息加解密异常用例。 - 保持测试命名空间 We\Tests,统一通过 tests/bootstrap.php 引导 Composer 自动加载。
42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* 微信支付 APIv3 通知 resource 解密测试。
|
|
*/
|
|
|
|
namespace We\Tests;
|
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use PHPUnit\Framework\TestCase;
|
|
use We\Support\PaymentCrypto;
|
|
|
|
/**
|
|
* 微信支付 APIv3 通知 resource 解密测试用例。
|
|
*/
|
|
#[CoversClass(PaymentCrypto::class)]
|
|
final class PaymentCryptoTest extends TestCase
|
|
{
|
|
/**
|
|
* 测试微信支付回调资源解密。
|
|
*/
|
|
public function testDecryptResource(): void
|
|
{
|
|
$key = str_repeat('k', 32);
|
|
$nonce = '123456789012';
|
|
$aad = 'transaction';
|
|
$plain = '{"out_trade_no":"T202605010001","trade_state":"SUCCESS"}';
|
|
$cipher = openssl_encrypt($plain, 'aes-256-gcm', $key, OPENSSL_RAW_DATA, $nonce, $tag, $aad);
|
|
|
|
$data = PaymentCrypto::decryptResource($key, [
|
|
'ciphertext' => base64_encode($cipher . $tag),
|
|
'nonce' => $nonce,
|
|
'associated_data' => $aad,
|
|
]);
|
|
|
|
$this->assertSame('T202605010001', $data['out_trade_no']);
|
|
$this->assertSame('SUCCESS', $data['trade_state']);
|
|
}
|
|
}
|