[英]I am getting blank response from webhook url which I am using for Stripe events
I am getting blank response from the stripe webhook url.我收到来自条纹 webhook url 的空白响应。
I am using the below code:我正在使用以下代码:
$json = file_get_contents('php://input');
$action = json_decode($json, true);
But in $json array, I am getting blank response.但是在$json数组中,我得到了空白响应。
I'm assuming you mean that the $action
array is empty.我假设你的意思是
$action
数组是空的。 My guess would be - and I've never looked in there - that the body of the request coming from php://input
isn't JSON.我的猜测是——而且我从来没有看过——来自
php://input
的请求正文不是 JSON。
The code I use is basically the same as the example on Stripe's site and it works just fine for me:我使用的代码与 Stripe 网站上的示例基本相同,对我来说效果很好:
$payload = @file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
$event = null;
try {
$event = Webhook::constructEvent(
$payload,
$sig_header,
$this->stripeApiKey
);
} catch (\UnexpectedValueException $e) {
throw new BadRequestHttpException('Unexpected value error');
} catch (SignatureVerification $e) {
throw new BadRequestHttpException('Signature verification error');
}
After this point you should have a valid event in $event
and its core object can be fetched with $object = $event->data->object
.此后,您应该在
$event
中有一个有效的事件,并且可以使用$object = $event->data->object
获取其核心 object 。 What type this object will be will depend on what events you are getting webhook calls for.这个 object 是什么类型将取决于您收到 webhook 调用的事件。 You can get the event type out with
$event->type
.您可以使用
$event->type
获取事件类型。
(Yes, I know using @
is bad practice, but I don't really mind failures there as everything is to do with whether Webhook::constructEvent()
works or not.) (是的,我知道使用
@
是不好的做法,但我并不介意那里的失败,因为一切都与Webhook::constructEvent()
是否有效有关。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.