From 550c2def401a804fba932cd79790911c65bddd42 Mon Sep 17 00:00:00 2001 From: Anyon Date: Fri, 12 Dec 2025 09:33:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E5=8F=8A=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WePayV3/Contracts/BasicWePay.php | 10 +++++++++- WePayV3/Order.php | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/WePayV3/Contracts/BasicWePay.php b/WePayV3/Contracts/BasicWePay.php index 7ad6d7b..8f628f3 100644 --- a/WePayV3/Contracts/BasicWePay.php +++ b/WePayV3/Contracts/BasicWePay.php @@ -333,7 +333,15 @@ abstract class BasicWePay protected function signBuild($data) { $pkeyid = openssl_pkey_get_private($this->config['cert_private']); - openssl_sign($data, $signature, $pkeyid, 'sha256WithRSAEncryption'); + if ($pkeyid === false) { + throw new InvalidArgumentException("Invalid private key -- [cert_private]"); + } + $signature = ''; + if (!openssl_sign($data, $signature, $pkeyid, 'sha256WithRSAEncryption')) { + openssl_free_key($pkeyid); + throw new InvalidArgumentException("Failed to sign data with private key"); + } + openssl_free_key($pkeyid); return base64_encode($signature); } diff --git a/WePayV3/Order.php b/WePayV3/Order.php index c4866dc..2b18d25 100644 --- a/WePayV3/Order.php +++ b/WePayV3/Order.php @@ -52,6 +52,13 @@ class Order extends BasicWePay if (empty($types[$type])) { throw new InvalidArgumentException("Payment {$type} not defined."); } else { + // 自动填充 mchid 和 appid(如果未提供) + if (empty($data['mchid']) && !empty($this->config['mch_id'])) { + $data['mchid'] = $this->config['mch_id']; + } + if (empty($data['appid']) && !empty($this->config['appid'])) { + $data['appid'] = $this->config['appid']; + } // 创建预支付码 $result = $this->doRequest('POST', $types[$type], json_encode($data, JSON_UNESCAPED_UNICODE), true); if (empty($result['h5_url']) && empty($result['code_url']) && empty($result['prepay_id'])) {