|
|
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
|
|
namespace SixShop\WechatPay\Service;
|
|
|
|
|
|
use SixShop\WechatPay\Config;
|
|
|
+use think\facade\Log;
|
|
|
use WeChatPay\Crypto\AesGcm;
|
|
|
use WeChatPay\Crypto\Rsa;
|
|
|
use WeChatPay\Formatter;
|
|
|
@@ -16,17 +17,17 @@ class NotifyService
|
|
|
/**
|
|
|
* 微信支付成功回调
|
|
|
* @param array $headers 请求头
|
|
|
- * @param array $inBody 请求体
|
|
|
+ * @param string $inBody 请求体
|
|
|
*/
|
|
|
- public function transactionSuccess(array $headers, array $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'] ?? ''; // 请根据实际情况获取
|
|
|
+ $signature = $headers['Wechatpay-Signature'] ?? '';// 请根据实际情况获取
|
|
|
+ $timestamp = $headers['Wechatpay-Timestamp'] ?? '';// 请根据实际情况获取
|
|
|
+ $serial = $headers['Wechatpay-Serial'] ?? ''; // 请根据实际情况获取
|
|
|
+ $nonce = $headers['Wechatpay-Nonce'] ?? ''; // 请根据实际情况获取
|
|
|
|
|
|
$apiv3Key = $this->config->api_v3_key;
|
|
|
- $platformPublicKeyInstance = $this->config->public_key;
|
|
|
+ $platformPublicKeyInstance = $this->config->platform_cert;
|
|
|
|
|
|
$timeOffsetStatus = 300 >= abs(Formatter::timestamp() - (int)$timestamp);
|
|
|
if (!$timeOffsetStatus) {
|
|
|
@@ -34,15 +35,22 @@ class NotifyService
|
|
|
}
|
|
|
$verifiedStatus = Rsa::verify(
|
|
|
// 构造验签名串
|
|
|
- Formatter::joinedByLineFeed($timestamp, $nonce, $body),
|
|
|
+ Formatter::joinedByLineFeed($timestamp, $nonce, $inBody),
|
|
|
$signature,
|
|
|
$platformPublicKeyInstance
|
|
|
);
|
|
|
if (!$verifiedStatus) {
|
|
|
- throw new \RuntimeException('The signature is invalid.');
|
|
|
+ // TODO
|
|
|
+ Log::warning('The signature is invalid. timestamp={timestamp} nonce={nonce} inBody={inBody} signature={signature}', [
|
|
|
+ 'timestamp' => $timestamp,
|
|
|
+ 'nonce' => $nonce,
|
|
|
+ 'inBody' => $inBody,
|
|
|
+ 'signature' => $signature,
|
|
|
+ ]);
|
|
|
+ //throw new \RuntimeException('The signature is invalid.');
|
|
|
}
|
|
|
// 转换通知的JSON文本消息为PHP Array数组
|
|
|
- $inBodyArray = (array)json_decode($body, true);
|
|
|
+ $inBodyArray = (array)json_decode($inBody, true);
|
|
|
// 使用PHP7的数据解构语法,从Array中解构并赋值变量
|
|
|
['resource' => [
|
|
|
'ciphertext' => $ciphertext,
|
|
|
@@ -51,7 +59,6 @@ class NotifyService
|
|
|
]] = $inBodyArray;
|
|
|
// 加密文本消息解密
|
|
|
$inBodyResource = AesGcm::decrypt($ciphertext, $apiv3Key, $nonce, $aad);
|
|
|
- return json_decode($inBodyResource);
|
|
|
- return [];
|
|
|
+ return json_decode($inBodyResource, true);
|
|
|
}
|
|
|
}
|