简体   繁体   English

Google Checkout API回调的POST数据为空

[英]POST data is empty for Google Checkout API Callback

I have set up the following script to test notifications of orders paid via Google Checkout: 我已设置以下脚本来测试通过Google Checkout支付的订单通知:

<?php
    mail('max@edison.com', 'google checkout order alert', json_encode($_POST));
?>

I'm getting the email, but the value of the $_POST array is blank (in other words, the body of the email is simply [] ). 我收到了电子邮件,但是$_POST数组的值为空白(换句话说,电子邮件的正文只是[] )。

Am I wrong to think that the values should be getting sent immediately via POST? 我认为应该立即通过POST发送值是错误的吗? Or is the notification request really just an opportunity for me to then request from Google the most recent order details? 还是通知请求确实是我向Google请求最新订单详细信息的机会? Ie, my above script would need to make a request to Google for the order details. 即,我的上述脚本需要向Google请求获取订单详细信息。

The Google Checkout postback request is a raw JSON post, not a typical HTTP post (which is what would be needed in order to populate the $_POST array). Google Checkout回发请求是原始的JSON帖子,而不是典型的HTTP帖子(这是填充$_POST数组所需要的)。 In order to read the contents of the postback request, you must get the raw post body, and json_decode it. 为了读取回发请求的内容,您必须获取原始的发布主体,并json_decode

This should do the trick: json_decode(file_get_contents('php://input')) 这应该可以解决问题: json_decode(file_get_contents('php://input'))

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

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