gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 16:06:03 26 4
gpt4 key购买 nike

我正在尝试设置 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com