From 845c9a2c09d9e6dc0a6dc2a685e681ae1e3c0d85 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 19 Jul 2023 16:25:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4app=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/pay/WeChatPayService.php | 32 +++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/app/common/service/pay/WeChatPayService.php b/app/common/service/pay/WeChatPayService.php index cd1f72e13..9896e86f9 100755 --- a/app/common/service/pay/WeChatPayService.php +++ b/app/common/service/pay/WeChatPayService.php @@ -215,7 +215,7 @@ class WeChatPayService extends BasePayService ]); $result = $response->toArray(false); $this->checkResultFail($result); - return $result['prepay_id']; + return $this->configForPayment($result['prepay_id'], $appId); } @@ -390,8 +390,36 @@ class WeChatPayService extends BasePayService return $server->serve(); } + public function configForPayment($prepayId, $appId) + { + $config = [ + 'appId' => $appId, + 'timeStamp' => strval(time()), + 'nonceStr' => uniqid(), + 'package' => "prepay_id=$prepayId", + 'signType' => 'RSA', + ]; + $message = $config['appId'] . "\n" . + $config['timeStamp'] . "\n" . + $config['nonceStr'] . "\n" . + $config['package'] . "\n"; + openssl_sign($message, $raw_sign, $this->getPrivateKey(), 'sha256WithRSAEncryption'); + $sign = base64_encode($raw_sign); + $config['paySign'] = $sign; + $config['timestamp'] = $config['timeStamp']; + unset($config['timeStamp']); + return $config; + } - + protected function getPrivateKey() + { + if (!file_exists($this->config['private_key'])) { + throw new \InvalidArgumentException( + "SSL certificate not found: {$this->config['private_key']}" + ); + } + return openssl_pkey_get_private(file_get_contents($this->config['private_key'])); + } } \ No newline at end of file