Encoding 条带Webhooks错误503编码无效:ISO-8859-1
我按照stripe的建议设置了带签名验证的stripe webhook:Encoding 条带Webhooks错误503编码无效:ISO-8859-1,encoding,stripe-payments,webhooks,Encoding,Stripe Payments,Webhooks,我按照stripe的建议设置了带签名验证的stripe webhook: <?php logme("Secure connection: ".isSecure()); logme("I was called at:".time()); require 'vendor/autoload.php'; \Stripe\Stripe::setApiKey('sk_test_ff...'); $endpoint_secret = 'whsec_Ky...
<?php
logme("Secure connection: ".isSecure());
logme("I was called at:".time());
require 'vendor/autoload.php';
\Stripe\Stripe::setApiKey('sk_test_ff...');
$endpoint_secret = 'whsec_Ky...';
$payload = @file_get_contents('php://input');
if($payload) {
//request body is set
} else {
//request body is not set
exit();
}
$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);
exit();
} catch(\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
http_response_code(400);
exit();
}
http_response_code(200);
// Handle the event
switch ($event->type) {
case 'event1':
// do something
break;
// ... handle other event types
default:
echo 'Received unknown event type ' . $event->type;
logme('Received unknown event type ' . $event->type);
}
function logme($msg){
$log_file = "error.txt";
// logging error message to given log file
error_log($msg."\n-\n", 3, $log_file);
}
function isSecure() {
return
(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
|| $_SERVER['SERVER_PORT'] == 443;
}
有人熟悉这种错误吗
更新
这似乎取决于触发的事件类型。例如,plan.deleted works and payment\u intent.successed不此错误似乎不是来自签名验证,而是来自请求/网络堆栈中的其他地方。请注意,在
try{}
中抛出的错误是withStatus(403)
(不是503)。您是否可以从服务器提供更详细的日志记录,以确定此操作失败的位置
请参阅和连接到HTTP->HTTPS重定向的解决方案。确保配置的端点直接指向HTTPS,并且SSL证书响应正确
我还看到您正在调用
$event=$request->getParsedBody()代码>在处理程序开始时,甚至在签名检查之前,这可能会导致正在处理的正文数据出现问题(签名验证需要请求的原始正文)。对于仍然面临此问题的任何人,我最近遇到了这个问题,最终意识到这是因为我错过了webhook端点的尾部斜杠……这几个小时花得很好 我刚刚更新了代码。新版本在上面。在后台,webhook端点位于https,而.htaccess
会将每个请求重定向到http,并确保我删除了整个.htaccess
,以查看是否存在由此引起的任何干扰,但错误是相同的。当然,但您再次指出存在503错误,但没有显示会引发该错误的代码。您是否有显示错误来源的服务器日志?(很抱歉,我未能添加到其他问题的链接,已编辑)我在后台收到错误503。我将$payload
和标题
记录在一个txt文件中,看起来一切正常。
Test-Webhook-Error: 503
Invalid encoding: ISO-8859-1