php - 为什么Stripe的webhooks不需要验证签名?

标签 php stripe-payments

文档 ( https://stripe.com/docs/webhooks ) 和 SDK(stripe-php) 都没有使用任何签名方法。所以我怀疑,如果有人冒充官方 webhook 发件人怎么办?

在SDK中,只有成功检索事件id才算一个好的webhook,我认为这太冒险了,不是吗?

最佳答案

Stripe 确实为 Web hook 提供了签名。看看这里:https://stripe.com/docs/webhooks#signatures

您还可以看看这篇文章:https://www.truespotmedia.com/testing-webhooks-in-stripe-with-php/

这里是一些示例代码:

// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("your secret api key");

// You can find your endpoint's secret in your webhook settings
$endpoint_secret = "whsec_...";

$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) {
  // Invalid payload
  http_response_code(400); // PHP 5.4 or greater
  exit();
} catch(\Stripe\Error\SignatureVerification $e) {
  // Invalid signature
  http_response_code(400); // PHP 5.4 or greater
  exit();
}

// Do something with $event

http_response_code(200); // PHP 5.4 or greater

关于php - 为什么Stripe的webhooks不需要验证签名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39210037/

相关文章:

php - 我应该使用排队系统来处理付款吗?

php - 将插入与搜索分开 MYSQL PHP

javascript - 使用自定义数量设置 strip

php - 如何获取 Silex 上的所有 GET 参数?

PHP/GD 使用 imagecreatetruecolor() 而不是 imagecreate() 呈现黑色图像

java - 是否可以通过 Stripe 仅通过一个用户 3d 验证来确认多个 PaymentIntents?

ruby-on-rails - Stripe : Cannot charge a customer that has no active card

java - 没有这样的收件人错误 Stripe

php - 如何在 php 中创建如下所示的多维数组?

java - 通过php运行jar