如何让 PayPal 和 cURL 协同工作?
背景细节:
我有一个自定义购物车,使用 PayPal 进行付款处理。我在购物车和 PayPal 之间有一个中间页面,它将订单添加到数据库并发送确认电子邮件。
到目前为止,我已将中间页面设置为包含所有必要的数据作为隐藏表单字段,并将表单提交到 PayPal onload
。
现在我正在尝试在 PHP 中使用 cURL 将 POST 数据发送到 PayPal。
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr');
//curl_setopt($ch, CURLOPT_URL, 'http://localhost/postecho.php');
// ^ this one is a simple page that echoes all POST data using print_r
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $poststring);
// Some options that didn't seem to help
//curl_setopt($ch, CURLOPT_HEADER, 1);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
// User agent spoofing which also didn't seem to help
//$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
//curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$result=curl_exec($ch);
curl_close($ch);
$poststring
包含我之前以 param1=value¶m2=value
格式传递的所有 POST 数据。通过测试页面 postecho.php
运行此命令表明 POST 数据似乎没问题。
问题:
“抱歉 - 您的上一个操作无法完成”
这是当我尝试以 cURL 方式执行操作时 PayPal 告诉我的信息。它并没有真正为我提供有关解决此问题的任何有用信息。我认为标题中一定有一些东西或者它不喜欢的东西。如何让 PayPal 和 cURL 协同工作?
THE BACKGROUND DETAILS:
I have a custom shopping cart that uses PayPal for payment processing. I have an intermediary page between the cart and PayPal that adds the order to a database and sends confirmation emails.
Until now, I had the intermediary page set up to include all the necessary data as hidden form fields and submit the form to PayPal onload
.
Now I'm experimenting with using cURL in PHP to send the POST data to PayPal.
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr');
//curl_setopt($ch, CURLOPT_URL, 'http://localhost/postecho.php');
// ^ this one is a simple page that echoes all POST data using print_r
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $poststring);
// Some options that didn't seem to help
//curl_setopt($ch, CURLOPT_HEADER, 1);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
// User agent spoofing which also didn't seem to help
//$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
//curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$result=curl_exec($ch);
curl_close($ch);
$poststring
contains all the POST data that I had previously been passing in param1=value¶m2=value
format. Running this through test page postecho.php
reveals that POST data seems to be alright.
THE PROBLEM:
"Sorry — your last action could not be completed"
This is what PayPal tells me when I try to do things the cURL way. It doesn't really give me any helpful information concerning the resolution of this problem. I figure there's gotta be something in the headers or something that it doesn't like. How do I make PayPal and cURL work together?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您很可能缺少 cookie/会话数据。如果我是你,我会捕获从你的浏览器发送到 paypal.com 的原始 http 消息。其中一些信息对于请求的工作来说并不需要,但至少它将包含您需要的所有信息。然后尝试用curl来模拟它。
长答案短:首先捕获原始http消息,然后用curl模拟它。
most likely you are missing cookie/session data. if i were you i would capture the raw http message that goes from your browser to paypal.com. some of it's info isn't going to be needed for the request to work, but at least it's going to contain all info you need. then try to emulate it with curl.
long answer short: first capture raw http message, then emulate it with curl.
您检查过 PHP 的 API 文档吗?
https://cms.paypal .com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/library_code
Have you checked the API docs for PHP?
https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/library_code