paypal ipn-回邮后没有收到paypal的回复
我在贝宝IPN上工作。我的应用程序成功地收到了来自Paypal的第一个通知,但是,在发送回发后,Paypal似乎没有回复回发是否有效 我从paypal开发者网站的示例代码中获得的大部分代码:paypal ipn-回邮后没有收到paypal的回复,paypal,paypal-ipn,Paypal,Paypal Ipn,我在贝宝IPN上工作。我的应用程序成功地收到了来自Paypal的第一个通知,但是,在发送回发后,Paypal似乎没有回复回发是否有效 我从paypal开发者网站的示例代码中获得的大部分代码: public function process(){ // Read the notification from PayPal and create the acknowledgement response $req = 'cmd=_notify-validate'; // a
public function process(){
// Read the notification from PayPal and create the acknowledgement response
$req = 'cmd=_notify-validate'; // add 'cmd' to beginning of the acknowledgement you send back to PayPal
//$raw = file_get_contents("php://input");
foreach ($_POST as $key => $value) { // Loop through the notification NV pairs
$value = urlencode(stripslashes($value)); // Encode the values
$req .= "&$key=$value"; // Add the NV pairs to the acknowledgement
}
//Set up the acknowledgement request headers
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Connection: close\r\n\r\n";
//Open a socket for the acknowledgement request
//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
// Post request back to PayPal for validation
fputs ($fp, $header . $req);
while (!feof($fp)) { // While not EOF
$res = fgets ($fp, 1024); // Get the acknowledgement response
//$res=stream_get_contents($fp, 1024);
$this->emailtest(print_r($_POST,true) .'<br /><br />' . $header.$req);
if (strcmp ($res, "VERIFIED") == 0) { // Response is VERIFIED
$this->emailtest('VERIFIED');
// Send an email announcing the IPN message is VERIFIED
//$mail_From = "IPN@example.com";
//$mail_To = "Your-eMail-Address";
//$mail_Subject = "VERIFIED IPN";
//$mail_Body = $req;
//mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
// Notification protocol is complete, OK to process notification contents
// Possible processing steps for a payment might include the following:
// Check that the payment_status is Completed
// Check that txn_id has not been previously processed
// Check that receiver_email is your Primary PayPal email
// Check that payment_amount/payment_currency are correct
// Process payment
}
else if (strcmp ($res, "INVALID") == 0) { // Response is INVALID
$this->emailtest('INVALID');
// Notification protocol is NOT complete, begin error handling
// Send an email announcing the IPN message is INVALID
$mail_From = "IPN@example.com";
$mail_To = "Your-eMail-Address";
$mail_Subject = "INVALID IPN";
$mail_Body = $req;
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
}
}
fclose ($fp);
提前谢谢 我通过另一个引用设法解决了这个问题,或者至少从IPN获得了一个回复[无效回复]——这毕竟是一个进步: 提及: 将标题格式更改为:
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n"; // www.paypal.com for a live site
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Connection: close\r\n\r\n";
和改变:
如果(strcmp($res,“VERIFIED”)==0)
为此:
if(stripos($res,“VERIFIED”)!==false)
谢谢!今天晚上,我试图更改HTTP 1.1,直到我更改了“已验证”的支票以匹配您的版本,我才识别出PayPal返回的任何响应
if (stripos($res, "VERIFIED") !== false) :
现在,它在live PayPal网站上起到了一种作用,对我来说,有效的方法是删除connection close标题,并在PP的回复中添加一个trim。下面是标题:
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
以下是fsockopen:
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
这是PP回复中的微调:
if (!$fp) {
// HTTP ERROR
error_mail("Could not open socket");
//
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = trim(fgets ($fp, 1024));
}
//
// check the payment_status is Completed
// check that receiver_email is your Primary PayPal email
//
if ((strcmp ($res, "VERIFIED") == 0) && ($payment_status == "Completed") && ($receiver_email == $valid_receiver_email)) {
这对我很管用
if (!$fp) {
// HTTP ERROR
error_mail("Could not open socket");
//
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = trim(fgets ($fp, 1024));
}
//
// check the payment_status is Completed
// check that receiver_email is your Primary PayPal email
//
if ((strcmp ($res, "VERIFIED") == 0) && ($payment_status == "Completed") && ($receiver_email == $valid_receiver_email)) {