简体   繁体   English

PayPal Webhook 不发送 POST 数据

[英]PayPal Webhook sends no POST data

Configured my PayPal webhook successfully to be notified of all events.成功配置我的 PayPal webhook 以收到所有事件的通知。

PayPal calls my webhook (a simple script) when events occur... but does not send any POST data with it....当事件发生时,PayPal 调用我的 webhook(一个简单的脚本)......但不发送任何 POST 数据......

All PHP arrays are empty ( $_POST, $_GET, $_REQUEST ) except for $_SERVER of course.除了$_SERVER当然所有 PHP 数组都是空的( $_POST, $_GET, $_REQUEST )。

What is going on?到底是怎么回事? The webhook simulator says that the events are sent/queued succesfully... webhook 模拟器说事件已成功发送/排队......

The $_SERVER array contains the suggested HTTP_PAYPAL_... headers and everything.... but the $_POST array is empty. $_SERVER数组包含建议的HTTP_PAYPAL_...标头和所有内容.... 但$_POST数组为空。

My webhook is written as follows...我的网络钩子是这样写的...

<?php

require ('./ace-includes/ace_log.php');

ace_log(print_r($_POST, true));
ace_log(print_r($_REQUEST, true));
ace_log(print_r($_GET, true));
ace_log(print_r($_SERVER, true));

ace_sendlog("NOTIFY SCRIPT CALLED");

?>

I figured it out....我想到了....

You cannot use $_POST to get the data....您不能使用 $_POST 来获取数据....

The data is contained in the HTTP file sent to the script.数据包含在发送到脚本的 HTTP 文件中。

In this case you MUST use在这种情况下,您必须使用

file_get_contents('php://input');

to get the data.获取数据。

So for PayPal PHP webhooks you would do this....所以对于 PayPal PHP webhooks 你会这样做....

$json = file_get_contents('php://input');
$data = json_decode($json);

This works and now I am getting all the data.这有效,现在我正在获取所有数据。

This really should be documented somewhere.... anywhere... but its not... and not obvious to an beginning PHP programmer.这真的应该在某处记录......任何地方......但它不是......并且对于初学者PHP程序员来说并不明显。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM