This commit is contained in:
Hankin 2026-04-24 17:30:02 +08:00
parent 86d1d7213f
commit 2296e07192
2 changed files with 6 additions and 5 deletions

View File

@ -56,7 +56,7 @@ class WechatPayController extends Controller
'wechatpay-serial' => $_SERVER['HTTP_WECHATPAY_SERIAL'] ?? '', 'wechatpay-serial' => $_SERVER['HTTP_WECHATPAY_SERIAL'] ?? '',
]; ];
$body = $request->all(); $body = $request->all();
$body = json_encode($body, JSON_UNESCAPED_UNICODE); // $body = json_encode($body, JSON_UNESCAPED_UNICODE);
Log::info("请求头", ["headers" => $headers]); Log::info("请求头", ["headers" => $headers]);
Log::info("请求体", ["body" => $body]); Log::info("请求体", ["body" => $body]);
$res = WechatPayService::mchTransferCallback($headers, $body); $res = WechatPayService::mchTransferCallback($headers, $body);

View File

@ -130,13 +130,14 @@ class WechatPayService
/** /**
* 验证签名RSA-SHA256 * 验证签名RSA-SHA256
*/ */
private function verifySignature(array $headers, string $body): bool private function verifySignature(array $headers, array $body): bool
{ {
// 检查必要头是否存在 // 检查必要头是否存在
if ( if (
empty($headers['timestamp']) || empty($headers['nonce']) || empty($headers['timestamp']) || empty($headers['nonce']) ||
empty($headers['signature']) || empty($headers['serial']) empty($headers['signature']) || empty($headers['serial'])
) { ) {
Log::error('请求头参数确实');
return false; return false;
} }
@ -149,7 +150,7 @@ class WechatPayService
// 构造验签名串timestamp + \n + nonce + \n + body + \n // 构造验签名串timestamp + \n + nonce + \n + body + \n
$signStr = $headers['timestamp'] . "\n" $signStr = $headers['timestamp'] . "\n"
. $headers['nonce'] . "\n" . $headers['nonce'] . "\n"
. $body . "\n"; . json_encode($body) . "\n";
// 加载微信支付平台公钥 // 加载微信支付平台公钥
$publicKey = openssl_pkey_get_public('file://' . config("wechatpay.payment.platform_cert_path")); $publicKey = openssl_pkey_get_public('file://' . config("wechatpay.payment.platform_cert_path"));
@ -170,9 +171,9 @@ class WechatPayService
/** /**
* AES-256-GCM 解密回调数据 * AES-256-GCM 解密回调数据
*/ */
private function decryptNotifyData(string $rawBody): ?array private function decryptNotifyData(array $data): ?array
{ {
$data = json_decode($rawBody, true); // $data = json_decode($rawBody, true);
if (!isset($data['resource'])) { if (!isset($data['resource'])) {
return null; return null;