“未找到与有效载荷的预期签名匹配的签名”。$预期签名未包含在$签名中

时间:2019-08-22 09:59:59

标签: php stripe-payments

发生错误的代码。 webhook.php

\Stripe\Stripe::setApiKey('xxxx');
$endpoint_secret = 'whsec_xxxx';
$payload = @file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
$event = null;
try {
  $event = \Stripe\Webhook::constructEvent(
      $payload, $sig_header, $endpoint_secret
  );
} catch(\UnexpectedValueException $e) {
    http_response_code(400);
    exit();
} catch(\Stripe\Error\SignatureVerification $e) {
    //An error is caught here
}

错误消息

  

未找到与有效负载的预期签名匹配的签名

stripe-php/lib/WebhookSignature.php

$signatureFound = false;
foreach ($signatures as $signature) {
    if (Util\Util::secureCompare($expectedSignature, $signature)) {
        $signatureFound = true;
        break;
    }
}
if (!$signatureFound) {
    throw new Error\SignatureVerification(
        "No signatures found matching the expected signature for payload",
        $header,
        $payload
    );

调试结果 $期望签名不包含在$签名中

'-----signatures-----'
array (
  0 => '171abxxxx',
)
'-----expectedSignature-----'
'd1a55xxxx'

0 个答案:

没有答案