如何让 PayPal 和 cURL 协同工作?

发布于 2024-09-15 07:27:10 字数 1355 浏览 3 评论 0原文

背景细节:

我有一个自定义购物车,使用 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&param2=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 技术交流群。

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

发布评论

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

评论(2

Saygoodbye 2024-09-22 07:27:10

您很可能缺少 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.

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