1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$raw = '
{
"id": "c4d4f8ec-8b57-5880-b86e-c007bb148124",
"create_time": "2026-02-24T23:51:27+08:00",
"resource_type": "encrypt-resource",
"event_type": "TRANSACTION.SUCCESS",
"summary": "支付成功",
"resource":
{
"original_type": "transaction",
"algorithm": "AEAD_AES_256_GCM",
"ciphertext": "微信支付密文",
"associated_data": "transaction",
"nonce": "UD01wII7yRkt"
}
}';

$data = json_decode($raw, true);

$ciphertext = $data['resource']['ciphertext'];
$key = config('wechat_pay.secret_key'); // V3密钥
$nonce = $data['resource']['nonce'];
$associatedData = $data['resource']['associated_data'] ?? '';

// 直接使用AesGcm解密
$plaintext = \EasyWeChat\Kernel\Support\AesGcm::decrypt($ciphertext, $key, $nonce, $associatedData);
$decryptedData = json_decode($plaintext, true);
dd($decryptedData);

// 使用解密后的数据
$outTradeNo = $decryptedData['out_trade_no'];
$transactionId = $decryptedData['transaction_id'];
// ... 其他业务逻辑