jan*_*doe 0 php google-cloud-platform google-cloud-pubsub
我目前已在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);
Run Code Online (Sandbox Code Playgroud)
为了让 POST 数据正确显示,我需要做什么特殊的事情吗?
对于任何遇到此问题的人,这是因为 POST 数据以 json 格式发送。因此,您不必查看 $_POST,而是必须这样做
json_decode(file_get_contents('php://input'));
Run Code Online (Sandbox Code Playgroud)
....这应该有效。或者,你可以这样做
json_decode($HTTP_RAW_POST_DATA);
Run Code Online (Sandbox Code Playgroud)
获取数据。