This commit is contained in:
xl
2023-11-13 22:59:34 +08:00
parent ac4c6c1e27
commit 0eb8aab1d2
3 changed files with 4 additions and 23 deletions
-20
View File
@@ -1,20 +0,0 @@
<?php
namespace wchat\wx\V3;
class Config
{
protected string $appId = '';
protected string $appSecret = '';
protected string $mchId = '';
protected string $mchKey = '';
protected string $secret = '';
protected string $mchCert = '';
protected string $SerialNumber = '';
protected string $notifyUrl = '';
}
+1 -1
View File
@@ -147,7 +147,7 @@ class WxV3PaymentNotify extends SmallProgram
*/
public function decode($ciphertext, $nonce, $associated_data): bool
{
$data = $this->decrypt($ciphertext, $nonce, $associated_data);
$data = $this->decrypt($ciphertext, $this->getConfig()->getMchKey(), $nonce, $associated_data);
$this->notifyModel = new NotifyModel();
$this->notifyModel->amount = $data['amount'];
$this->notifyModel->payer = $data['payer'];
+3 -2
View File
@@ -135,11 +135,12 @@ trait WxV3PaymentTait
/**
* @param string $ciphertext
* @param string $v3Key
* @param string $iv
* @param string $aad
* @return array
*/
public function decrypt(string $ciphertext, string $iv = '', string $aad = ''): array
public function decrypt(string $ciphertext, string $v3Key, string $iv = '', string $aad = ''): array
{
$ciphertext = base64_decode($ciphertext);
$authTag = substr($ciphertext, $tailLength = 0 - BLOCK_SIZE);
@@ -149,7 +150,7 @@ trait WxV3PaymentTait
if ($tagLength > BLOCK_SIZE || ($tagLength < 12 && $tagLength !== 8 && $tagLength !== 4)) {
throw new \RuntimeException('The inputs `$ciphertext` incomplete, the bytes length must be one of 16, 15, 14, 13, 12, 8 or 4.');
}
$plaintext = openssl_decrypt(substr($ciphertext, 0, $tailLength), ALGO_AES_256_GCM, $this->getConfig()->getKey(), OPENSSL_RAW_DATA, $iv, $authTag, $aad);
$plaintext = openssl_decrypt(substr($ciphertext, 0, $tailLength), ALGO_AES_256_GCM, $v3Key, OPENSSL_RAW_DATA, $iv, $authTag, $aad);
if (false === $plaintext) {
throw new \UnexpectedValueException('Decrypting the input $ciphertext failed, please checking your $key and $iv whether or nor correct.');
}