dqv84329 2014-05-24 23:18
浏览 47
已采纳

IPN - 教程有错误

I was trying to follow the tutorial on paypal's developer site on setting up a basic IPN listener, and it looks nearly syntax for syntax like on their example. In fact when I started receiving the errors I've been receiving, I thought I would create a new ipn listener and use just the code they have in their example to see if it was my code or not and received the same errors.

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

the errors on those line numbers are for these pieces of code at those lines:

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

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

here is the rest of the entire code

<?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
"; //HTTP POST REQUEST
$header .="Content-Type: application/x-www-form-urlencoded
";
$header .="Content-Length: " .strlen($req) . "

";

// 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
?>

Okay now the new warning I get is this:

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

1条回答 默认 最新

  • douju6651 2014-05-24 23:27
    关注

    You're not checking the result of fsockopen() which returns FALSE upon failure.

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

    One clue from the documentation is the first parameter:

    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.

    Note that your example is using ssl:// - it is possible your server is not correctly configured with OpenSSL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大