PHP Google Checkout 通知 - 用于发送通知请求的代码示例?

发布于 2024-12-15 00:06:11 字数 1730 浏览 1 评论 0原文

我已经将 Google Checkout 与一个网站集成,让它正常工作/假装向人们收费,并且还很好地处理订单通知。

但是,当我向 Google 发出请求以获取通知的详细信息时,我收到了 400 响应,其中涉及无效 XML。

问题是,到目前为止,此集成的所有内容都是 HTML 键值对,但突然间我需要解析和处理 XML?我可能遗漏了一些东西,但我看不到文档中的哪个位置它准确地告诉我我的请求应该是什么样子。

参见这里: http://code.google.com/apis/checkout/developer/Google_Checkout_HTML_API_Notification_API .html#Receiving_and_Processing_Notifications

它清楚地列出了带有名称/值对的示例,但显然我实际上需要将它们作为 XML 发送?

这就是我现在所处的位置:

<?php    $header_arr = array("Authorization: Basic ".$authKey,
                    "Content-Type: application/xml; charset=UTF-8",
            "Accept: application/xml; charset=UTF-8");

$request='type=notification-history-request&serial-number='.$serialNumber;

$ch = curl_init($test_URL);     
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header_arr);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$body = curl_exec($ch);

if (curl_errno($ch)) {
  $log.=', error! :'.curl_error($ch);
} else {
  $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  $log.=', status code is: '.$status_code;  //400
}
?>

每次都会返回 400 - 是的,我意识到我正在为 XML 设置一个接受标头,这是文档指定的,此处: http://code.google.com/apis/checkout/developer/Google_Checkout_HTML_API.html#https_auth_scheme

所以,我发现自己需要发送正确的请求...有什么想法吗?

PS我还检查了谷歌的示例代码,但它是如此分层和依赖,虽然我已经成功地使用了其中的一些,但其余的都是一个谜 - 所以除非你能给我行号,否则示例不会有很大帮助

I've integrated Google Checkout with a site, got it working / pretending to charge people fine and also processing the order notifications fine.

However, when I make a request back to Google to get the details of the notification, I receive a 400 response, something about invalid XML.

Thing is, everything for this integration so far has been HTML key value pairs, but all of a sudden I need to parse and deal with XML? I may be missing something, but I can't see where in the docs it tells me exactly what my request should look like.

See here:
http://code.google.com/apis/checkout/developer/Google_Checkout_HTML_API_Notification_API.html#Receiving_and_Processing_Notifications

It clearly lists an example with name / value pairs, yet apparently I actually need to send them as XML?

Here's where I am right now:

<?php    $header_arr = array("Authorization: Basic ".$authKey,
                    "Content-Type: application/xml; charset=UTF-8",
            "Accept: application/xml; charset=UTF-8");

$request='type=notification-history-request&serial-number='.$serialNumber;

$ch = curl_init($test_URL);     
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header_arr);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$body = curl_exec($ch);

if (curl_errno($ch)) {
  $log.=', error! :'.curl_error($ch);
} else {
  $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  $log.=', status code is: '.$status_code;  //400
}
?>

This returns a 400 each time - yes I realise I'm setting an accept header for XML, this is as the docs specify, here: http://code.google.com/apis/checkout/developer/Google_Checkout_HTML_API.html#https_auth_scheme

So, I find myself needing to send the correct request... any ideas?

P.S I've also checked through google's sample code but it's so layered and dependency-ridden that while I've managed to use some of it, the rest is a mystery - so unless you can give me line numbers, the samples aren't much help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞琼窗梦回ˉ 2024-12-22 00:06:11

好吧,事实证明这真的很简单。

我的参数名称错误 - 'type' 应该是 '_type',如下所示:

$request='_type=notification-history-request&serial-number='.$serialNumber;

我现在得到了我需要的响应,避免了恐慌:)

OK turns out this was really simple.

I had the param names wrong - 'type' should have been '_type', like this:

$request='_type=notification-history-request&serial-number='.$serialNumber;

I'm getting the response I need now, panic averted :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文