最近出现了这个问题:我无法从paypal沙箱(IPN)获得回复。
我使用以下代码:
import requests
params = {} #all params paypal sent via IPN, empty here for sake of brevity
params['cmd'] = "_notify-validate"
r = requests.post("https://www.sandbox.paypal.com/cgi-bin/webscr", params = params)
这将返回一条错误消息,说明"由对等方重置连接"
请注意,此代码之前工作正常,如果我使用实时网站Paypal网址而不是沙盒,那么我仍然会收到响应而不是连接错误。
任何人都可以验证这是Paypal的问题吗?我的代码都没有改变,但是从昨天开始,我使用沙箱的测试都不再适用。
答案 0 :(得分:2)
PayPal目前在Sandbox环境中没有遇到IPN问题。我已经测试过并且无法重新描述所描述的问题。您可以尝试测试下面的代码,看看您是否有相同的结果?
<?php
// change email from xxx@xxxx.com to a valid one.
// read the post from PayPal system and add 'cmd'
if($_SERVER['REQUEST_METHOD']!="POST") die("No data");
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$url=(!isset($_POST['test_ipn'])) ? 'https://www.paypal.com/cgi-bin/webscr' : 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$curl_result=$curl_err='';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
curl_setopt($ch, CURLOPT_HEADER , 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$curl_result = @curl_exec($ch);
$curl_err = curl_error($ch);
curl_close($ch);
//are we verified? If so, let's process the IPN
if (strpos($curl_result, "VERIFIED")!==false)
{
//do your IPN stuff here
$mail_From = "From: IPN@domain.com"; // enter an email address alias here example ipn@fiercepc.co.uk please note this does not need to be a real email address
$mail_To = "email@domain.com"; //enter the email address you want to receive the email at
$mail_Subject = "VERIFIED IPN";
$mail_Body = $req;
foreach ($_POST as $key => $value){
$emailtext .= $key . " = " .$value ."\r\n\r\n";
}
mail($mail_To, $mail_Subject, $emailtext . "\r\n\r\n" . $mail_Body, $mail_From);
}
else{
$mail_From = "From: IPN@domain.com";
$mail_To = "email@domain.com";
$mail_Subject = "INVALID IPN";
$mail_Body = $req;
$emailtext = "you didn't get anything";
mail($mail_To, $mail_Subject, $emailtext . "\r\n\r\n" . $mail_Body, $mail_From);
}
?>
&#13;
或者转到GitHub存储库以查找更多IPN样本。
答案 1 :(得分:1)
这实际上是我的Python代码的一个问题。奇怪的是,我没有更改请求模块,但它停止使用相同的代码。
一旦我改为通过'data'参数发送IPN变量,而不是'params',那么我就能收到正常的响应。
r = requests.post("https://www.sandbox.paypal.com/cgi-bin/webscr", data = params)