php - IPN - 教程有错误

标签 php paypal

我试图按照 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/

相关文章:

php - Laravel Homestead 安装 : bash init. sh 不工作

PHP吐出事件的过程/位置/时间,结合结果以在页面上创建带有 session 的项目存储并创建购物车项目以发送到paypal?

c# - 如何使用任何 PayPal SDK 检查付款状态

android - 从 PayPal lib 获取支付配置

php - 从上一页获取 Id。

php - 确定在哪里捕获php/codeigniter错误

php - 将 fpdf 输出存储在服务器中并在数据库中添加文件名

php - Laravel Blade 显示大括号

Paypal-credit 智能支付按钮未显示

paypal - 打印 paypal 的交易 ID 是一种好习惯吗