Google 云 Pub/Sub 推送消息 - 空 POST

Google Cloud Pub/Sub Push Messages - Empty POST

目前我已经在google云平台成功设置了主题和订阅,并且已经通过google验证了我的站点并将域添加到GCP。

每当我尝试从 https://console.cloud.google.com/cloudpubsub/topics/subscription_sync 发送测试消息时,我配置的端点都会收到 某些内容 ,但 POST 变量为空。这是我目前在 php 中的代码,它只是简单地记录 POST 变量(稍后在我的日志中显示为空。)

require_once 'EventPersister.class.php';


$eventPersister = new EventPersister(EventPersister::GOOGLE_WEBHOOKS);

$eventPersister->Persist($_POST);

我需要做些什么才能让 POST 数据正确显示吗?

对于遇到此问题的任何人,这是因为 POST 数据以 json 格式发送。所以不是看$_POST,你必须做

json_decode(file_get_contents('php://input'));

...这应该有效。或者,您可以

json_decode($HTTP_RAW_POST_DATA);

获取数据。