php - 尝试使用 Sandbox 测试 Paypal IPN,但握手未通过

标签 php paypal paypal-ipn paypal-sandbox

我正在尝试设置 Paypal IPN,但无法弄清楚我在下面编写的代码有什么问题。当我尝试使用 Paypal 的 Sandbox IPN Simulator 对其进行测试时,它返回“IPN 未发送,握手未验证。请检查您的信息。”我认为问题出在标题需要更改为 sanbox freindly 格式,但无法弄清楚我需要更改的确切内容。

这是代码所在的 URL: http://pmoore17.altervista.org/TWADrama/ticketsales1.php

感谢任何帮助!谢谢!

<?php
// Read the notification from PayPal which comes in the form of a POST array and create the acknowledgement response
$req = 'cmd=_notify-validate';               // add 'cmd' to beginning of the acknowledgement you send back to PayPal

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
}


// Assign the paypal payment notification values to local variables
if($_POST){
$last_name = $_POST['last_name'];
$first_name = $_POST['first_name'];
$quantity = $_POST['quantity'];
$payer_email = $_POST['payer_email'];}

//Set up the acknowledgement request headers (this is the updated version for http 1.1)
$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 .= "Connection: close\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
//Open a socket for the acknowledgement request
$fq = fsockopen ('www.paypal.com/cgi-bin/webscr', 80, $errno, $errstr, 30);

if(!$fq){
    echo "HTTP ERROR";
}
else
{//start 1

// Post request back to PayPal for validation
fputs ($fq, $header . $req);

//once paypal receives the acknowledgement response, another message will be send containing the single word VERIFIED or INVALID

while (!feof($fq)) 
    { //start 2, while not EndOfFile
$res = fgets ($fq, 1024); // Get the acknowledgement response
$res = trim($res);
    if (strcmp ($res, "VERIFIED") == 0) 
        {// start 3, Response is OK
        $fn = "content.txt";
$fp = fopen($fn,"a+") or die ("Error opening file in write mode!");
fputs($fp,"last_name: ".$last_name.", ");
fputs($fp,"first_name: ".$first_name.", ");
fputs($fp,"quantity: ".$quantity.", ");
fputs($fp,"payer_email: ".$payer_email."\n");
fclose($fp) or die ("Error closing file!");
        }//end 3
        else if(strcmp ($res, "INVALID") == 0)
            {//start 4
            $fn = "content.txt";
$fp = fopen($fn,"a+") or die ("Error opening file in write mode!");
fputs($fp,"last_name: ".$last_name.", ");
fputs($fp,"first_name: ".$first_name.", ");
fputs($fp,"quantity: ".$quantity.", ");
fputs($fp,"payer_email: ".$payer_email."\n");
fclose($fp) or die ("Error closing file!");
            }//end 4


} //end 2
fclose ($fq);  //close file pointer
} //end 1
?>

最佳答案

尝试改变这个:

//Open a socket for the acknowledgement request
$fq = fsockopen ('www.paypal.com/cgi-bin/webscr', 80, $errno, $errstr, 30);

对此:

//Open a socket for the acknowledgement request
$fq = fsockopen ('ssl://www.sandbox.paypal.com/cgi-bin/webscr', 443, $errno, $errstr, 30);

关于php - 尝试使用 Sandbox 测试 Paypal IPN,但握手未通过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42571314/

相关文章:

parameters - Paypal IPN 和付款人电子邮件

php - 通过 php 定义 CSS 颜色

php - Bloggish 项目 MySQL 数据库设计问题

node.js - paypal rest sdk - 取消付款只给 token

javascript - Paypal 客户端 REST : how to notify server?

paypal - Paypal 购买后发送电子邮件

Paypal IPN 处理多个自定义变量

php - Laravel资源集合-分页-JSON响应错误

php - SQL ERROR 当我加入 2 个表时

paypal - Paypal 沙箱没有交易历史记录