|
|
@@ -1,5 +1,6 @@
|
|
|
<?php
|
|
|
declare(strict_types=1);
|
|
|
+
|
|
|
namespace SixShop\WechatPay\Service;
|
|
|
|
|
|
use SixShop\WechatPay\Config;
|
|
|
@@ -19,28 +20,26 @@ class NotifyService
|
|
|
* @param array $headers 请求头
|
|
|
* @param string $inBody 请求体
|
|
|
*/
|
|
|
- public function transactionSuccess(array $headers, string $inBody):array
|
|
|
+ public function transactionSuccess(array $headers, string $inBody): array
|
|
|
{
|
|
|
$signature = $headers['Wechatpay-Signature'] ?? '';// 请根据实际情况获取
|
|
|
$timestamp = $headers['Wechatpay-Timestamp'] ?? '';// 请根据实际情况获取
|
|
|
$serial = $headers['Wechatpay-Serial'] ?? ''; // 请根据实际情况获取
|
|
|
$nonce = $headers['Wechatpay-Nonce'] ?? ''; // 请根据实际情况获取
|
|
|
-
|
|
|
+
|
|
|
$apiv3Key = $this->config->api_v3_key;
|
|
|
- $platformPublicKeyInstance = str_starts_with($serial,'PUB_KEY_ID_')?$this->config->public_key:$this->config->platform_cert;
|
|
|
+ $platformPublicKeyInstance = str_starts_with($serial, 'PUB_KEY_ID_') ? $this->config->public_key : $this->config->platform_cert;
|
|
|
|
|
|
$timeOffsetStatus = 300 >= abs(Formatter::timestamp() - (int)$timestamp);
|
|
|
if (!$timeOffsetStatus) {
|
|
|
throw new \RuntimeException('The timestamp is out of range.');
|
|
|
}
|
|
|
$verifiedStatus = Rsa::verify(
|
|
|
- // 构造验签名串
|
|
|
Formatter::joinedByLineFeed($timestamp, $nonce, $inBody),
|
|
|
$signature,
|
|
|
$platformPublicKeyInstance
|
|
|
);
|
|
|
if (!$verifiedStatus) {
|
|
|
- // TODO
|
|
|
Log::warning('The signature is invalid. timestamp={timestamp} nonce={nonce} inBody={inBody} signature={signature} serial={serial}', [
|
|
|
'timestamp' => $timestamp,
|
|
|
'nonce' => $nonce,
|
|
|
@@ -48,7 +47,7 @@ class NotifyService
|
|
|
'signature' => $signature,
|
|
|
'serial' => $serial,
|
|
|
]);
|
|
|
- //throw new \RuntimeException('The signature is invalid.');
|
|
|
+ throw new \RuntimeException('The signature is invalid.');
|
|
|
}
|
|
|
// 转换通知的JSON文本消息为PHP Array数组
|
|
|
$inBodyArray = (array)json_decode($inBody, true);
|