gpt4 book ai didi

php - IPN - 教程有错误

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

我试图按照 paypal 开发者网站上关于设置基本 IPN 监听器的教程进行操作,它看起来几乎像他们的示例中的语法一样。事实上,当我开始收到我一直收到的错误时,我想我会创建一个新的 ipn 监听器并仅使用他们在示例中的代码来查看它是否是我的代码并收到相同的错误。

Warning: fgets(): supplied argument is not a valid stream resource in \supergate\ipn.php on line 42

Warning: feof(): supplied argument is not a valid stream resource in \supergate\ipn.php on line 39

这些行号上的错误是针对这些行中的这些代码片段:

 while (!feof($fp)) //line 39
{

$res = fgets($fp, 1024); //line 42

这是整个代码的其余部分

<?php
//Empty Header HTTP 200 OK reponse to ack receipt of the notification
header('HTTP/1.1 200 OK');


///////////////////////////////////////////////////////
//assign payment notification values to local variables
$item_name =$_POST['item_name'];
$item_number =$_POST['item_number'];
$payment_status =$_POST['payment_status'];
$payment_ammount =$_POST['mc_gross'];
$payment_currency =$_POST['mc_currency'];
$txn_id =$_POST['txn_id'];
$receiver_email =$_POST['receiver_email'];
$payer_email =$_POST['payer_email'];
///////////////////////////////////////////////////////


//build the required ack message of notification just received
$req = 'cmd=_notify-validate'; //add 'cmd=_notify-validate' to beginning of acknowledgement

foreach ($_POST as $key => $value) { //loop through the notification nv pairs
$value = urlencode(stripcslashes($value)); //encode these values
$req .= "&$key=$value"; //add the nv pairs to the acknowledgement
}

//set up the acknowledgement request headers

$header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; //HTTP POST REQUEST
$header .="Content-Type: application/x-www-form-urlencoded\r\n";
$header .="Content-Length: " .strlen($req) . "\r\n\r\n";

// Open a socket for the acknowledgement request
$fp = fsockopen('ssl://sandbox.paypal.com', 443, $errno, $errstr, 30);

//send the http post request back to paypal for validation
fputs($fp, $header . $req);

while (!feof($fp))
{

$res = fgets($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0)
{
//WRITE TO EMAIL


*/
}
//--------------------------------------------------------------------------------------------------------------------
else if (strcmp($res,"INVALID") == 0)
{

//write to email
}


fclose($fp); //close the file
?>

好的,现在我收到的新警告是这样的:

Warning: fgets() [function.fgets]: SSL: An existing connection was forcibly closed by the remote host. 

最佳答案

您没有检查 fsockopen() 的结果失败时返回 FALSE

$fp = fsockopen(...);
if ($fp === FALSE) {
exit("Could not open socket");
}

文档中的一个线索是第一个参数:

hostname If OpenSSL support is installed, you may prefix the hostname with either ssl:// or tls:// to use an SSL or TLS client connection over TCP/IP to connect to the remote host.

请注意,您的示例使用的是 ssl:// - 您的服务器可能未正确配置 OpenSSL。

关于php - IPN - 教程有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23850577/

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